- Select ref document -

Buffer API documentation

version 1.2.162

Functions for manipulating buffers and streams

Functions

buffer.copy_buffer

buffer.copy_buffer(dst, dstoffset, src, srcoffset, count)

Copy all data streams from one buffer to another, element wise.

Each of the source streams must have a matching stream in the destination buffer. The streams must match in both type and size. The source and destination buffer can be the same.

Parameters

dst

buffer the destination buffer

dstoffset

number the offset to start copying data to

src

buffer the source data buffer

srcoffset

number the offset to start copying data from

count

number the number of elements to copy

dst

buffer the destination buffer

dstoffset

number the offset to start copying data to

src

buffer the source data buffer

srcoffset

number the offset to start copying data from

count

number the number of elements to copy

Examples

How to copy elements (e.g. vertices) from one buffer to another

-- copy entire buffer
buffer.copy_buffer(dstbuffer, 0, srcbuffer, 0, #srcbuffer)

-- copy last 10 elements to the front of another buffer
buffer.copy_buffer(dstbuffer, 0, srcbuffer, #srcbuffer - 10, 10)

buffer.copy_stream

buffer.copy_stream(dst, dstoffset, src, srcoffset, count)

Copy a specified amount of data from one stream to another.

The value type and size must match between source and destination streams. The source and destination streams can be the same.

Parameters

dst

bufferstream the destination stream

dstoffset

number the offset to start copying data to (measured in value type)

src

bufferstream the source data stream

srcoffset

number the offset to start copying data from (measured in value type)

count

number the number of values to copy (measured in value type)

dst

bufferstream the destination stream

dstoffset

number the offset to start copying data to (measured in value type)

src

bufferstream the source data stream

srcoffset

number the offset to start copying data from (measured in value type)

count

number the number of values to copy (measured in value type)

Examples

How to update a texture of a sprite:

-- copy entire stream
local srcstream = buffer.get_stream(srcbuffer, hash("xyz"))
local dststream = buffer.get_stream(dstbuffer, hash("xyz"))
buffer.copy_stream(dststream, 0, srcstream, 0, #srcstream)

buffer.create

buffer.create(element_count, declaration)

Create a new data buffer containing a specified set of streams. A data buffer can contain one or more streams with typed data. This is useful for managing compound data, for instance a vertex buffer could contain separate streams for vertex position, color, normal etc.

Parameters

element_count

number The number of elements the buffer should hold

declaration

table A table where each entry (table) describes a stream

  • hash | string name: The name of the stream
  • constant type: The data type of the stream
  • number count: The number of values each element should hold
element_count

number The number of elements the buffer should hold

declaration

table A table where each entry (table) describes a stream

  • hash | string name: The name of the stream
  • constant type: The data type of the stream
  • number count: The number of values each element should hold

Examples

How to create and initialize a buffer

function init(self)
  local size = 128
  self.image = buffer.create( size * size, { {name=hash("rgb"), type=buffer.VALUE_TYPE_UINT8, count=3 } })
  self.imagestream = buffer.get_stream(self.image, hash("rgb"))

  for y=0,self.height-1 do
     for x=0,self.width-1 do
         local index = y * self.width * 3 + x * 3 + 1
         self.imagestream[index + 0] = self.r
         self.imagestream[index + 1] = self.g
         self.imagestream[index + 2] = self.b
     end
  end

buffer.get_bytes

buffer.get_bytes(buffer, stream_name)

Get a copy of all the bytes from a specified stream as a Lua string.

Parameters

buffer

buffer the source buffer

stream_name

hash the name of the stream

buffer

buffer the source buffer

stream_name

hash the name of the stream

Returns

data

string the buffer data as a Lua string

data

string the buffer data as a Lua string

buffer.get_stream

buffer.get_stream(buffer, stream_name)

Get a specified stream from a buffer.

Parameters

buffer

buffer the buffer to get the stream from

stream_name

hash | string the stream name

buffer

buffer the buffer to get the stream from

stream_name

hash | string the stream name

Returns

stream

bufferstream the data stream

stream

bufferstream the data stream

Constants

buffer.VALUE_TYPE_FLOAT32

Float, single precision, 4 bytes

buffer.VALUE_TYPE_INT16

Signed integer, 2 bytes

buffer.VALUE_TYPE_INT32

Signed integer, 4 bytes

buffer.VALUE_TYPE_INT64

Signed integer, 8 bytes

buffer.VALUE_TYPE_INT8

Signed integer, 1 byte

buffer.VALUE_TYPE_UINT16

Unsigned integer, 2 bytes

buffer.VALUE_TYPE_UINT32

Unsigned integer, 4 bytes

buffer.VALUE_TYPE_UINT64

Unsigned integer, 8 bytes

buffer.VALUE_TYPE_UINT8

Unsigned integer, 1 byte