程序代写代做代考 10: The OpenGL Pipeline

10: The OpenGL Pipeline

06: Adding Vertex Buffers

COMP5822M: High Performance Graphics
Vertex Buffers
Yesterday, we hard-coded vertex positions
Next, we want to pass them in
Which means we need vertex buffers
In Vulkan, there are just buffers (arrays)
A vertex buffer is just a buffer full of vertices
And has no special meaning

COMP5822M: High Performance Graphics
Working with Vertex Buffers
A vertex buffer is just a chunk of memory
But where?
How do we allocate it?
How do we transfer data to it?
How do we connect it into the pipeline?
How does the shader access it?

COMP5822M: High Performance Graphics
Possible Locations
A vertex buffer can be:
In main RAM
In shared (mapped) memory
In host-accessible VRAM
In GPU-only VRAM (fastest)
The question is really how do we transfer it

COMP5822M: High Performance Graphics
Vertex Buffer Contents
Ideally, we have a package of attributes

And then a vector full of them:

COMP5822M: High Performance Graphics
Variations
We might want to have separate arrays

Or a combination:

COMP5822M: High Performance Graphics
Consequences
Vulkan cannot make assumptions about format
So we have to give explicit detail:
How many attributes
How they are laid out in memory
Their offset in the array
The stride between elements in the buffer
This is used to instantiate the buffer

COMP5822M: High Performance Graphics

Setting It Up

COMP5822M: High Performance Graphics
Transferring the Data
We want the data to end up in fast VRAM
So we will have to copy it twice:
Once into CPU-accessible VRAM
Call this the staging buffer
Then into GPU-only fast VRAM
The actual vertex buffer

COMP5822M: High Performance Graphics
The Staging Buffer

COMP5822M: High Performance Graphics

COMP5822M: High Performance Graphics
Shader Access
The shader still needs to access the attributes
This is done through layout and location

COMP5822M: High Performance Graphics
Replacing the FF Pipeline
We will load the vertices into a vertex buffer
We need to pass in the matrices as descriptors
Vertex shader will apply the matrices
Compute position & normal
Fragment shader will do the Phong lighting

COMP5822M: High Performance Graphics