Getting multiple viewports to work

Started by
5 comments, last by Wan 19 years, 3 months ago
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.

www.marklightforunity.com | MarkLight: Markup Extension Framework for Unity

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.

www.marklightforunity.com | MarkLight: Markup Extension Framework for Unity

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?
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.

www.marklightforunity.com | MarkLight: Markup Extension Framework for Unity

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?
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.

www.marklightforunity.com | MarkLight: Markup Extension Framework for Unity

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]

This topic is closed to new replies.

Advertisement