make the fps counter more stable

This commit is contained in:
wmayer
2017-10-13 00:13:19 +02:00
parent 8e694c3820
commit e9bed58f4b
5 changed files with 52 additions and 11 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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<int>(this->framecount, framearray_size);
this->frames[arrayptr] = static_cast<float>(renderTime);
this->starttime = timeofday;
return SbVec2f(1000 * drawfps, 1.0f / drawfps);
}

View File

@@ -30,6 +30,7 @@
#include <Inventor/sensors/SoTimerSensor.h>
#include <Inventor/actions/SoGetMatrixAction.h>
#include <Inventor/actions/SoSearchAction.h>
#include <vector>
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<float> 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

View File

@@ -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));
}