diff --git a/src/Gui/Quarter/QuarterWidget.cpp b/src/Gui/Quarter/QuarterWidget.cpp index 32008aabe5..14edc6d2ea 100644 --- a/src/Gui/Quarter/QuarterWidget.cpp +++ b/src/Gui/Quarter/QuarterWidget.cpp @@ -297,7 +297,7 @@ QuarterWidget::constructor(const QtGLFormat & format, const QtGLWidget * sharewi this->installEventFilter(PRIVATE(this)->eventfilter); this->installEventFilter(PRIVATE(this)->interactionmode); - + initialized = false; } @@ -844,8 +844,6 @@ void QuarterWidget::paintEvent(QPaintEvent* event) PRIVATE(this)->soeventmanager->setViewportRegion(vp); } - std::clock_t begin = std::clock(); - if(!initialized) { #if !defined(HAVE_QT5_OPENGL) glEnable(GL_DEPTH_TEST); @@ -917,9 +915,6 @@ void QuarterWidget::paintEvent(QPaintEvent* event) // process the delay queue the next time we enter this function, // unless we get here after a call to redraw(). PRIVATE(this)->processdelayqueue = true; - - std::clock_t end = std::clock(); - renderTime = double(double(end-begin)/CLOCKS_PER_SEC)*1000.0; } bool QuarterWidget::viewportEvent(QEvent* event) diff --git a/src/Gui/Quarter/QuarterWidget.h b/src/Gui/Quarter/QuarterWidget.h index 4c5fec37ec..260fb68112 100644 --- a/src/Gui/Quarter/QuarterWidget.h +++ b/src/Gui/Quarter/QuarterWidget.h @@ -199,13 +199,11 @@ protected: virtual void actualRedraw(void); virtual bool updateDevicePixelRatio(void); - double renderTime; - private: void constructor(const QtGLFormat& format, const QtGLWidget* sharewidget); friend class QuarterWidgetP; class QuarterWidgetP * pimpl; - bool initialized; + bool initialized; }; }}} // namespace diff --git a/src/Gui/Quarter/SoQTQuarterAdaptor.cpp b/src/Gui/Quarter/SoQTQuarterAdaptor.cpp index 5ef109615f..e3ac5d05c9 100644 --- a/src/Gui/Quarter/SoQTQuarterAdaptor.cpp +++ b/src/Gui/Quarter/SoQTQuarterAdaptor.cpp @@ -168,6 +168,8 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::init() m_seeksensor = new SoTimerSensor(SoQTQuarterAdaptor::seeksensorCB, (void*)this); getSoEventManager()->setNavigationState(SoEventManager::NO_NAVIGATION); + + resetFrameCounter(); } @@ -701,3 +703,38 @@ bool SIM::Coin3D::Quarter::SoQTQuarterAdaptor::processSoEvent(const SoEvent* eve return SIM::Coin3D::Quarter::QuarterWidget::processSoEvent(event); } + +/*! + Overridden from QuarterWidget to render the scenegraph +*/ +void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::paintEvent(QPaintEvent* event) +{ + QuarterWidget::paintEvent(event); + + this->framesPerSecond = addFrametime(SbTime::getTimeOfDay().getValue()); +} + +void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::resetFrameCounter(void) +{ + this->framecount = 0; + this->frames.assign(100, 0.0f); + this->totaldraw = 0.0f; + this->starttime = SbTime::getTimeOfDay().getValue(); + this->framesPerSecond = SbVec2f(0, 0); +} + +SbVec2f SIM::Coin3D::Quarter::SoQTQuarterAdaptor::addFrametime(double timeofday) +{ + int framearray_size = 100; + this->framecount++; + + int arrayptr = (this->framecount - 1) % framearray_size; + + double renderTime = timeofday - this->starttime; + this->totaldraw += (float(renderTime) - this->frames[arrayptr]); + float drawfps = this->totaldraw / std::min(this->framecount, framearray_size); + + this->frames[arrayptr] = static_cast(renderTime); + this->starttime = timeofday; + return SbVec2f(1000 * drawfps, 1.0f / drawfps); +} diff --git a/src/Gui/Quarter/SoQTQuarterAdaptor.h b/src/Gui/Quarter/SoQTQuarterAdaptor.h index f0c51c2b92..55014bd01e 100644 --- a/src/Gui/Quarter/SoQTQuarterAdaptor.h +++ b/src/Gui/Quarter/SoQTQuarterAdaptor.h @@ -30,6 +30,7 @@ #include #include #include +#include class SbViewportRegion; class SoCamera; @@ -96,7 +97,8 @@ public: } virtual bool processSoEvent(const SoEvent* event); - + virtual void paintEvent(QPaintEvent*); + //this functions still need to be ported virtual void afterRealizeHook(void) {} //enables spacenav and joystick in soqt, dunno if this is needed @@ -107,12 +109,20 @@ private: void getCameraCoordinateSystem(SoCamera * camera, SoNode * root, SbMatrix & matrix, SbMatrix & inverse); static void seeksensorCB(void * data, SoSensor * s); void moveCameraScreen(const SbVec2f & screenpos); + void resetFrameCounter(void); + SbVec2f addFrametime(double ft); bool m_viewingflag; int m_interactionnesting; SoCallbackList m_interactionStartCallback; SoCallbackList m_interactionEndCallback; + // Keep track of the frames-per-second counter. + std::vector frames; + float totaldraw; + double starttime; + int framecount; + // Seek functionality SoTimerSensor* m_seeksensor; float m_seekperiod; @@ -130,6 +140,7 @@ private: protected: void draw2DString(const char * str, SbVec2s glsize, SbVec2f position); void printString(const char * s); + SbVec2f framesPerSecond; }; } //Quarter diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index 098ac7a321..31d5101f3a 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -1642,7 +1642,7 @@ void View3DInventorViewer::renderScene(void) std::stringstream stream; stream.precision(1); stream.setf(std::ios::fixed | std::ios::showpoint); - stream << renderTime << " ms / " << 1000./renderTime << " fps"; + stream << framesPerSecond[0] << " ms / " << framesPerSecond[1] << " fps"; draw2DString(stream.str().c_str(), SbVec2s(10,10), SbVec2f(0.1f,0.1f)); }