DirectX 9 and MFC

Started by
6 comments, last by Namethatnobodyelsetook 18 years, 10 months ago
Hey! I´m planning to write a very simple 3D viewer. The app. should be multi-document app. and I want to be able to have up to four 3D views/document. My question is, how should I organise my project? Should every 3DView (CView) have its own IDirect3DDevice and share a global IDirect3D Interface or should I put one IDirect3DDevice Interface in the Document to be shared with the 3DViews? /p
Advertisement
You should use only one device, but create a swapchain and add the other views there. This allows you to share the loaded textures and other resources. You would have to load all resources for every single device otherwise.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Ok, so one device/document, but how many swapchains can one device support? I read somewhere that a device can only support 2 swapchains?
/p
I'm sorry to interrupt, but Endurion: how can you use one device to display more then one render targets? Is could heavily use this!

Thanks for your answer,
kp
------------------------------------------------------------Neo, the Matrix should be 16-byte aligned for better performance!
You can call CreateAdditionalSwapChain with the new presentation parameters, and these can also contain a different HWND.

I never used that myself though, so i could be off.

Another option: In the Present call you can provide an alternative HWND as target.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

I've created editor using MFC and DX.

You create IDirect3DDevice9 for main frame (main window). I've used SDI so my view was split in 4 parts each using its own IDirect3DSwapChain9 interface.

Don't forget to handle resizing!

Basicly, you can do one of the following:

1. One device
Create one device for main window and for each renderable window, set its HWND* in device->Present(0, hWnd, 0, 0) IIRC.

2. One device, multiple swap chains
Create device for main frame and swap chain for each view class.

3. Multiple devices
Create independant device for each view class.
So... Muira Yoshimoto sliced off his head, walked 8 miles, and defeated a Mongolian horde... by beating them with his head?

Documentation? "We are writing games, we don't have to document anything".
Thanks for your arswers guys!
Just one more:
why would I want to create multiple swap chains (and allocate more video memory) if I can simply point another hwnd to Present?

kp
------------------------------------------------------------Neo, the Matrix should be 16-byte aligned for better performance!
Presenting to another window means scaling the backbuffer from whatever size it is, to the new window's size. Swap chains allow you to create a second (and third, etc.) front and backbuffer of the dimensions you actually want. Also, if you're using a SWAPEFFECT_COPY instead of DISCARD, you're expecting the backbuffer to remain untouched. This is useful for partially updating a GUI window. With it's own swap chain you won't destroy the backbuffer the other part of your app is expecting to keep.

Basically, they're different windows, with different sizes and settings, and a swapchain allows you to treat them as such.

This topic is closed to new replies.

Advertisement