From 09250ff4f3ee62e734970370d9d4670b4caacca7 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 30 Mar 2023 21:08:20 +0900 Subject: [PATCH] internal/graphicsdriver/directx: adjust buffer count Apparently the buffer count should be 1 with a non-flipping swap effect. Updates #2613 --- internal/graphicsdriver/directx/graphics_windows.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/graphicsdriver/directx/graphics_windows.go b/internal/graphicsdriver/directx/graphics_windows.go index c62394246..eb86e1dc8 100644 --- a/internal/graphicsdriver/directx/graphics_windows.go +++ b/internal/graphicsdriver/directx/graphics_windows.go @@ -156,6 +156,8 @@ type graphicsInfra struct { // lastTime is the last time for rendering. lastTime time.Time + + bufferCount int } func newGraphicsInfra() (*graphicsInfra, error) { @@ -275,8 +277,11 @@ func (g *graphicsInfra) initSwapChain(width, height int, device unsafe.Pointer, // https://learn.microsoft.com/en-us/windows/win32/api/dxgi/ne-dxgi-dxgi_swap_effect if !isWindows10OrGreaterWin32() { desc.SwapEffect = _DXGI_SWAP_EFFECT_SEQUENTIAL + desc.BufferCount = 1 } + g.bufferCount = int(desc.BufferCount) + if g.allowTearing { desc.Flags |= uint32(_DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) } @@ -313,7 +318,7 @@ func (g *graphicsInfra) resizeSwapChain(width, height int) error { if g.allowTearing { flag |= uint32(_DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) } - if err := g.swapChain.ResizeBuffers(frameCount, uint32(width), uint32(height), _DXGI_FORMAT_B8G8R8A8_UNORM, flag); err != nil { + if err := g.swapChain.ResizeBuffers(uint32(g.bufferCount), uint32(width), uint32(height), _DXGI_FORMAT_B8G8R8A8_UNORM, flag); err != nil { return err } return nil