如果我要破坏我最初创建设备的表面(形式)并且......,我该怎么办?

发布于 2024-08-21 10:18:37 字数 818 浏览 10 评论 0原文

假设我有一个基于 SlimDX 的游戏编辑器。我有一个 DeviceContext 实例,它基本上控制设备的所有状态,处理丢失的设备,创建设备等。编辑器并不总是在进行渲染的地方打开视口。相反,它包含各种编辑器、场景编辑器、纹理查看器/编辑器、动画编辑器、材质编辑器等。

现在假设用户打开场景编辑器(一个包含渲染到面板中的四个视图的对话框)。当编辑器被实例化时,它会从 DeviceContext 获取引用,如果发现“null”,它会调用 context.CreateDevice(Control ctrl)。此方法“确保”设备不会丢失、作废或处置。如果是这样,它会根据正在发生的情况进行处理。现在,编辑器向“CreateDevice”方法发送创建/重置设备时要使用的控件(面板),该控件是代表左上角视图的面板。接下来,它从上下文中获取“设备”引用,然后创建它的交换链视图(即其他三个视口面板)。

现在假设用户打开 ModelViewer 对话框。这也确保设备实例不为 'null' ,如果是这样,则调用 DeviceContext.CreateDevice(ModelViewPanel) 并从中获取设备引用。如果 Device 不为 null,它将为其视图(将在其中渲染模型)创建一个交换链。

好的,我们有一个带有四个视图的场景编辑器(左上角面板是用于创建设备对象的控件)和作为交换链创建的其他三个面板对象。接下来我们有用户打开的 ModelViewer。它有一个作为交换链创建的面板。

我的问题是: 由于场景编辑器拥有最初创建设备实例的控件,如果用户关闭场景编辑器我该怎么办?我是否调用 Devi)ce.Reset() 或使用 ModelViewer 的演示参数创建“新”Device()?

如果有不明白的地方,请要求重新考虑问题,谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生生漫 2024-08-28 10:18:37

我的问题是:由于场景编辑器拥有最初创建设备实例的控件,如果用户关闭场景编辑器我该怎么办?我是否调用 Devi)ce.Reset() 或使用 ModelViewer 的演示参数创建“新”Device()'?

基本上,如果用户销毁了创建设备的控件,您将需要基于新控件(和窗口句柄)创建一个设备。

由于您已经在使用交换链,因此一个不同的、非常好的选择是制作一个(不可见的)1 像素控件,并使用它来创建您的设备。然后使用交换链创建所有单独的曲面。

当然,这里的优点是您可以在应用程序的整个生命周期内保持 HWND(1 像素控件的句柄)处于活动状态 - 不再担心用户破坏您的设备。

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.

停滞 2024-08-28 10:18:37

您在设计中描述的核心问题似乎是您有两个不同的类负责同一件事 - 创建设备。

相反,请考虑重构这些类,将该责任赋予一个单独的类,并在构造时为您的表单提供对该类的引用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文