-
Notifications
You must be signed in to change notification settings - Fork 2
/
13_framebuffers.diff
77 lines (71 loc) · 2.44 KB
/
13_framebuffers.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
72
73
74
75
76
77
diff --git a/../steps/12_graphics_pipeline_complete/main.go b/../steps/13_framebuffers/main.go
index 00e5503..f04de7b 100644
--- a/../steps/12_graphics_pipeline_complete/main.go
+++ b/../steps/13_framebuffers/main.go
@@ -53,12 +53,13 @@ type HelloTriangleApplication struct {
graphicsQueue core1_0.Queue
presentQueue core1_0.Queue
- swapchainExtension khr_swapchain.Extension
- swapchain khr_swapchain.Swapchain
- swapchainImages []core1_0.Image
- swapchainImageFormat core1_0.Format
- swapchainExtent core1_0.Extent2D
- swapchainImageViews []core1_0.ImageView
+ swapchainExtension khr_swapchain.Extension
+ swapchain khr_swapchain.Swapchain
+ swapchainImages []core1_0.Image
+ swapchainImageFormat core1_0.Format
+ swapchainExtent core1_0.Extent2D
+ swapchainImageViews []core1_0.ImageView
+ swapchainFramebuffers []core1_0.Framebuffer
renderPass core1_0.RenderPass
pipelineLayout core1_0.PipelineLayout
@@ -135,7 +136,12 @@ func (app *HelloTriangleApplication) initVulkan() error {
return err
}
- return app.createGraphicsPipeline()
+ err = app.createGraphicsPipeline()
+ if err != nil {
+ return err
+ }
+
+ return app.createFramebuffers()
}
func (app *HelloTriangleApplication) mainLoop() error {
@@ -153,6 +159,10 @@ appLoop:
}
func (app *HelloTriangleApplication) cleanup() {
+ for _, framebuffer := range app.swapchainFramebuffers {
+ framebuffer.Destroy(nil)
+ }
+
if app.graphicsPipeline != nil {
app.graphicsPipeline.Destroy(nil)
}
@@ -642,6 +652,27 @@ func (app *HelloTriangleApplication) createGraphicsPipeline() error {
return nil
}
+func (app *HelloTriangleApplication) createFramebuffers() error {
+ for _, imageView := range app.swapchainImageViews {
+ framebuffer, _, err := app.device.CreateFramebuffer(nil, core1_0.FramebufferCreateInfo{
+ RenderPass: app.renderPass,
+ Layers: 1,
+ Attachments: []core1_0.ImageView{
+ imageView,
+ },
+ Width: app.swapchainExtent.Width,
+ Height: app.swapchainExtent.Height,
+ })
+ if err != nil {
+ return err
+ }
+
+ app.swapchainFramebuffers = append(app.swapchainFramebuffers, framebuffer)
+ }
+
+ return nil
+}
+
func (app *HelloTriangleApplication) chooseSwapSurfaceFormat(availableFormats []khr_surface.SurfaceFormat) khr_surface.SurfaceFormat {
for _, format := range availableFormats {
if format.Format == core1_0.FormatB8G8R8A8SRGB && format.ColorSpace == khr_surface.ColorSpaceSRGBNonlinear {