DirectX11 and Alt+Tab

Started by
6 comments, last by NSG 13 years, 6 months ago
I'm new to DirectX11 after lots of programming in DirectX9. I find it's far cleaner and smarter, generally I like it.

I'm having a problem with it's alt+tab handling, I turned the automatic handling of it off as I very much disliked DXGI's auto handling. Now all resizing and full screen switching is done by my application.

The problem is that when in full screen, if I alt+tab, the program goes back to windowed automatically and since the application didn't actually initiate this, the back buffer and etc are still at the same resolution as when in full screen.

I don't want windows to automatically window my full screen app just because of alt+tab, basically I'm looking for functionality similar to DirectX9 where alt+tab doesn't do anything to the window but activate another.
Advertisement
I think that you'll have to let the swapchain handle the alt+tab then. What problems are you having with the spawchain's handling that caused you to disable it? Perhaps we can help you through any difficulties.
I had the same problems I'm having now only if you use the DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH flag for the swap chain, you have to handle changing render targets and back buffer etc in WM_SIZE which just felt very messy and annoying. I would prefer the application decide when to change what.
So basically even if I let DXGI handle alt+tab, it would still be the same problem I'm having now, which is that alt+tabbing out of a full screen D3D11 application causes it to revert to a windowed application.
Handling windows messages is just part of writing an app. You've probably already done this for key and mouse events and the same messages apply whether you're in fullscreen or windowed. The size message will be the cleanest way to determine if the resolution is changing and then it's up to you to decide how to handle it. When the user does an alt+tab - that event is not application controlled - meaning that the application didn't choose to trigger the event. I'm not sure why you'd want to prevent someone from sizing your application as they see fit. Same goes with a resize message from windowed mode. Users also have an expectation when using alt+tab that the application will perform like any other standard application.

So there are several reasons to handle this message with alt+tab. Your users probably won't be doing this often. Recreating the back buffers isn't expensive and should be quite easy. Recreating the back buffers allows you to keep them the same resolution as the window/fullscreen which ensures that the system doesn't have to do a costly scaling blt in order to display your image. I believe that when you call IDXGISwapChain::ResizeBuffers() that it may only shrink the allocation if the difference is not significant. This is sort of an optimization for things like alt+tab where the change in size is only a few rows/columns different, and in the near future you'll return to using the full allocation again. You can apply this same approach to any non-swapchain render targets that your application uses. Same goes for DSV's. Just create new views into the ones you already have instead of recreating them when the resolution requested will still fit within the current resources. Handling this correctly will also mean that your application responds the way people expect otherwise you'll likely end up with bugs for scenario's you might not even be able to predict. It's generally bad practice to have the application forcibly predict what it is the user wants because some portion of the time you will be wrong.

[Edited by - DieterVW on October 26, 2010 10:53:14 AM]
I think you misunderstand the problem, the problem isn't the WM_SIZE or stopping alt+tab, the problem is that if alt+tab is pressed in a full screen d3d11 application, it automatically switches to a windowed application.
If someone is running a program in fullscreen and wishes it to be windowed, that is fine; but if they are just trying to switch program with alt+tab why should the application be switched to windowed and force them to reacquire full screen when they alt+tab back? That's what I'm trying to fix, so that you can alt+tab out of the full screen application and alt+tab back and it's still fullscreen.

[Edited by - NSG on October 28, 2010 1:48:49 AM]
That's odd since the fullscreen DX11 app I have returns to full screen when I alt+tab back in. I just went and tried severall DX10 and DX11 samples as well. You can use alt+enter to put them into fullscreen. Alt+tab returns them to windowed mode and restores the desktop. Further alt+tab returns them to fullscreen mode. I believe that is the default behavior you should get for free.

Could you post your WM_SIZE handler code, perhaps something will become apparent.
I'm not sure what samples you speak of, but if they are the ones included in the SDK, that's using DXUT which handles everything differently. I'm still having the same problems and like I said before, I disabled WM_SIZE and any unwarranted window changes from DXGI.
Alright I rewrote everything several times and no matter what approach or style, alt tabbing back into a full screen program will window it. Another problem is that when alt+tabbing out there is a memory leak on the graphics card. So is there someway to check if someone is alt tabbing out and in of my application?

This topic is closed to new replies.

Advertisement