forked from vkngwrapper/vulkan-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path17_vertex_input.diff
71 lines (67 loc) · 2.06 KB
/
17_vertex_input.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
diff --git a/../steps/16_swap_chain_recreation/main.go b/../steps/17_vertex_input/main.go
index 4d47c48..249e800 100644
--- a/../steps/16_swap_chain_recreation/main.go
+++ b/../steps/17_vertex_input/main.go
@@ -14,6 +14,7 @@ import (
"github.com/vkngwrapper/extensions/v2/khr_swapchain"
vkng_sdl2 "github.com/vkngwrapper/integrations/sdl2/v2"
"log"
+ "unsafe"
)
//go:embed shaders
@@ -41,6 +42,46 @@ type SwapChainSupportDetails struct {
PresentModes []khr_surface.PresentMode
}
+type Vertex struct {
+ X, Y float32 // Could also be Position Vector2 - as long as Vector2 is a value, not a pointer
+ R, G, B float32 // Could also be Color Vector3
+}
+
+func getVertexBindingDescription() []core1_0.VertexInputBindingDescription {
+ v := Vertex{}
+ return []core1_0.VertexInputBindingDescription{
+ {
+ Binding: 0,
+ Stride: int(unsafe.Sizeof(v)),
+ InputRate: core1_0.VertexInputRateVertex,
+ },
+ }
+}
+
+func getVertexAttributeDescriptions() []core1_0.VertexInputAttributeDescription {
+ v := Vertex{}
+ return []core1_0.VertexInputAttributeDescription{
+ {
+ Binding: 0,
+ Location: 0,
+ Format: core1_0.FormatR32G32SignedFloat,
+ Offset: int(unsafe.Offsetof(v.X)),
+ },
+ {
+ Binding: 0,
+ Location: 1,
+ Format: core1_0.FormatR32G32B32SignedFloat,
+ Offset: int(unsafe.Offsetof(v.R)),
+ },
+ }
+}
+
+var vertices = []Vertex{
+ {X: 0, Y: -0.5, R: 1, G: 0, B: 0},
+ {X: 0.5, Y: 0.5, R: 0, G: 1, B: 0},
+ {X: -0.5, Y: 0.5, R: 0, G: 0, B: 1},
+}
+
type HelloTriangleApplication struct {
window *sdl.Window
loader core.Loader
@@ -695,7 +736,10 @@ func (app *HelloTriangleApplication) createGraphicsPipeline() error {
}
defer fragShader.Destroy(nil)
- vertexInput := &core1_0.PipelineVertexInputStateCreateInfo{}
+ vertexInput := &core1_0.PipelineVertexInputStateCreateInfo{
+ VertexBindingDescriptions: getVertexBindingDescription(),
+ VertexAttributeDescriptions: getVertexAttributeDescriptions(),
+ }
inputAssembly := &core1_0.PipelineInputAssemblyStateCreateInfo{
Topology: core1_0.PrimitiveTopologyTriangleList,