Sign in to follow this  
MrSparkle27

[SlimDX] Windowless DX10 device

Recommended Posts

Hi! I try to set up a windowless render device with DirectX 10. In D3D9, I used a SwapChain, initialized with a hidden form, and then presented the SwapChain using the Present(Control)-Method if needed (in most cases, the result is saved to a file without presenting it to the screen). In DirectX10, there is no Present(Control)-Method, so I always have to create the SwapChain with the ControlHandle it will be presented to. In my application there is no Control available when the SwapChain is created because, it used DirectX to render in background and save the image to a file. Only in some cases (for debug purposes) the image will be shown on a window. Is there a workaround so I can still use windowless SwapChains with DX10? Thanks, Christian

Share this post


Link to post
Share on other sites
Not as far as I know -- you need to give the swap chain description a HWND, or the associated DXGI device needs to have a window association to an HWND. I haven't looked into it in great detail but it doesn't appear to be obvious how you'd create a 'windowless' swap chain... best option may be for you to create a dummy control that you never show.

Share this post


Link to post
Share on other sites
The dummy control was a good solution with DX9 because I still could present the SwapChain to a Control if needed. That's not possible anymore if I understand this right. So I need to dispose and create a new SwapChain if I want to see output on screen, I guess.

Share this post


Link to post
Share on other sites
I don't know how to do it using SlimDX, bet there is way how to use DX10 without window.
Take a look at DirectX SDK sample C++\Direct3D10\GPUSpectrogram. It uses Direct3D10 device and does some GPGPU without any window creation.

Share this post


Link to post
Share on other sites
Quote:
Original post by MrSparkle27
The dummy control was a good solution with DX9 because I still could present the SwapChain to a Control if needed. That's not possible anymore if I understand this right. So I need to dispose and create a new SwapChain if I want to see output on screen, I guess.


Why is it not possible? You just need a valid window handle to pass to the creation methods, you don't ever need to show that control.

bubu LV's example seems like it might be a better solution anyway, provided SlimDX exposes whatever calls are necessary to perform the operation. If anything seems missing let me know and I'll try to add it this evening.

Share this post


Link to post
Share on other sites
Well, this looks interesting, thank you for pointing this out. It seems that this sample doesn't work with a SwapChain, it just renders to a DX10 RenderTarget using the ID3D10RenderTargetView interface.
Unfortunately, the only example provided by the SlimDX SDK is the MiniTri project that just outputs a triangle. I need to go deeper into the DX10 and SlimDX features, first...

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
Why is it not possible? You just need a valid window handle to pass to the creation methods, you don't ever need to show that control.


...but I have to create a new SwapChain and pass the Control's handle.

Quote:
Original post by jpetrie
bubu LV's example seems like it might be a better solution anyway, provided SlimDX exposes whatever calls are necessary to perform the operation. If anything seems missing let me know and I'll try to add it this evening.


The interesting part of the RenderToTexture method is:

// Set the render target and a NULL depth/stencil surface
if( pRTV )
{
ID3D10RenderTargetView* aRTViews[] = { pRTV };
pd3dDevice->OMSetRenderTargets( 1, aRTViews, NULL );
}

D3D10_TECHNIQUE_DESC techDesc;
pTechnique->GetDesc( &techDesc );
for( UINT p = 0; p < techDesc.Passes; ++p )
{
g_ptxSource->SetResource( pSRV );
pTechnique->GetPassByIndex( p )->Apply( 0 );
pd3dDevice->DrawIndexed( 6, 0, 0 );
}


Seems like the SlimDX.Direct3D10.Device does not expose a SetRenderTarget or OMSetRenderTargets-Method, maybe this feature is implemented elsewhere. The best solution, of course, would be a RenderToTexture class, similar to the Managed DirectX9 framework, but any other solution would be appreciated as well ;)




Share this post


Link to post
Share on other sites
Can you give me a short explanation of the steps I have to do to set up a RenderTargetView in order to render to a texture? That would be really helpful because it seems to be totally different from Managed DirectX. From what I read in the documentation, SlimDX seems to have all classes I need to render to a texture. But I just can figure out how to do it, so any help would be appreciated.
Thanks, Christian

Share this post


Link to post
Share on other sites
Quote:

...but I have to create a new SwapChain and pass the Control's handle.

I'm not following why this is bad, you said you had to do this in 9 as well.

Anyway.

You need a texture to create the render target view; it takes a resource and a description object, which you'll have to fill out according to your needs. The MiniTri10 sample creates a render target view since one is required for the back buffer.

The OMSetRenderTargets method is exposed as SetTargets (or something similar) on the D3D10 device. Everything else should be as normal (you just need an effect, and some geometry to render).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this