lovr.graphics.getBuffer

Edit

Returns a temporary Buffer.















Arguments

NameTypeDescription
sizenumber The size of the Buffer, in bytes.

Returns

NameTypeDescription
bufferBuffer The new Buffer.

Arguments

NameTypeDescription
blobBlob A Blob with the initial contents of the Buffer. The size of the Blob will be used to determine the length of the Buffer.

Returns

NameTypeDescription
bufferBuffer The new Buffer.

Arguments

NameTypeDefaultDescription
formattable A list of fields in the Buffer.
.layoutDataLayoutpacked How to lay out the Buffer fields in memory.
.stridenumber The stride of the Buffer, in bytes. When nil, the stride will be automatically computed based on the fields. The stride can not be zero or smaller than the max byte occupied by one of the fields. The layout of the Buffer may adjust the stride.
lengthnumber1 The length of the Buffer.

Returns

NameTypeDescription
bufferBuffer The new Buffer.

Arguments

NameTypeDefaultDescription
formattable A list of fields in the Buffer.
.layoutDataLayoutpacked How to lay out the Buffer fields in memory.
.stridenumber The stride of the Buffer, in bytes. When nil, the stride will be automatically computed based on the fields. The stride can not be zero or smaller than the max byte occupied by one of the fields. The layout of the Buffer may adjust the stride.
datatable The initial data to put into the Buffer. The length of the Buffer will be determined by the contents of the table. The contents can be a mix of tables, numbers, and vectors, but the length calculation requires each field to consistently use one type of data.

Returns

NameTypeDescription
bufferBuffer The new Buffer.

Arguments

NameTypeDefaultDescription
formattable A list of fields in the Buffer.
.layoutDataLayoutpacked How to lay out the Buffer fields in memory.
.stridenumber The stride of the Buffer, in bytes. When nil, the stride will be automatically computed based on the fields. The stride can not be zero or smaller than the max byte occupied by one of the fields. The layout of the Buffer may adjust the stride.
blobBlob A Blob with the initial contents of the Buffer. The size of the Blob will be used to determine the length of the Buffer.

Returns

NameTypeDescription
bufferBuffer The new Buffer.

Arguments

NameTypeDefaultDescription
typeDataType The type of each item in the Buffer.
lengthnumber1 The length of the Buffer.

Returns

NameTypeDescription
bufferBuffer The new Buffer.

Arguments

NameTypeDescription
typeDataType The type of each item in the Buffer.
datatable The initial data to put into the Buffer. The length of the Buffer will be determined by the contents of the table. The contents can be a mix of tables, numbers, and vectors, but the length calculation requires each field to consistently use one type of data.

Returns

NameTypeDescription
bufferBuffer The new Buffer.

Arguments

NameTypeDescription
typeDataType The type of each item in the Buffer.
blobBlob A Blob with the initial contents of the Buffer. The size of the Blob will be used to determine the length of the Buffer.

Returns

NameTypeDescription
bufferBuffer The new Buffer.

Arguments

NameTypeDefaultDescription
lengthnumber1 The length of the Buffer.
typeDataType The type of each item in the Buffer.

Returns

NameTypeDescription
bufferBuffer The new Buffer.

Arguments

NameTypeDescription
datatable The initial data to put into the Buffer. The length of the Buffer will be determined by the contents of the table. The contents can be a mix of tables, numbers, and vectors, but the length calculation requires each field to consistently use one type of data.
typeDataType The type of each item in the Buffer.

Returns

NameTypeDescription
bufferBuffer The new Buffer.

Arguments

NameTypeDefaultDescription
lengthnumber1 The length of the Buffer.
formattable A list of fields in the Buffer.
.layoutDataLayoutpacked How to lay out the Buffer fields in memory.
.stridenumber The stride of the Buffer, in bytes. When nil, the stride will be automatically computed based on the fields. The stride can not be zero or smaller than the max byte occupied by one of the fields. The layout of the Buffer may adjust the stride.

Returns

NameTypeDescription
bufferBuffer The new Buffer.

Arguments

NameTypeDefaultDescription
datatable The initial data to put into the Buffer. The length of the Buffer will be determined by the contents of the table. The contents can be a mix of tables, numbers, and vectors, but the length calculation requires each field to consistently use one type of data.
formattable A list of fields in the Buffer.
.layoutDataLayoutpacked How to lay out the Buffer fields in memory.
.stridenumber The stride of the Buffer, in bytes. When nil, the stride will be automatically computed based on the fields. The stride can not be zero or smaller than the max byte occupied by one of the fields. The layout of the Buffer may adjust the stride.

Returns

NameTypeDescription
bufferBuffer The new Buffer.

Arguments

NameTypeDescription
blobBlob A Blob with the initial contents of the Buffer. The size of the Blob will be used to determine the length of the Buffer.
typeDataType The type of each item in the Buffer.

Returns

NameTypeDescription
bufferBuffer The new Buffer.

Arguments

NameTypeDefaultDescription
blobBlob A Blob with the initial contents of the Buffer. The size of the Blob will be used to determine the length of the Buffer.
formattable A list of fields in the Buffer.
.layoutDataLayoutpacked How to lay out the Buffer fields in memory.
.stridenumber The stride of the Buffer, in bytes. When nil, the stride will be automatically computed based on the fields. The stride can not be zero or smaller than the max byte occupied by one of the fields. The layout of the Buffer may adjust the stride.

Returns

NameTypeDescription
bufferBuffer The new Buffer.

Notes

The format table can contain a list of DataTypes or a list of tables to provide extra information about each field. Each inner table has the following keys:

As a shorthand, the name, type, and optionally the length of a field can be provided as a list instead of using keys.

If no table or Blob is used to define the initial Buffer contents, its data will be undefined.

Example

Examples of different buffer formats.

-- 2 matrices
lovr.graphics.getBuffer('mat4', 2)

-- 3 integers, with initial data
lovr.graphics.getBuffer('int', { 1, 2, 3 })

-- a simple mesh:
lovr.graphics.getBuffer({
  { name = 'VertexPosition', type = 'vec3' },
  { name = 'VertexColor', type = 'color' }
}, 4)

-- a uniform buffer with vec3's, using the std140 packing
lovr.graphics.getBuffer({ 'vec3', layout = 'std140' }, data)

-- a uniform buffer with key-value fields
lovr.graphics.getBuffer({
  { 'AmbientColor', 'vec3' },
  { 'LightPosition', 'vec3' },
  { 'LightType', 'u32' },
  { 'LightColor', 'vec4' },
  layout = 'std140'
})

-- a buffer with nested structure and array types
lovr.graphics.getBuffer({
  { 'globals', {
    { 'ObjectCount', 'int' },
    { 'WorldSize', 'vec2' },
    { 'Scale', 'float' }
  }},
  { 'materials', {
    { 'Color', 'vec4' },
    { 'Glow', 'vec3' },
    { 'Roughness', 'float' }
  }, length = 32 },
  layout = 'std430'
})

-- a buffer using a variable from a shader:
lovr.graphics.getBuffer(shader:getBufferFormat('transforms'))

See also