dwmkerr / sharpgl

Use OpenGL in .NET applications. SharpGL wraps all modern OpenGL features and offers a powerful scene graph to aid development.
MIT License
755 stars 299 forks source link

DispatchTimer Priority for drawing in OpenGLControl #111

Open ThVoss opened 9 years ago

ThVoss commented 9 years ago

Hi,

Our users complained about a poor performance of our application when an OpenGLControl was open.

I tracked that down to the Dispatch timer priority which was 10 (DispatcherPriority.Send) which is the highest priority.

I lowered that priority to 7 (DispatcherPriority.Render). Doing this, reduces fps a little bit, but the rest of the application stays responsive.

Maybe that should be changed in the next Version?!

Cheers Thomas

ThVoss commented 9 years ago

Hi,

just as an addition to this issue:

If you add multiple controls to to your application, which are used at the same time, even the DispatcherPriority.Render might cause the application to freeze, especially when the time needed in the draw handler * the number of controls exeeds the break time (1000/Frames in ms).

I've reduced the priority to DispatcherPriority.ApplicationIdle which still works fine for me.

Cheers Thomas

davidedec commented 8 years ago

Hi ThVoss, can you tell me where I can find the priority setting?

Thanks Davide

ThVoss commented 8 years ago

Sure,

you can find that Setting in SharpGL.WPF.OpenGLControl.cs in the OnApplyTemplate method.

Just Change: timer = new DispatcherTimer(DispatcherPriority.Render); to: timer = new DispatcherTimer(DispatcherPriority.ApplicationIdle); or: timer = new DispatcherTimer(DispatcherPriority.SystemIdle);

Cheers

Thomas