![]() |
Vireo
0.0
Vireo 3D Rendering Hardware Interface
|
Our triangle vertices will be hard-coded into the application. Add the struct describing a vertex composed of a XYZ position and an RGB color in your class interface:
Add the triangle data with a different color for each vertex, after the Vertex
struct:
The next step is to tell the graphic API how to pass this data format to the vertex shader once it's been uploaded into GPU memory. We have to describe each field of the Vertex
struct using VertexAttributeDesc, after the triangle data:
This vector is used to create the vertex layout for the future pipeline. Add the following code before the for loop in the onInit()
method:
We are done with the vertex layout. Now we have to upload the vertex data into the VRAM in a vireo::BufferType::VERTEX buffer. Add the buffer field to your application :
In the onInit()
method, just before the createVertexLayout()
line, add the buffer creation :
We will use a vireo::CommandType::TRANSFER command list to upload the vertex data into the VRAM. You can use a vireo::CommandType::GRAPHIC command list for that but the vireo::CommandType::TRANSFER command buffers and submit queues can take advantage of DMA transfers.
In the onInit()
method, just after the buffer creation add the command allocator and command list creation :
Followed by the recording of the upload command :
Then the submission of the commands using a vireo::CommandType::TRANSFER submit queue :
Since the upload operation is asynchronous, we have to wait for the command to finish before terminating the onInit()
method. Add the following code at the end of the method :
By adding the vireo::SubmitQueue::waitIdle at the end of the method, the upload operation will be executed while we continue to create our pipeline.
Note that we call the vireo::CommandList::cleanup method to clear the temporary (staging) buffer used for the host-to-device copy of the vertex data. The asynchronous nature of the operation means that we have to wait for the end of the operation to free the host-visible allocated memory. This is done automatically in the command list destructor, but we added this call in the tutorial for clarification.
Next : The graphic pipeline
Related manual page : Memory buffers