如何有效地调整DirectX窗口大小? [英] How to resize DirectX window efficiently?

查看:1661
本文介绍了如何有效地调整DirectX窗口大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



但是代码很奇怪:它释放了每个纹理,顶点缓冲区,一切!然后再构建它们:从磁盘加载模型...我不认为这是非常高效! OpenGL可以进行窗口大小调整,没有这样的限制。我如何做与OpenGL一样的:高效的窗口调整大小,而不需要释放我的程序中的每个资源?



我试过上面的链接示例中的代码,那些invalidateDeviceObjects / restoreDeviceObjects函数调用,但它没有工作..所以我想它一定要做?我希望不会,或窗口调整大小将是一个痛苦的大型应用程序,你有数百MB的数据分配在纹理,模型等。

解决方案

这是d3d9如何设计的结果。调整d3d9窗口大小需要调用 IDirect3DDevice9 :: Reset ,从文档:


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

所以它是什么。从游戏开始到游戏结束,你实际上并不习惯地改变显示器的分辨率。 通常你在游戏开始时设置分辨率,允许在一些特殊的设置屏幕中重置。



现在我应该添加,如果你使用D3D9,您可以使用( D3DPOOL_MANAGED )为您加载资源 。因此,所有纹理,顶点缓冲器等的本地(系统存储器)副本被自动地维持在系统存储器中,并且当GPU被重置时,那些纹理等被自动地复制回到GPU。 / p>

请记住如果您使用较新的 IDirect3DDevice9Ex / code>。


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.

解决方案

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.

这篇关于如何有效地调整DirectX窗口大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆