Class VBO
Vertex Buffer Object
See also:
Methods
- VBO:Delete
- VBO:Define
- Allows you to specify what kind of VBO you will be using.
- VBO:GetBufferSize
- VBO:Upload
- Uploads the data (array of floats) into the VBO
- VBO:Download
- VBO:ModelsVBO
- Binds engine side vertex or index VBO containing models (units, features) data.
- VBO:InstanceDataFromUnitDefIDs
- Fills in attribute data for each specified unitDefID
- VBO:InstanceDataFromFeatureDefIDs
- Fills in attribute data for each specified featureDefID
- VBO:InstanceDataFromUnitIDs
- Fills in attribute data for each specified unitID
- VBO:InstanceDataFromFeatureIDs
- Fills in attribute data for each specified featureID
- VBO:MatrixDataFromProjectileIDs
- VBO:BindBufferRange
- Bind a range within a buffer object to an indexed buffer target
- VBO:UnbindBufferRange
- VBO:DumpDefinition
- Logs the definition of the VBO to the console
Methods
VBO:Delete()
Returns:
- nil
VBO:Define(size, attribs)
Allows you to specify what kind of VBO you will be using.
It is usually an array of vertex/color/uv data, but can also be an array of instance uniforms. If you want to specify multiple instances of something to render, you will need to create another VBO, which also specifies the number of instances you wish to render, and the size of the data passed to each instance. If you want say 5 elements, and each element is defined in the layout: {id = 0, name = "first", size = 1},{id = 1, name = "second", size = 2}} , then the total size of your VBO will be 5 * (1 + 2). They will be laid out consecutively: [1,2],[1,2],[1,2],[1,2],[1,2]. This is important for when you call VBO:Upload, you need to make sure you enter your data into the Lua array correctly.
Parameters:
-
size
number the maximum number of elements this VBO can have. -
attribs
number or {{number,number,number,number,number},...}When number, the maximum number of elements this VBO can have.
Otherwise, an array of arrays specifying the layout composed of:
id
: the location in the vertex shader layout e.g.: layout (location = 0) in vec2 aPos. optional attrib, specifies location in the vertex shader. If not specified the implementation will increment the counter starting from 0. There can be maximum 16 attributes (so id of 15 is max).name
: the name for this VBO, only used for debuggingsize
: optional, defaults to 4 for VBO. The number of floats that constitute 1 element in this buffer. O.g. for the previous layout (location = 0) in vec2 aPos, it would be size = 2.- type: is the datatype of this element, can be:
GL.BYTE
,GL.UNSIGNED_BYTE
,GL.SHORT
,GL.UNSIGNED_SHORT
,GL.INT
,GL.UNSIGNED_INT
,GL.FLOAT
. Default isGL.FLOAT
. normalized
: it's possible to submit say normal without normalizing them first, normalized will make sure data is normalized. Optional attrib, defaults to false.
Returns:
- nil
See also:
Usage:
terrainVertexVBO:Define(numPoints, { {id = 0, name = "pos", size = 2}, })
VBO:GetBufferSize()
Returns:
- number elementsCount
- number bufferSizeInBytes
- number size
VBO:Upload(vboData[, attributeIndex=-1[, elemOffset=0[, luaStartIndex=0[, luaFinishIndex]]]])
Uploads the data (array of floats) into the VBO
Parameters:
-
vboData
{number,...} a lua array of values to upload into the VBO -
attributeIndex
number If supplied with non-default value then the data from vboData will only be used to upload the data to this particular attribute. The whole vboData is expected to contain only attributeIndex data. Otherwise all attributes get updated sequentially across attributes and elements. (default -1) -
elemOffset
number which VBO element to start uploading data from Lua array into (default 0) -
luaStartIndex
number start uploading from that element in supplied Lua array (default 0) -
luaFinishIndex
number consider this element the last element in Lua array (optional)
Returns:
- {number, ...} indexData
- number elemOffset
- number or {number,number,number,number} attrID
See also:
Usage:
vbo:Upload(posArray, 0, 1) -- 0 is offset into vbo (on GPU) in this case no offset -- 1 is lua index index into the Lua table, in this case it's same as default -- Upload will upload from luaOffset to end of lua array
rectInstanceVBO:Upload({1},0)
VBO:Download([attributeIndex=-1[, elementOffset=0[, elementCount[, forceGPURead=false]]]])
Parameters:
-
attributeIndex
number when supplied with non-default value: only data from specified attribute will be downloaded - otherwise all attributes are downloaded (default -1) -
elementOffset
number download data starting from this element (default 0) -
elementCount
number number of elements to download (optional) -
forceGPURead
bool force downloading the data from GPU buffer as opposed to using shadow RAM buffer (default false)
Returns:
- {{number,...},...} vboData
VBO:ModelsVBO()
Binds engine side vertex or index VBO containing models (units, features) data.
Also fills in VBO definition data as they're set for engine models (no need to do VBO:Define()).
Returns:
- nil or number buffer size in bytes
VBO:InstanceDataFromUnitDefIDs(unitDefIDs, attrID[, teamIdOpt[, elementOffset]])
Fills in attribute data for each specified unitDefID
The instance data in that attribute will contain the offset to bind position matrix in global matrices SSBO and offset to uniform buffer structure in global per unit/feature uniform SSBO (unused for Unit/FeatureDefs), as well as some auxiliary data ushc as draw flags and team index.
Parameters:
-
unitDefIDs
number or {number,...} -
attrID
number -
teamIdOpt
number (optional) -
elementOffset
number (optional)
Returns:
- {number,number,number,number} instanceData
- number elementOffset
- attrID
Usage:
Data Layout SInstanceData: , matOffset{ matOffset_ } // updated during the following draw frames , uniOffset{ uniOffset_ } // updated during the following draw frames , info{ teamIndex, drawFlags, 0, 0 } // not updated during the following draw frames , aux1 { 0u }
VBO:InstanceDataFromFeatureDefIDs(featureDefIDs, attrID[, teamIdOpt[, elementOffset]])
Fills in attribute data for each specified featureDefID
The instance data in that attribute will contain the offset to bind position matrix in global matrices SSBO and offset to uniform buffer structure in global per unit/feature uniform SSBO (unused for Unit/FeatureDefs), as well as some auxiliary data ushc as draw flags and team index.
Parameters:
-
featureDefIDs
number or {number,...} -
attrID
number -
teamIdOpt
number (optional) -
elementOffset
number (optional)
Returns:
- {number,number,number,number} instanceData
- number elementOffset
- attrID
Usage:
Data Layout SInstanceData: , matOffset{ matOffset_ } // updated during the following draw frames , uniOffset{ uniOffset_ } // updated during the following draw frames , info{ teamIndex, drawFlags, 0, 0 } // not updated during the following draw frames , aux1 { 0u }
VBO:InstanceDataFromUnitIDs(unitIDs, attrID[, teamIdOpt[, elementOffset]])
Fills in attribute data for each specified unitID
The instance data in that attribute will contain the offset to bind position matrix in global matrices SSBO and offset to uniform buffer structure in global per unit/feature uniform SSBO (unused for Unit/FeatureDefs), as well as some auxiliary data ushc as draw flags and team index.
Parameters:
-
unitIDs
number or {number,...} -
attrID
number -
teamIdOpt
number (optional) -
elementOffset
number (optional)
Returns:
- {number,number,number,number} instanceData
- number elementOffset
- attrID
Usage:
Data Layout SInstanceData: , matOffset{ matOffset_ } // updated during the following draw frames , uniOffset{ uniOffset_ } // updated during the following draw frames , info{ teamIndex, drawFlags, 0, 0 } // not updated during the following draw frames , aux1 { 0u }
VBO:InstanceDataFromFeatureIDs(featureIDs, attrID[, teamIdOpt[, elementOffset]])
Fills in attribute data for each specified featureID
The instance data in that attribute will contain the offset to bind position matrix in global matrices SSBO and offset to uniform buffer structure in global per unit/feature uniform SSBO (unused for Unit/FeatureDefs), as well as some auxiliary data ushc as draw flags and team index.
Parameters:
-
featureIDs
number or {number,...} -
attrID
number -
teamIdOpt
number (optional) -
elementOffset
number (optional)
Returns:
- {number,number,number,number} instanceData
- number elementOffset
- attrID
VBO:MatrixDataFromProjectileIDs(projectileIDs, attrID[, teamIdOpt[, elementOffset]])
Parameters:
-
projectileIDs
number or {number,...} -
attrID
number -
teamIdOpt
number (optional) -
elementOffset
number (optional)
Returns:
- {number, ...} matDataVec 4x4 matrix
- number elemOffset
- number or {number,number,number,number} attrID
VBO:BindBufferRange(index[, elementOffset[, elementCount[, target]]])
Bind a range within a buffer object to an indexed buffer target
Generally mimics https://registry.khronos.org/OpenGL-Refpages/gl4/html/glBindBufferRange.xhtml except offset and size are specified in number of elements / element indices.
Parameters:
-
index
number should be in the range between5 < index < GL_MAX_UNIFORM_BUFFER_BINDINGS
value (usually 31) -
elementOffset
number (optional) -
elementCount
number (optional) -
target
number glEnum (optional)
Returns:
- number bindingIndex when successful, -1 otherwise
VBO:UnbindBufferRange(index[, elementOffset[, elementCount[, target]]])
Parameters:
-
index
number -
elementOffset
number (optional) -
elementCount
number (optional) -
target
number glEnum (optional)
Returns:
- number bindingIndex when successful, -1 otherwise
VBO:DumpDefinition()
Logs the definition of the VBO to the console
Returns:
- nil