You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `bufferSize` is now equal to the number of indices times the size of the index type, either `uint16_t` or `uint32_t`.
92
-
The usage of the `indexBuffer` should be `VK_BUFFER_USAGE_INDEX_BUFFER_BIT` instead of `VK_BUFFER_USAGE_VERTEX_BUFFER_BIT`, which makes sense.
94
+
The usage of the `indexBuffer` should be `vk::BufferUsageFlagBits::eIndexBuffer` instead of `vk::BufferUsageFlagBits::eVertexBuffer`, which makes sense.
93
95
Other than that, the process is exactly the same.
94
96
We create a staging buffer to copy the contents of `indices` to and then copy it to the final device local index buffer.
95
97
@@ -103,21 +105,21 @@ It's unfortunately not possible to use different indices for each vertex attribu
An index buffer is bound with `vkCmdBindIndexBuffer` which has the index buffer, a byte offset into it, and the type of index data as parameters.
110
-
As mentioned before, the possible types are `VK_INDEX_TYPE_UINT16` and `VK_INDEX_TYPE_UINT32`.
111
+
An index buffer is bound with `vk::raii::CommandBuffer::bindIndexBuffer` which has the index buffer, a byte offset into it, and the type of index data as parameters.
112
+
As mentioned before, the possible types are `vk::IndexType::eUint16` and `vk::IndexType::eUint32`.
111
113
112
114
Just binding an index buffer doesn't change anything yet, we also need to change the drawing command to tell Vulkan to use the index buffer.
113
-
Remove the `vkCmdDraw` line and replace it with `vkCmdDrawIndexed`:
115
+
Remove the `vk::raii::CommandBuffer::draw` line and replace it with `vk::raii::CommandBuffer::drawIndexed`:
A call to this function is very similar to `vkCmdDraw`.
122
+
A call to this function is very similar to `vk::raii::CommandBuffer::draw`.
121
123
The first two parameters specify the number of indices and the number of instances.
122
124
We're not using instancing, so just specify `1` instance.
123
125
The number of indices represents the number of vertices that will be passed to the vertex shader.
@@ -133,7 +135,7 @@ You now know how to save memory by reusing vertices with index buffers.
133
135
This will become especially important in a future chapter where we're going to load complex 3D models.
134
136
135
137
The previous chapter already mentioned that you should allocate multiple resources like buffers from a single memory allocation, but in fact you should go a step further.
136
-
https://developer.nvidia.com/vulkan-memory-management[Driver developers recommend] that you also store multiple buffers, like the vertex and index buffer, into a single `VkBuffer` and use offsets in commands like `vkCmdBindVertexBuffers`.
138
+
https://developer.nvidia.com/vulkan-memory-management[Driver developers recommend] that you also store multiple buffers, like the vertex and index buffer, into a single `vk::raii::Buffer` and use offsets in commands like `vk::raii::CommandBuffer::bindVertexBuffers`.
137
139
The advantage is that your data is more cache friendly in that case, because it's closer together.
138
140
It is even possible to reuse the same chunk of memory for multiple resources if they are not used during the same render operations, provided that their data is refreshed, of course.
139
141
This is known as _aliasing_ and some Vulkan functions have explicit flags to specify that you want to do this.
0 commit comments