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:

  1. 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:

  1. size number the maximum number of elements this VBO can have.
  2. 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 debugging
    • size: 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 is GL.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:

  1. nil

See also:

Usage:

  • terrainVertexVBO:Define(numPoints, { {id = 0, name = "pos", size = 2}, })

VBO:GetBufferSize()

Returns:

  1. number elementsCount
  2. number bufferSizeInBytes
  3. number size

VBO:Upload(vboData[, attributeIndex=-1[, elemOffset=0[, luaStartIndex=0[, luaFinishIndex]]]])

Uploads the data (array of floats) into the VBO

Parameters:

  1. vboData {number,...} a lua array of values to upload into the VBO
  2. 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)
  3. elemOffset number which VBO element to start uploading data from Lua array into (default 0)
  4. luaStartIndex number start uploading from that element in supplied Lua array (default 0)
  5. luaFinishIndex number consider this element the last element in Lua array (optional)

Returns:

  1. {number, ...} indexData
  2. number elemOffset
  3. 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:

  1. attributeIndex number when supplied with non-default value: only data from specified attribute will be downloaded - otherwise all attributes are downloaded (default -1)
  2. elementOffset number download data starting from this element (default 0)
  3. elementCount number number of elements to download (optional)
  4. forceGPURead bool force downloading the data from GPU buffer as opposed to using shadow RAM buffer (default false)

Returns:

  1. {{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:

  1. 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:

  1. unitDefIDs number or {number,...}
  2. attrID number
  3. teamIdOpt number (optional)
  4. elementOffset number (optional)

Returns:

  1. {number,number,number,number} instanceData
  2. number elementOffset
  3. 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:

  1. featureDefIDs number or {number,...}
  2. attrID number
  3. teamIdOpt number (optional)
  4. elementOffset number (optional)

Returns:

  1. {number,number,number,number} instanceData
  2. number elementOffset
  3. 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:

  1. unitIDs number or {number,...}
  2. attrID number
  3. teamIdOpt number (optional)
  4. elementOffset number (optional)

Returns:

  1. {number,number,number,number} instanceData
  2. number elementOffset
  3. 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:

  1. featureIDs number or {number,...}
  2. attrID number
  3. teamIdOpt number (optional)
  4. elementOffset number (optional)

Returns:

  1. {number,number,number,number} instanceData
  2. number elementOffset
  3. attrID

VBO:MatrixDataFromProjectileIDs(projectileIDs, attrID[, teamIdOpt[, elementOffset]])

Parameters:

  1. projectileIDs number or {number,...}
  2. attrID number
  3. teamIdOpt number (optional)
  4. elementOffset number (optional)

Returns:

  1. {number, ...} matDataVec 4x4 matrix
  2. number elemOffset
  3. 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:

  1. index number should be in the range between 5 < index < GL_MAX_UNIFORM_BUFFER_BINDINGS value (usually 31)
  2. elementOffset number (optional)
  3. elementCount number (optional)
  4. target number glEnum (optional)

Returns:

  1. number bindingIndex when successful, -1 otherwise

VBO:UnbindBufferRange(index[, elementOffset[, elementCount[, target]]])

Parameters:

  1. index number
  2. elementOffset number (optional)
  3. elementCount number (optional)
  4. target number glEnum (optional)

Returns:

  1. number bindingIndex when successful, -1 otherwise

VBO:DumpDefinition()

Logs the definition of the VBO to the console

Returns:

  1. nil