worker thread slowed by MFC UI interactions  
Author Message
solehome





PostPosted: Visual C++ General, worker thread slowed by MFC UI interactions Top

I create a SDI MFC program in which there is a worker thread to render a 3D scene. I found the rendering speed will be interupted and slowed by some UI interactions, e.g., moving the window by drag the window title, mouse move on some toolbar's buttons. However the program implemented by C win32 API has little performence decrease under the same condition.

 Could you give some suggestion

Thanks.



Visual C++5  
 
 
Alex Farber





PostPosted: Visual C++ General, worker thread slowed by MFC UI interactions Top

What do you expect, there is only one processor which does these operations. If main thread makes more operations, background thread gets less CPU time. You can increase background thread priority, but in this case UI becomes less responsive.
 
 
einaros





PostPosted: Visual C++ General, worker thread slowed by MFC UI interactions Top

If you render within the window you are draging or otherwise interact with, the slowdown is likely to be caused by the added traffic to the message pump.

How are you invalidating / painting / rendering the window content in the first place



 
 
solehome





PostPosted: Visual C++ General, worker thread slowed by MFC UI interactions Top

I haven't manually invalidated the view or coustomized its ondraw function. I just create a 3D engine renderer(Ogre 3D engine) in the worker thread and give the HWND of the view to it. Then call the 3D engine's method "renderOneFrame" in the loop of the worker thread. I guess the engine do the video buffer swapping job in the "renderOneFrame" method.

I tried capturing and handling WM_ENTERSIZEMOVE and WM_MOVING messages in the program. But failed to improve the perfomence.


 
 
einaros





PostPosted: Visual C++ General, worker thread slowed by MFC UI interactions Top

You cannot avoid having *some* delays when you resize or more the window. It hogs the message queue, and can cause a lot of repaints, so the renderer will not have sole access anymore.

My two cent: you will have to live with the delay. The performance is fine as long as you avoid resizing or moving the window, isnt it



 
 
solehome





PostPosted: Visual C++ General, worker thread slowed by MFC UI interactions Top

You cannot avoid having *some* delays when you resize or more the window. It hogs the message queue, and can cause a lot of repaints, so the renderer will not have sole access anymore.

My two cent: you will have to live with the delay. The performance is fine as long as you avoid resizing or moving the window, isnt it

I see. Thank you.

maybe run the program in fullscreen mode and use some open source GUI can help. But it will make the program a little bit greedy and limit the user's freedom.