MCPcopy Create free account
hub / github.com/cogentcore/core / ConfigSwapchain

Method ConfigSwapchain

vgpu/surface.go:126–289  ·  view source on GitHub ↗

ConfigSwapchain configures the swapchain for surface. This assumes that all existing items have been destroyed. It returns false if the swapchain size is zero.

()

Source from the content-addressed store, hash-verified

124// This assumes that all existing items have been destroyed.
125// It returns false if the swapchain size is zero.
126func (sf *Surface) ConfigSwapchain() bool {
127 dev := sf.Device.Device
128
129 // Read sf.Surface capabilities
130 var surfaceCapabilities vk.SurfaceCapabilities
131 ret := vk.GetPhysicalDeviceSurfaceCapabilities(sf.GPU.GPU, sf.Surface, &surfaceCapabilities)
132 IfPanic(NewError(ret))
133 surfaceCapabilities.Deref()
134
135 // Get available surface pixel formats
136 var formatCount uint32
137 vk.GetPhysicalDeviceSurfaceFormats(sf.GPU.GPU, sf.Surface, &formatCount, nil)
138 formats := make([]vk.SurfaceFormat, formatCount)
139 vk.GetPhysicalDeviceSurfaceFormats(sf.GPU.GPU, sf.Surface, &formatCount, formats)
140
141 // Select a proper surface format
142 var format vk.SurfaceFormat
143 if formatCount == 1 {
144 formats[0].Deref()
145 if formats[0].Format == vk.FormatUndefined {
146 format = formats[0]
147 format.Format = sf.Format.Format
148 } else {
149 format = formats[0]
150 }
151 } else if formatCount == 0 {
152 IfPanic(errors.New("vulkan error: surface has no pixel formats"))
153 } else {
154 got := false
155 for _, df := range sf.DesiredFormats {
156 for _, ft := range formats {
157 ft.Deref()
158 if ft.Format == df {
159 format = ft
160 got = true
161 break
162 }
163 }
164 if got {
165 break
166 }
167 }
168 if !got {
169 formats[0].Deref()
170 format = formats[0]
171 if Debug {
172 dfs := make([]string, len(sf.DesiredFormats))
173 for i, df := range sf.DesiredFormats {
174 dfs[i] = ImageFormatNames[df]
175 }
176 fmt.Printf("vgpu.Surface:Init unable to find desired format: %v, using first one: %s\n", dfs, ImageFormatNames[format.Format])
177 }
178 }
179 }
180
181 // Setup swapchain parameters
182 var swapchainSize vk.Extent2D
183 surfaceCapabilities.CurrentExtent.Deref()

Callers 3

InitMethod · 0.95
ReConfigSwapchainMethod · 0.95
AcquireNextImageMethod · 0.95

Calls 9

ConfigSurfaceImageMethod · 0.95
IfPanicFunction · 0.85
NewErrorFunction · 0.85
NewSemaphoreFunction · 0.85
NewFenceFunction · 0.85
Size32Method · 0.80
NewMethod · 0.65
SetMethod · 0.65
PrintfMethod · 0.45

Tested by

no test coverage detected