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
Buffers can be backed by host (RAM) or device (VRAM) memory: the former is mappable and thus useful for data that changes every frame, latter is faster to access for the GPU but needs more complex methods to copy data from the CPU to it. Add the relevant subset of parameters and the RAII wrapper:
31
+
Buffers can be backed by host (RAM) or device (VRAM) memory: the former is mappable and thus useful for data that changes every frame, latter is faster to access for the GPU but needs more complex methods to copy data from the CPU to it. Leaving device buffers for later, add the `Buffer` alias and a create function:
29
32
30
33
```cpp
31
-
enum class BufferType : std::int8_t { Host, Device };
The goal here is to move the hard-coded vertices in the shader to application code. For the time being we will use an ad-hoc host`vma::Buffer` and focus more on the rest of the infrastructure like vertex attributes.
3
+
The goal here is to move the hard-coded vertices in the shader to application code. For the time being we will use an ad-hoc Host type`vma::Buffer` and focus more on the rest of the infrastructure like vertex attributes.
4
4
5
5
First add a new header, `vertex.hpp`:
6
6
@@ -9,11 +9,7 @@ struct Vertex {
9
9
glm::vec2 position{};
10
10
glm::vec3 color{};
11
11
};
12
-
```
13
-
14
-
In `app.cpp`, store the vertex input:
15
12
16
-
```cpp
17
13
// two vertex attributes: position at 0, color at 1.
18
14
constexpr auto vertex_attributes_v = std::array{
19
15
// the format matches the type and layout of data: vec2 => 2x 32-bit floats.
@@ -30,21 +26,24 @@ constexpr auto vertex_bindings_v = std::array{
You should see the same triangle as before. But now we can use whatever set of vertices we like! To change it to a quad / rectangle, let's utilize an index buffer: this will reduce vertex duplication in general.
102
-
103
-
```cpp
104
-
voidApp::create_vertex_buffer() {
105
-
// we want to write 4x Vertex objects to a Host VertexBuffer.
Bind the index buffer and use the `drawIndexed()` command:
100
+
You should see the same triangle as before. But now we can use whatever set of vertices we like! The Primitive Topology is Triange List by default, so every three vertices in the array is drawn as a triangle, eg for 9 vertices: `[[0, 1, 2], [3, 4, 5], [6, 7, 8]]`, where each inner `[]` represents a triangle comprised of the vertices at those indices.
Host Vertex Buffers are useful for primitives that are temporary and/or frequently changing, such as UI objects. A 2D framework can use such VBOs exclusively: a simple approach would be a pool of buffers per virtual frame where for each draw a buffer is obtained from the current virtual frame's pool and vertices are copied in.
0 commit comments