-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path07_image_views.diff
More file actions
72 lines (66 loc) · 2.02 KB
/
07_image_views.diff
File metadata and controls
72 lines (66 loc) · 2.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
diff --git a/../steps/06_swapchain/main.go b/../steps/07_image_views/main.go
index 5536e3b..e03d590 100644
--- a/../steps/06_swapchain/main.go
+++ b/../steps/07_image_views/main.go
@@ -54,6 +54,7 @@ type HelloTriangleApplication struct {
swapchainImages []core1_0.Image
swapchainImageFormat core1_0.Format
swapchainExtent core1_0.Extent2D
+ swapchainImageViews []core1_0.ImageView
}
func (app *HelloTriangleApplication) Run() error {
@@ -134,6 +135,10 @@ appLoop:
}
func (app *HelloTriangleApplication) cleanup() {
+ for _, imageView := range app.swapchainImageViews {
+ imageView.Destroy(nil)
+ }
+
if app.swapchain != nil {
app.swapchain.Destroy(nil)
}
@@ -270,7 +275,7 @@ func (app *HelloTriangleApplication) pickPhysicalDevice() error {
}
if app.physicalDevice == nil {
- return errors.New("failed to find a suitable GPU!")
+ return errors.Errorf("failed to find a suitable GPU!")
}
return nil
@@ -378,6 +383,39 @@ func (app *HelloTriangleApplication) createSwapchain() error {
app.swapchainExtent = extent
app.swapchain = swapchain
+ images, _, err := swapchain.SwapchainImages()
+ if err != nil {
+ return err
+ }
+ app.swapchainImages = images
+
+ var imageViews []core1_0.ImageView
+ for _, image := range images {
+ view, _, err := app.device.CreateImageView(nil, core1_0.ImageViewCreateInfo{
+ ViewType: core1_0.ImageViewType2D,
+ Image: image,
+ Format: surfaceFormat.Format,
+ Components: core1_0.ComponentMapping{
+ R: core1_0.ComponentSwizzleIdentity,
+ G: core1_0.ComponentSwizzleIdentity,
+ B: core1_0.ComponentSwizzleIdentity,
+ A: core1_0.ComponentSwizzleIdentity,
+ },
+ SubresourceRange: core1_0.ImageSubresourceRange{
+ AspectMask: core1_0.ImageAspectColor,
+ BaseMipLevel: 0,
+ LevelCount: 1,
+ BaseArrayLayer: 0,
+ LayerCount: 1,
+ },
+ })
+ if err != nil {
+ return err
+ }
+
+ imageViews = append(imageViews, view)
+ }
+ app.swapchainImageViews = imageViews
app.swapchainImageFormat = surfaceFormat.Format
return nil