BasicInstancedVertexArray
in package
See "BasicVertexArray.php" this is basically the same but with an additional buffer for instanced data.
Keep in bind these basic classes are not meant to be useful for every use case, If you have to handle more complex vertex layouts you should handle it yourself.
Also here all values are assumed to be floats.
You can specify a simple vertex layout by specifying the element sizes in sequence. Example: [3, 2] = vec3, vec2 = 5 floats per vertex [3, 2, 3] = vec3, vec2, vec3 = 8 floats per vertex [3, 2, 3, 1] = vec3, vec2, vec3, float = 9 floats per vertex // etc..
Table of Contents
Properties
- $instanceBuffer : int
- The instanced data buffer object from GL
- $vertexArray : int
- The vertex array object from GL
- $vertexBuffer : int
- The vertex buffer object from GL
- $floatsPerInstance : int
- Number of floats per instance
- $floatsPerVertex : int
- Number of floats per vertex
- $instanceCount : int
- Number of instances
- $state : GLState
- $vertexCount : int
- Vertex count
Methods
- __construct() : void
- Constructor
- __destruct() : void
- Destructor
- bind() : void
- Binds the vertex array
- draw() : void
- Draws a range of vertices
- drawAll() : void
- Draws all vertices
- uploadInstanceData() : void
- Uploads the instance data to the GPU
- uploadVertexData() : void
- Uploads the vertex data to the GPU
Properties
$instanceBuffer read-only
The instanced data buffer object from GL
public
int
$instanceBuffer
$vertexArray read-only
The vertex array object from GL
public
int
$vertexArray
$vertexBuffer read-only
The vertex buffer object from GL
public
int
$vertexBuffer
$floatsPerInstance
Number of floats per instance
private
int
$floatsPerInstance
= 0
$floatsPerVertex
Number of floats per vertex
private
int
$floatsPerVertex
= 0
$instanceCount
Number of instances
private
int
$instanceCount
= 0
$state
private
GLState
$state
$vertexCount
Vertex count
private
int
$vertexCount
= 0
Methods
__construct()
Constructor
public
__construct(GLState $state, array<string|int, int> $vertexLayout, array<string|int, int> $instanceLayout) : void
Parameters
- $state : GLState
- $vertexLayout : array<string|int, int>
-
The vertex layout
- $instanceLayout : array<string|int, int>
-
The instance layout
__destruct()
Destructor
public
__destruct() : void
bind()
Binds the vertex array
public
bind() : void
draw()
Draws a range of vertices
public
draw(int $vertexOffset, int $vertexCount, int $instanceCount[, int $drawMode = GL_TRIANGLES ]) : void
Parameters
- $vertexOffset : int
-
The vertex offset
- $vertexCount : int
-
The vertex count
- $instanceCount : int
-
The instance count
- $drawMode : int = GL_TRIANGLES
-
The draw mode (default: GL_TRIANGLES)
drawAll()
Draws all vertices
public
drawAll([int $drawMode = GL_TRIANGLES ]) : void
Parameters
- $drawMode : int = GL_TRIANGLES
uploadInstanceData()
Uploads the instance data to the GPU
public
uploadInstanceData(FloatBuffer $instanceData) : void
Parameters
- $instanceData : FloatBuffer
-
The instance data
uploadVertexData()
Uploads the vertex data to the GPU
public
uploadVertexData(FloatBuffer $vertexData) : void
Parameters
- $vertexData : FloatBuffer
-
The vertex data