dwmkerr / dwmkerr/sharpgl

Correct FPS

Open
#15 1 comment 0 reactions 1 assignee Claimed by @dwmkerr View on GitHub
Dominant language
C#
Stars
804
Forks
294
Avg merge
3d 23h
Merged PRs (30d)
1

Description

Original issues:
https://sharpgl.codeplex.com/workitem/1083
https://sharpgl.codeplex.com/workitem/903

Details:
First of all, really great work!
I saw this

```
private void SetupDrawingTimer()
{
// First, if the framerate is less than zero, set it to zero.
if (frameRate < 0)
frameRate = 0;

// Now, if the framerate is zero, we're going to disable the timer.
if (frameRate == 0 && timerDrawing.Enabled)
{
// Disable the timer - at this stage we're done.
timerDrawing.Enabled = false;
return;
}

// Now set the interval.
timerDrawing.Interval = (int)(1000.0 / FrameRate);

// Finally, if the timer is not enabled, enable it now.
if(timerDrawing.Enabled == false)
timerDrawing.Enabled = true;
}
```

So, the timerDrawing.Interval will not work properly when frameRate is 0 and timerDrawing.Enabled is false.
I think maybe we can write it like this:

```
//...
// Now, if the framerate is zero, we're going to disable the timer.
if (frameRate == 0)
{
// Disable the timer - at this stage we're done.
if (timerDrawing.Enabled)
timerDrawing.Enabled = false;
return;
}
//...
```

Hope this help.

Next issue:

The FPS measurement routine is a bit off. It measures the frame drawing time. The true FPS(which depends on the total code) is different. One must measure the total time, including non-rendering code as that effects the frame rate. e.g., it doesn't matter if you can draw a frame in 0s if your non-rendering code takes 10 seconds(==> 1/10 fps).

I've attached a modified OpenGLControl that not only adds these proper FPS measurements(both single frame executing/drawing time + true FPS) + it minimizes the effect by not doing the calculation every frame.

The DTPF is the time it takes to draw a frame(user drawing code + gl rendering code), the AFPS is the average frames per second(the fps as seen by the user), DFPS is the desired frames per second as set by the timer = FrameRate, NDT is the "non-drawing time" which is the time left over for other code outside the gl loop.

(the code could be cleaned up a bit as I just downloaded the code)

Source code at: https://sharpgl.codeplex.com/workitem/903

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.