AcquireNextImage gets the next frame index to render to. It automatically handles any issues with out-of-date swapchain. It triggers the ImageAcquired semaphore when image actually acquired. Must call SubmitRender with command to launch command contingent on that semaphore. It returns false if the s
()
| 350 | // Must call SubmitRender with command to launch command contingent |
| 351 | // on that semaphore. It returns false if the swapchain size is zero. |
| 352 | func (sf *Surface) AcquireNextImage() (uint32, bool) { |
| 353 | dev := sf.Device.Device |
| 354 | for { |
| 355 | vk.WaitForFences(dev, 1, []vk.Fence{sf.RenderFence}, vk.True, vk.MaxUint64) |
| 356 | vk.ResetFences(dev, 1, []vk.Fence{sf.RenderFence}) |
| 357 | var idx uint32 |
| 358 | if sf.NeedsConfig { |
| 359 | // we must skip FreeSwapchain for NeedsConfig |
| 360 | if !sf.ConfigSwapchain() { |
| 361 | if Debug { |
| 362 | fmt.Println("vgpu.Surface.AcquireNextImage: bailing on ConfigSwapchain caused by NeedsConfig (somewhat unexpected)") |
| 363 | } |
| 364 | return idx, false |
| 365 | } |
| 366 | sf.Render.SetSize(sf.Format.Size) |
| 367 | sf.ReConfigFrames() |
| 368 | sf.NeedsConfig = false |
| 369 | if Debug { |
| 370 | fmt.Println("vgpu.Surface.AcquireNextImage: did NeedsConfig update") |
| 371 | } |
| 372 | continue |
| 373 | } |
| 374 | ret := vk.AcquireNextImage(dev, sf.Swapchain, vk.MaxUint64, sf.ImageAcquired, vk.NullFence, &idx) |
| 375 | switch ret { |
| 376 | case vk.ErrorOutOfDate, vk.Suboptimal: |
| 377 | if !sf.ReConfigSwapchain() { |
| 378 | if Debug { |
| 379 | fmt.Println("vgpu.Surface.AcquireNextImage: bailing on zero swapchain size") |
| 380 | } |
| 381 | sf.NeedsConfig = true |
| 382 | return idx, false |
| 383 | } |
| 384 | if Debug { |
| 385 | fmt.Printf("vgpu.Surface.AcquireNextImage: new format: %#v\n", sf.Format) |
| 386 | } |
| 387 | continue // try again |
| 388 | case vk.Success: |
| 389 | return idx, true |
| 390 | default: |
| 391 | IfPanic(NewError(ret)) |
| 392 | return idx, true |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | // SubmitRender submits a rendering command that must have been added |
| 398 | // to the given command buffer, calling CmdEnd on the buffer first. |
no test coverage detected