🔒 Locked
[DX11] Rendering to multiple windows
Advertisement
Original Post
I'll give you the keyword: "Swapchains".
When you create one, it gets attached to a window and gives you a rendertarget for that window, which you can simply set and render to as you would do usually.
When you create one, it gets attached to a window and gives you a rendertarget for that window, which you can simply set and render to as you would do usually.
Mind in a box has it right - you need to set up multiple swap chains (one for each window) to be able to render to more than one window. You can take a look at the "ViewFromTheWindow" sample of my engine (linked in my signature) that shows how to do this. Even though it is done in a different framework than yours, it should still show you the general steps.
You can take a look at the "ViewFromTheWindow" sample of my engine (linked in my signature) that shows how to do this. Even though it is done in a different framework than yours, it should still show you the general steps.
I have been looking up swap chains, and from what I see, I create one and then the only other time it is used would be when I present?
I took a look at your ViewFromTheWindow sample and that is how it seems there too. Though I have a few questions ...
1) Why do you do a CopySubresourceRegion of the RenderTarget before you render?
2) The window handle is no longer needed to be passed into render11->Present, is it?
3) Is there a particular reason why you get the desc of the swap chain before you present it?
4) What is the SwapChainBuffer texture used for?
I ask this because I am trying to figure out why when I go to present I am not getting anything at all to render (not even the back buffer it seems). This is my second swap chain, my main one I created with my device is working just fine.
The basic workflow for using swap chains is like this:
- Create a swap chain for each window, using the window handle to bind the swap chain to that particular window. Usually you also make the swap chain's backbuffer have the same size as the window's client area. You don't need the window handle anymore after this step.
- From each swap chain, get a pointer to the back buffer texture and create a render target view for it
- When you want to render to a particular window, bind the render target view corresponding to the back buffer for the window's swap chain to the device context and perform your rendering (you can also use CopyResource, or any other means of writing data to the render target)
- Call Present on the swap chain to display the back buffer contents on the window
MJP has it exactly right - you more or less create a swap chain, get a reference to its texture resource, render into it, and then present with the swap chain. The reason the sample seems like it follows a little differently is that I am rendering to an offscreen buffer that is the desktop resolution, then simply copying the appropriate sub-rectangle of that buffer to each swap chain based on the position and size of each window's client area.
Sorry, I should have said that up front - but the code for doing each of the steps that Matt specified above can be ripped from the Hieroglyph sample fairly easily.
Sorry, I should have said that up front - but the code for doing each of the steps that Matt specified above can be ripped from the Hieroglyph sample fairly easily.
I am still having difficulty with this, I am going to post my steps in order
1) A) Create the Swap chain
1) B) buffer texture from the swap chain
1) C) the ID3D11RenderTargetView from the buffer texture
1) D) the depth stencil texture
1) E) the depth stencil view from the depth stencil texture.
2) Before anything is rendered, set the rendertarget to the device (OMSetRenderTargets) along with the depth stencil view from above
3) Present the swap chain from above
Am I missing anything? I looked over your example and I did not see anything I was missing
What is happening is for some reason it is rendering to the original HWND, and not the swap chains it seems. I disabled all rendering for the original window, and it is still going to the original window.
1) A) Create the Swap chain
1) B) buffer texture from the swap chain
1) C) the ID3D11RenderTargetView from the buffer texture
1) D) the depth stencil texture
1) E) the depth stencil view from the depth stencil texture.
2) Before anything is rendered, set the rendertarget to the device (OMSetRenderTargets) along with the depth stencil view from above
3) Present the swap chain from above
Am I missing anything? I looked over your example and I did not see anything I was missing
What is happening is for some reason it is rendering to the original HWND, and not the swap chains it seems. I disabled all rendering for the original window, and it is still going to the original window.
Are you sure that you used the HWND from the second window when creating the second swap chain?
That is my thought, but I am without a doubt sure. I also checked to make sure there was nothing wrong with the window handle by at one time testing the second windows hwnd as the hwnd used for creating the device, and it rendered on the second window.
Have you double checked that the Texture2D / RTV that you are using is the right one? You should have one combination for each swap chain, and that is what determines where your rendering ends up. Presenting on the swap chain just flips what is in the swap chain's back buffer to the window contents.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement