-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path25_texture_mapping.diff
More file actions
84 lines (80 loc) · 3.02 KB
/
25_texture_mapping.diff
File metadata and controls
84 lines (80 loc) · 3.02 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
diff --git a/../steps/24_sampler/main.go b/../steps/25_texture_mapping/main.go
index 5fdfdf0..706f57c 100644
--- a/../steps/24_sampler/main.go
+++ b/../steps/25_texture_mapping/main.go
@@ -52,6 +52,7 @@ type SwapChainSupportDetails struct {
type Vertex struct {
Position vkngmath.Vec2[float32]
Color vkngmath.Vec3[float32]
+ TexCoord vkngmath.Vec2[float32]
}
type UniformBufferObject struct {
@@ -86,14 +87,20 @@ func getVertexAttributeDescriptions() []core1_0.VertexInputAttributeDescription
Format: core1_0.FormatR32G32B32SignedFloat,
Offset: int(unsafe.Offsetof(v.Color)),
},
+ {
+ Binding: 0,
+ Location: 2,
+ Format: core1_0.FormatR32G32SignedFloat,
+ Offset: int(unsafe.Offsetof(v.TexCoord)),
+ },
}
}
var vertices = []Vertex{
- {Position: vkngmath.Vec2[float32]{X: -0.5, Y: -0.5}, Color: vkngmath.Vec3[float32]{X: 1, Y: 0, Z: 0}},
- {Position: vkngmath.Vec2[float32]{X: 0.5, Y: -0.5}, Color: vkngmath.Vec3[float32]{X: 0, Y: 1, Z: 0}},
- {Position: vkngmath.Vec2[float32]{X: 0.5, Y: 0.5}, Color: vkngmath.Vec3[float32]{X: 0, Y: 0, Z: 1}},
- {Position: vkngmath.Vec2[float32]{X: -0.5, Y: 0.5}, Color: vkngmath.Vec3[float32]{X: 1, Y: 1, Z: 1}},
+ {Position: vkngmath.Vec2[float32]{X: -0.5, Y: -0.5}, Color: vkngmath.Vec3[float32]{X: 1, Y: 0, Z: 0}, TexCoord: vkngmath.Vec2[float32]{X: 1, Y: 0}},
+ {Position: vkngmath.Vec2[float32]{X: 0.5, Y: -0.5}, Color: vkngmath.Vec3[float32]{X: 0, Y: 1, Z: 0}, TexCoord: vkngmath.Vec2[float32]{X: 0, Y: 0}},
+ {Position: vkngmath.Vec2[float32]{X: 0.5, Y: 0.5}, Color: vkngmath.Vec3[float32]{X: 0, Y: 0, Z: 1}, TexCoord: vkngmath.Vec2[float32]{X: 0, Y: 1}},
+ {Position: vkngmath.Vec2[float32]{X: -0.5, Y: 0.5}, Color: vkngmath.Vec3[float32]{X: 1, Y: 1, Z: 1}, TexCoord: vkngmath.Vec2[float32]{X: 1, Y: 1}},
}
var indices = []uint16{0, 1, 2, 2, 3, 0}
@@ -830,6 +837,13 @@ func (app *HelloTriangleApplication) createDescriptorSetLayout() error {
StageFlags: core1_0.StageVertex,
},
+ {
+ Binding: 1,
+ DescriptorType: core1_0.DescriptorTypeCombinedImageSampler,
+ DescriptorCount: 1,
+
+ StageFlags: core1_0.StageFragment,
+ },
},
})
if err != nil {
@@ -1352,6 +1366,10 @@ func (app *HelloTriangleApplication) createDescriptorPool() error {
Type: core1_0.DescriptorTypeUniformBuffer,
DescriptorCount: len(app.swapchainImages),
},
+ {
+ Type: core1_0.DescriptorTypeCombinedImageSampler,
+ DescriptorCount: len(app.swapchainImages),
+ },
},
})
return err
@@ -1389,6 +1407,21 @@ func (app *HelloTriangleApplication) createDescriptorSets() error {
},
},
},
+ {
+ DstSet: app.descriptorSets[i],
+ DstBinding: 1,
+ DstArrayElement: 0,
+
+ DescriptorType: core1_0.DescriptorTypeCombinedImageSampler,
+
+ ImageInfo: []core1_0.DescriptorImageInfo{
+ {
+ ImageView: app.textureImageView,
+ Sampler: app.textureSampler,
+ ImageLayout: core1_0.ImageLayoutShaderReadOnlyOptimal,
+ },
+ },
+ },
}, nil)
if err != nil {
return err