Jump to content
  • Advertisement
Sign in to follow this  
GTD_NOR_CAL

DirectX 9.0c Swapchains and DXUT

This topic is 3790 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

While my MFC-based game editor successfully renders to multiple windows using additional swapchains, I would like to remove an existing limitation in my code whereby the sizes of the rendering windows are apparently limited to the size of the window initially created by DXUT for the primary swapchain. (I hide DXUT's window as I don't currently support fullscreen rendering in my editor.) For example, if I launch my editor on an 800x600 desktop, and force DXUT to create a desktop-sized window for the primary swapchain, I can resize my rendering windows at will, and all is good. However, if I then resize the desktop to 1600x1200, without closing down my editor, rendering will fail on any of my windows if they are re-sized to be greater than the original 800x600 size of the primary swapchain. There appears to be an implicit relationship between the allowable sizes of the explicit additional swapchains and the original implicit swapchain created by DXUT. Any thoughts on this subject would be appreciated! In my implementation I release the additional swapchains during the OnD3D9LostDevice callback from DXUT, and I create/release the additional swapchains whenever I discover just before rendering that the size of the rendering window has changed. I implement the Present() off the swapchain as a callback from DXUT that replaces their Present() off the primary swapchain (i.e.., ipSwapChain->Present( NULL, NULL, NULL, NULL, 0 ) ). Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
You need to create a depth buffer large enough for the largest swap chain, or just one per swapchain of the appropriate size.

A bug in the nVidia drivers or DirectX (not sure which) also sometimes makes depth surfaces fail to work correctly, when the debug Direct3D runtimes are chosen in the DirectX control panel.

Share this post


Link to post
Share on other sites
I do indeed use nVidia drivers, but I am currently running with the Retail version of the Direct3D 9 DLLs. If I understand you correctly, you're suggesting that I explicitly create a depth buffer matching the size of the client area in my rendering window (to avoid stretching), and do this for each of my additional swapchains. Does the same apply to the color buffer and stencil buffer?

I have been relying on DXUT to manage the D3D device, and to detect lost devices, etc. Can you give me a specific example of how you would go about creating a swapchain with a separately created depth buffer? If I did this would I also need to explicitly release the depth buffer?

Thanks!

P.S.

My code swapchain creation looks like this:

D3DPRESENT_PARAMETERS presentParams;
presentParams = DXUTGetD3D9PresentParameters();
presentParams.BackBufferWidth = 0;
presentParams.BackBufferHeight = 0;
presentParams.hDeviceWindow = hRenderWnd;

IDirect3DSwapChain9* ipSwapChain;
DXUTGetD3D9Device()->CreateAdditionalSwapChain( &presentParams, &ipSwapChain );

My code for rendering looks like this:

LPDIRECT3DSURFACE9 ipBackBuffer = NULL;
ipSwapChain->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &ipBackBuffer );
pd3dDevice->SetRenderTarget( 0, ipBackBuffer );
ipBackBuffer->Release();

... render scene ...

ipSwapChain->Present( NULL, NULL, NULL, NULL, 0 );

Finally, my code for lost devices includes this:

SAFE_RELEASE( ipSwapChain );


Share this post


Link to post
Share on other sites
On startup and reset, use GetDepthStencilSurface to grab the depth buffer you get with the device. If you don't grab it, you won't have a pointer to use to switch it back.

When you create your swap chain, you'll notice you can query the swap chain for it's render surface, but not it's depth surface. Swapchains don't make depth buffers for you. The autodepthstencil values are ignored for swapchains. Right after you make your swapchain, use CreateDepthStencilSurface to create a depth buffer with matching size and AA settings.

When you select a render target, right after you SetRenderTarget, also call SetDepthStencilSurface with the depth buffer for that surface (One you made for a swapchain, or the one that came with the device (that I had you query in step 1) for the backbuffer). Some drivers also work best if you SetViewport as well, after setting up both surfaces.

Share this post


Link to post
Share on other sites
Problem solved! Thanks a bunch!

Now that you've pointed me in the right direction I see in the ShadowMap sample from the June 2008 DirectX SDK that this very issue is commented on with regard to CreateDepthStencilSurface()/SetDepthStencilSurface().

Thanks again!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!