I have some code that uses DirectX 9 with Windows native window management, that I would like to port to newer graphics APIs, but this code has a fairly unusual approach to window resizing, and it doesn't seem obvious how to achieve the same things with newer graphics APIs.
The code I want to port allocates a back buffer large enough for a full screen window which remains the same size across window maximised, minimised, and resize events. When the window is smaller than the back buffer, only part of the back buffer is shown.
In order to render from this large back buffer, in DirectX 9, I'm specifying regions with the pSourceRect and pDestRect in IDirect3DDevice9::Present and using D3DSWAPEFFECT_COPY.
The advantages of this, as I see it, are as follows:
- There's no need to free and reallocate any resources in response to window size changes.
- Not reallocating resources reduces code complexity significantly.
- Not reallocating resources makes the application more responsive in the case of windows size changes.
- The rendered scene continues to be drawn, smoothly, as the application window is being resized, without any need for potentially tricky and complicated attempts to update rendering settings in response to resize events.
(As the code is written, the application is essentially paused during window resize. The user nevertheless gets a smoothly updated view of the relevant part of the current static rendered scene during window resize.)
How do I do the same thing with newer graphics APIs?
In newer DirectX versions it seems like the 'BitBlt model' described on this page roughly corresponds to D3DSWAPEFFECT_COPY in DirectX 9: https://docs.microsoft.com/en-us/windows/win32/direct3ddxgi/dxgi-flip-model
However, when I try setting the swap effect to DXGI_SWAP_EFFECT_DISCARD, in DirectX 12, I get the following error: IDXGIFactory::CreateSwapChain: This D3D API version requires the swap effect to be one of DXGI_SWAP_EFFECT_FLIP_*.
So I guess the BitBlit model is no longer supported. :(
I guess a logical alternative would then be to do something equivalent 'manually', but it seems like doing something like this would lose one of the advantages of the trick, as it works out in DirectX 9, which is the smooth update during resizing without needing to intercept resize events and update stuff in response to these, in the application code.
What I'd like to see, ideally, are links to working code that does something equivalent to what I'm doing in DirectX 9, in DirectX 12, OpenGL, or Vulkan.
If it helps to see the code in action, and the resulting resize behaviour, you can see this in the PathEngine graphical testbed, which can be downloaded here: https://pathengine.com/downloads (And I could also look at stripping out and posting source code for a minimal example application that demonstrates this behaviour, if this would help.)