Jump to content
  • Advertisement
Sign in to follow this  
Opwiz

Getting multiple viewports to work

This topic is 5025 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!