如何有效地调整 DirectX 窗口大小?

发布于 2024-12-25 14:36:11 字数 479 浏览 2 评论 0原文

我查看了这个网站示例: http ://www.codesampler.com/dx9src/dx9src_6.htm

但代码相当奇怪:它释放了每个纹理、顶点缓冲区,一切!然后再次构建它们:从磁盘加载模型......我认为这不是很有效! OpenGL 可以动态调整窗口大小,而没有这样的限制。我怎样才能像 OpenGL 那样:高效地调整窗口大小,而不需要释放程序中的所有资源?

我尝试了上面链接示例中的代码,没有那些 invalidateDeviceObjects/restoreDeviceObjects 函数调用,但它不起作用..所以我想它必须完成?我希望不会,否则窗口大小调整对于大型应用程序来说会很痛苦,因为在纹理、模型等中分配了数百兆字节的数据。

I looked at this site example: http://www.codesampler.com/dx9src/dx9src_6.htm

But the code is rather weird: it frees every texture, vertex buffer, everything! and then builds them up again: loads the model from disk ... i dont think that is very efficient! OpenGL can do window resizing on fly with no such limitations. How can i do the same as OpenGL does: efficient window resize with no need to free every resource in my program?

I tried the code in the above link example, without those invalidateDeviceObjects/restoreDeviceObjects function calls, but it didnt work.. so i guess it must be done? I hope not, or window resizing would be a pain on larger apps where you have hundreds of megabytes of data allocated in textures, models etc.

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

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

发布评论

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

评论(3

断肠人 2025-01-01 14:36:11

这是 d3d9 设计方式的结果。调整 d3d9 窗口大小需要调用 IDirect3DDevice9::Reset,并且来自文档:

调用 IDirect3DDevice9::Reset 会导致所有纹理内存表面丢失、托管纹理从视频内存中刷新以及所有状态信息丢失。

所以事情就是这样。实际上,从游戏开始到游戏结束,您根本不会更改显示器的分辨率。通常您在游戏开始时设置分辨率,允许在某些特殊设置屏幕中重置。

现在我应该补充一点,如果您使用的是 D3D9,则可以使用一个特殊的资源分配标志(D3DPOOL_MANAGED),它实际上会为您重新加载资源。。因此,所有纹理、顶点缓冲区等的本地(系统内存)副本自动保存在系统内存中,并且当 GPU 重置时,这些纹理等会自动复制回 GPU。

请记住,如果您使用较新的 IDirect3DDevice9Ex,则不允许使用 D3DPOOL_MANAGED

This is a consequence of how d3d9 was designed. Resizing a d3d9 window requires a call to IDirect3DDevice9::Reset, and from the docs:

Calling IDirect3DDevice9::Reset causes all texture memory surfaces to be lost, managed textures to be flushed from video memory, and all state information to be lost.

So it is what it is. You don't actually customarily change the resolution of the display, at all, ever, from game start to game end. Usually you set the resolution on game start, allow resetting in some special settings screen.

Now I should add, if you are using D3D9, there is a special resource allocation flag you can use (D3DPOOL_MANAGED) that will actually take care of re-loading resources for you. So a local (system memory) copy of all textures, vertex buffers, etc is automatically maintained in system memory, and when the GPU is reset, those textures etc are automatically copied back down to the GPU.

Keep in mind D3DPOOL_MANAGED isn't allowed if you're using the newer IDirect3DDevice9Ex.

王权女流氓 2025-01-01 14:36:11

在非游戏业务应用程序中,频繁调整窗口大小是 UI 的重要组成部分,我通过以检测到的全屏分辨率创建 D3D 设备作为内存设备来解决此问题,然后在 CWnd::OnDraw 中使用 StretchBlt (...) 在内存位图从后台缓冲区写入屏幕时调整内存位图的大小。对于高帧速率动画来说,这不是一个好的解决方案,但在相对静态的视图情况下,用户的操作控制对象/视图运动,它比拆卸和重新创建方法效果更好。

In a non-game business application where frequent resizing windows was an important part of the UI, I worked around this issue by creating the D3D device as a memory device at the detected full-screen resolution, then used StretchBlt in the CWnd::OnDraw(...) to resize the memory bitmap as it was being written from the backbuffer to the screen. This isn't a good solution for high frame rate animation, but in a relatively static view situation where the user's actions control the object/view motion it works better than the tear-down and recreate approach.

七堇年 2025-01-01 14:36:11

创建后台缓冲区作为显示器的最大分辨率,并使用 SWAPEFFECT_COPY

绘制时,让代码绘制到当前窗口大小。

调用 Present 时,提供源矩形和目标矩形的窗口大小。

这样您就拥有了一个可调整大小的窗口,当窗口大小发生变化时,无需重新创建 D3D 设备。

Create the back buffer to be the monitor's max resolution, and use SWAPEFFECT_COPY.

When drawing, have your code draw to the current window size.

When calling Present, provide the window size for the source and destination rectangles.

Then you have a resizable window that doesn't need to recreate the D3D device when the window size changes.

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