|
|
发表于 2009-5-6 14:52:00
|
显示全部楼层
Re:DXUT和多线程的问题
loading的时候要降低渲染频率
比如每load n%才重新渲染一次loading画面
否则你的load过程会非常非常慢
while (!finishedLoading)
{
DrawFunkyLoadingAnimation();
GraphicsDevice.Present();
}
Here be dragons! The above code will work, but is liable to make your loading hundreds of times slower.
The reason is that every time you touch the graphics device from a different thread, the framework takes out a critical section, in order to avoid heisenbadness. If the animation is constantly redrawing, the animation thread will pretty much always own this lock, so any time your load function wants to create a graphics resource such as a texture, vertex buffer, or shader, it must wait until the animation thread releases it. This might take a while if the animation thread is just constantly looping over the same piece of draw code!
The solution is to slow down your animation thread by inserting a sleep call, which stops it hogging the graphics device. |
|