Skip to content

Commit

Permalink
Zinc widget: added a way to retrieve the FPS.
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Aug 20, 2020
1 parent 6e65d4d commit d10bc71
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/plugins/widget/ZincWidget/src/zincwidget.cpp
Expand Up @@ -286,6 +286,15 @@ void ZincWidget::viewAll()

//==============================================================================

double ZincWidget::fps() const
{
// Return our FPS

return mFps;
}

//==============================================================================

void ZincWidget::createSceneViewer()
{
// Create our scene viewer and have it have the same OpenGL properties as
Expand Down Expand Up @@ -359,6 +368,10 @@ void ZincWidget::updateSceneViewerViewerportSize(int pWidth, int pHeight,

void ZincWidget::initializeGL()
{
// Start our FPS clock

mFpsClock.start();

// Forward the fact that our context is going to be destroyed

connect(QOpenGLWidget::context(), &QOpenGLContext::aboutToBeDestroyed,
Expand All @@ -378,6 +391,19 @@ void ZincWidget::paintGL()
updateSceneViewerViewerportSize(width(), height(), true);

mSceneViewer.renderScene();

// Update our FPS, if needed

++mNbOfFrames;

int fpsClockElapsed = mFpsClock.elapsed();

if (fpsClockElapsed >= 1000) {
mFps = 1000.0*mNbOfFrames/fpsClockElapsed;

mNbOfFrames = 0;
mFpsClock.start();
}
}

//==============================================================================
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/widget/ZincWidget/src/zincwidget.h
Expand Up @@ -31,6 +31,7 @@ along with this program. If not, see <https://gnu.org/licenses>.
//==============================================================================

#include <QOpenGLWidget>
#include <QTime>

//==============================================================================

Expand Down Expand Up @@ -118,6 +119,8 @@ class ZINCWIDGET_EXPORT ZincWidget : public QOpenGLWidget,

void viewAll();

double fps() const;

protected:
void initializeGL() override;
void paintGL() override;
Expand All @@ -142,6 +145,10 @@ class ZINCWIDGET_EXPORT ZincWidget : public QOpenGLWidget,
bool mNeedContextMenu = false;
QMenu *mContextMenu = nullptr;

QTime mFpsClock;
int mNbOfFrames = 0;
double mFps = 0.0;

void createSceneViewer();

void updateSceneViewerViewerportSize(int pWidth, int pHeight,
Expand Down

0 comments on commit d10bc71

Please sign in to comment.