Sign in to follow this  

Getting multiple viewports to work

This topic is 4713 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

First of all I'm using C# and managed directx 9. I'm trying to get my renderer to work with multiple viewports and I think I've found a design that will work. The renderer holds a reference to the current viewport as well as a list of viewports. Each viewport has a SwapChain. When the current viewport is set/changed the renderer calls: device.SetRenderTarget(0, viewport.SwapChain.GetBackBuffer(0, BackBufferType.Mono)); At the beginning of the rendering pass all buffers are cleared and at the end each viewport in the list are presented by looping through each viewport and calling Present() on the SwapChains. This works fine except when I try to resize the parent window a NullReferenceException exception is thrown: System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.DirectX.Direct3D.SwapChain.GetBackBuffer(Int32 backBuffer, BackBufferType typeBuffer) at Adventure.D3D9Renderer3.set_Viewport(Viewport3 value) in d3d9renderer3.cs:line 75 at Adventure.Window.OnPaint(PaintEventArgs e) in window.cs:line 38 ... In my parent window's OnDraw() function I render the scene on two viewports (meaning I change the render's viewport twice each pass). Something happens while resizing that makes SwapChain.GetBackBuffer() fail. What is going on? How do I handle this? There is very little information on the web on handling multiple viewports and I'm new at Direct3d so forgive me if I'm asking stupid questions.

Share this post


Link to post
Share on other sites
Is there no one that can help me with this? I would greatly appreciate it. I'm glad if someone can ge me some pointers as the MSDN directx documentation and the book Managed directx 9 Kickstart gave me nothing.

Share this post


Link to post
Share on other sites
I've no experience with multiple viewports, but it looks like you're passing an invalid pointer.
Have you checked wether references to the backbuffer, viewports etc. aren't null?

Share this post


Link to post
Share on other sites
Actually I think I've solved it. When the parent window is resized apparently the viewports swap chain's need to be reset. I believe this is because the backbuffer of the parent is freed and another one is created that fits the new window size - the old swap chains still holds a reference to the old backbuffer. Thanks for the reply anyway.

Share this post


Link to post
Share on other sites
Viewports belong to a particular render target. You can have many viewports on one target. It seems like your question is more about multiple windows, unless what you really want is one window with several viewports in which case why the need for multiple back buffers/swap chains?

Share this post


Link to post
Share on other sites
Quote:
Original post by DBX
Viewports belong to a particular render target. You can have many viewports on one target. It seems like your question is more about multiple windows, unless what you really want is one window with several viewports in which case why the need for multiple back buffers/swap chains?


Yes it is about multiple windows. I should'nt have called it viewports, sorry for that.

Share this post


Link to post
Share on other sites
Quote:
Original post by Opwiz
Quote:
Original post by DBX
Viewports belong to a particular render target. You can have many viewports on one target. It seems like your question is more about multiple windows, unless what you really want is one window with several viewports in which case why the need for multiple back buffers/swap chains?


Yes it is about multiple windows. I should'nt have called it viewports, sorry for that.

Ah! [grin]

Share this post


Link to post
Share on other sites

This topic is 4713 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.

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