tags:

views:

43

answers:

2

Say I have a SlimDX based game editor. I have a DeviceContext instance which basically controls all states of the device, handles lost device, creates it, etc. The editor does not always have a view-port open where rendering is taking place. Instead it contains various editors, a scene editor, texture viewer/editor, animation editor, material editor, etc, etc.

Now say a user opens up the SceneEditor (a dialog with four views rendered into panels). When the editor is instanced, it grabs a reference from the DeviceContext and if found 'null' it calls on context.CreateDevice(Control ctrl). This method 'ensures' the device is not lost, null or disposed. If so, it takes care of it based on what is going on. Now the editor sends the 'CreateDevice' method the control(Panel) to use when creating/resetting the device, this control is the panel that represents the TopLeft view. Next it grabs a 'Device' reference from the context and then creates it's swap-chains views (being the other three view-port Panels).

Now let's say a user opens up the ModelViewer dialog. This too makes sure the device instance is not 'null' , if so calls on DeviceContext.CreateDevice(ModelViewPanel) and grabs the Device reference from it. If Device is not null, it creates a swap-chain for it's view (where the Model will be rendered).

Ok so we have a scene editor with four views (the TopLeft Panel being the control used to create the Device object) and three other Panel objects created as swap-chains. Next we have the ModelViewer that the user opened. This has a single panel created as a swap-chain.

My question is: Since the scene-editor has the control that initially created the device instance, what do I do if the user closes the scene editor? Do I call on Devi)ce.Reset() or create a 'new' Device()' using the presentation parameters of the ModelViewer?

Please ask to re-factor the question if something is not understood, thanks.

+2  A: 

My question is: Since the scene-editor has the control that initially created the device instance, what do I do if the user closes the scene editor? Do I call on Devi)ce.Reset() or create a 'new' Device()' using the presentation parameters of the ModelViewer?

Basically, if the user destroys the control that created the device, you'll need to make a new device, based off a new control (and window handle).

Since you're already using swap chains, a different, very good option, is to make an (invisible) 1 pixel control, and use this to create your device. Then use swap chains to create all of your individual surfaces.

The advantage here, of course, is that you can keep that HWND (the 1 pixel control's handle) alive for the lifetime of your application - no more worry about the user destroying your device.

Reed Copsey
I have thought about this. I just didn't want to 'Hack' my code structure. As all the rendering is abstract going through the game engines graphics framework, this isn't a viable option, but still a possibility.
qc.zackf-FissureStudios
Now as of 'recreating' the device. This sounds like the best option and the most clean. Another idea would be to create a little 50 x 50 canvas and render a logo or something into it. And just use this for my initial 'device' creator canvas. PS - Sorry about double posting here :/ ... it would not allow me to edit :?
qc.zackf-FissureStudios
A: 

The core problem you seem to be describing in your design is that you have two different classes responsible for the same thing - creating a device.

Instead of that, consider refactoring the classes to give that responsibility to a separate class, and give your forms a reference to that class on construction.

kyoryu
Your description is the exact description I gave in my question about the DeviceContext. The DeviceContext handles everything related to the Device. It's creation, resetting, destruction, etc. It also internally implements a working system for handling DirectX resources being used.
qc.zackf-FissureStudios
True, but I'm still seeing a lot of device-management code in your individual forms. I'd attempt to make it more active, rather than being what sounds like primarily a repository.
kyoryu