fix framerate rendering
This commit is contained in:
parent
deda49b098
commit
71e0793493
|
@ -79,6 +79,8 @@
|
|||
#include <Quarter/eventhandlers/EventFilter.h>
|
||||
#include <Quarter/eventhandlers/DragDropHandler.h>
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#include "InteractionMode.h"
|
||||
#include "QuarterWidgetP.h"
|
||||
#include "QuarterP.h"
|
||||
|
@ -671,6 +673,8 @@ void QuarterWidget::resizeEvent(QResizeEvent* event)
|
|||
*/
|
||||
void QuarterWidget::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
std::clock_t begin = std::clock();
|
||||
|
||||
if(!initialized) {
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
this->getSoRenderManager()->reinitialize();
|
||||
|
@ -731,6 +735,9 @@ 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)
|
||||
|
|
|
@ -188,13 +188,14 @@ protected:
|
|||
virtual void resizeEvent(QResizeEvent*);
|
||||
virtual bool viewportEvent(QEvent* event);
|
||||
virtual void actualRedraw(void);
|
||||
|
||||
double renderTime;
|
||||
|
||||
private:
|
||||
void constructor(const QGLFormat& format, const QGLWidget* sharewidget);
|
||||
friend class QuarterWidgetP;
|
||||
class QuarterWidgetP * pimpl;
|
||||
bool initialized;
|
||||
|
||||
bool initialized;
|
||||
};
|
||||
|
||||
}}} // namespace
|
||||
|
|
|
@ -31,6 +31,103 @@
|
|||
#include <Inventor/actions/SoGetBoundingBoxAction.h>
|
||||
#include <Inventor/SoPickedPoint.h>
|
||||
|
||||
static unsigned char fps2dfont[][12] = {
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, //
|
||||
{ 0, 0, 12, 12, 0, 8, 12, 12, 12, 12, 12, 0 }, // !
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 20, 20 }, // \"
|
||||
{ 0, 0, 18, 18, 18, 63, 18, 18, 63, 18, 18, 0 }, // #
|
||||
{ 0, 8, 28, 42, 10, 10, 12, 24, 40, 42, 28, 8 }, // $
|
||||
{ 0, 0, 6, 73, 41, 22, 8, 52, 74, 73, 48, 0 }, // %
|
||||
{ 0, 12, 18, 18, 12, 25, 37, 34, 34, 29, 0, 0 }, // &
|
||||
{ 12, 12, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // '
|
||||
{ 0, 6, 8, 8, 16, 16, 16, 16, 16, 8, 8, 6 }, // (
|
||||
{ 0, 48, 8, 8, 4, 4, 4, 4, 4, 8, 8, 48 }, //)
|
||||
{ 0, 0, 0, 0, 0, 0, 8, 42, 20, 42, 8, 0 }, // *
|
||||
{ 0, 0, 0, 8, 8, 8,127, 8, 8, 8, 0, 0 }, // +
|
||||
{ 0, 24, 12, 12, 0, 0, 0, 0, 0, 0, 0, 0 }, // ,
|
||||
{ 0, 0, 0, 0, 0, 0,127, 0, 0, 0, 0, 0 }, // -
|
||||
{ 0, 0, 24, 24, 0, 0, 0, 0, 0, 0, 0, 0 }, // .
|
||||
{ 0, 32, 32, 16, 16, 8, 8, 8, 4, 4, 2, 2 }, // /
|
||||
{ 0, 0, 28, 34, 34, 34, 34, 34, 34, 34, 28, 0 }, // 0
|
||||
{ 0, 0, 8, 8, 8, 8, 8, 8, 40, 24, 8, 0 }, // 1
|
||||
{ 0, 0, 62, 32, 16, 8, 4, 2, 2, 34, 28, 0 }, // 2
|
||||
{ 0, 0, 28, 34, 2, 2, 12, 2, 2, 34, 28, 0 }, // 3
|
||||
{ 0, 0, 4, 4, 4,126, 68, 36, 20, 12, 4, 0 }, // 4
|
||||
{ 0, 0, 28, 34, 2, 2, 2, 60, 32, 32, 62, 0 }, // 5
|
||||
{ 0, 0, 28, 34, 34, 34, 60, 32, 32, 34, 28, 0 }, // 6
|
||||
{ 0, 0, 16, 16, 16, 8, 8, 4, 2, 2, 62, 0 }, // 7
|
||||
{ 0, 0, 28, 34, 34, 34, 28, 34, 34, 34, 28, 0 }, // 8
|
||||
{ 0, 0, 28, 34, 2, 2, 30, 34, 34, 34, 28, 0 }, // 9
|
||||
{ 0, 0, 24, 24, 0, 0, 0, 24, 24, 0, 0, 0 }, // :
|
||||
{ 0, 48, 24, 24, 0, 0, 0, 24, 24, 0, 0, 0 }, // ;
|
||||
{ 0, 0, 0, 2, 4, 8, 16, 8, 4, 2, 0, 0 }, // <
|
||||
{ 0, 0, 0, 0, 0,127, 0,127, 0, 0, 0, 0 }, // =
|
||||
{ 0, 0, 0, 16, 8, 4, 2, 4, 8, 16, 0, 0 }, // >
|
||||
{ 0, 0, 16, 16, 0, 16, 28, 2, 2, 2, 60, 0 }, // ?
|
||||
{ 0, 0, 28, 32, 73, 86, 82, 82, 78, 34, 28, 0 }, // @
|
||||
{ 0, 0, 33, 33, 33, 63, 18, 18, 18, 12, 12, 0 }, // A
|
||||
{ 0, 0, 60, 34, 34, 34, 60, 34, 34, 34, 60, 0 }, // B
|
||||
{ 0, 0, 14, 16, 32, 32, 32, 32, 32, 18, 14, 0 }, // C
|
||||
{ 0, 0, 56, 36, 34, 34, 34, 34, 34, 36, 56, 0 }, // D
|
||||
{ 0, 0, 62, 32, 32, 32, 60, 32, 32, 32, 62, 0 }, // E
|
||||
{ 0, 0, 16, 16, 16, 16, 30, 16, 16, 16, 30, 0 }, // F
|
||||
{ 0, 0, 14, 18, 34, 34, 32, 32, 32, 18, 14, 0 }, // G
|
||||
{ 0, 0, 34, 34, 34, 34, 62, 34, 34, 34, 34, 0 }, // H
|
||||
{ 0, 0, 62, 8, 8, 8, 8, 8, 8, 8, 62, 0 }, // I
|
||||
{ 0, 0,112, 8, 8, 8, 8, 8, 8, 8, 62, 0 }, // J
|
||||
{ 0, 0, 33, 33, 34, 36, 56, 40, 36, 34, 33, 0 }, // K
|
||||
{ 0, 0, 30, 16, 16, 16, 16, 16, 16, 16, 16, 0 }, // L
|
||||
{ 0, 0, 33, 33, 33, 45, 45, 45, 51, 51, 33, 0 }, // M
|
||||
{ 0, 0, 34, 34, 38, 38, 42, 42, 50, 50, 34, 0 }, // N
|
||||
{ 0, 0, 12, 18, 33, 33, 33, 33, 33, 18, 12, 0 }, // O
|
||||
{ 0, 0, 32, 32, 32, 60, 34, 34, 34, 34, 60, 0 }, // P
|
||||
{ 3, 6, 12, 18, 33, 33, 33, 33, 33, 18, 12, 0 }, // Q
|
||||
{ 0, 0, 34, 34, 34, 36, 60, 34, 34, 34, 60, 0 }, // R
|
||||
{ 0, 0, 60, 2, 2, 6, 28, 48, 32, 32, 30, 0 }, // S
|
||||
{ 0, 0, 8, 8, 8, 8, 8, 8, 8, 8,127, 0 }, // T
|
||||
{ 0, 0, 28, 34, 34, 34, 34, 34, 34, 34, 34, 0 }, // U
|
||||
{ 0, 0, 12, 12, 18, 18, 18, 33, 33, 33, 33, 0 }, // V
|
||||
{ 0, 0, 34, 34, 34, 54, 85, 73, 73, 73, 65, 0 }, // W
|
||||
{ 0, 0, 34, 34, 20, 20, 8, 20, 20, 34, 34, 0 }, // X
|
||||
{ 0, 0, 8, 8, 8, 8, 20, 20, 34, 34, 34, 0 }, // Y
|
||||
{ 0, 0, 62, 32, 16, 16, 8, 4, 4, 2, 62, 0 }, // Z
|
||||
{ 0, 14, 8, 8, 8, 8, 8, 8, 8, 8, 8, 14 }, // [
|
||||
{ 0, 2, 2, 4, 4, 8, 8, 8, 16, 16, 32, 32 }, // [backslash]
|
||||
{ 0, 56, 8, 8, 8, 8, 8, 8, 8, 8, 8, 56 }, // ]
|
||||
{ 0, 0, 0, 0, 0, 34, 34, 20, 20, 8, 8, 0 }, // ^
|
||||
{ 0,127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // _
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 24, 12 }, // `
|
||||
{ 0, 0, 29, 34, 34, 30, 2, 34, 28, 0, 0, 0 }, // a
|
||||
{ 0, 0, 60, 34, 34, 34, 34, 50, 44, 32, 32, 32 }, // b
|
||||
{ 0, 0, 14, 16, 32, 32, 32, 16, 14, 0, 0, 0 }, // c
|
||||
{ 0, 0, 26, 38, 34, 34, 34, 34, 30, 2, 2, 2 }, // d
|
||||
{ 0, 0, 28, 34, 32, 62, 34, 34, 28, 0, 0, 0 }, // e
|
||||
{ 0, 0, 16, 16, 16, 16, 16, 16, 62, 16, 16, 14 }, // f
|
||||
{ 28, 2, 2, 26, 38, 34, 34, 34, 30, 0, 0, 0 }, // g
|
||||
{ 0, 0, 34, 34, 34, 34, 34, 50, 44, 32, 32, 32 }, // h
|
||||
{ 0, 0, 8, 8, 8, 8, 8, 8, 56, 0, 8, 8 }, // i
|
||||
{ 56, 4, 4, 4, 4, 4, 4, 4, 60, 0, 4, 4 }, // j
|
||||
{ 0, 0, 33, 34, 36, 56, 40, 36, 34, 32, 32, 32 }, // k
|
||||
{ 0, 0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 56 }, // l
|
||||
{ 0, 0, 73, 73, 73, 73, 73,109, 82, 0, 0, 0 }, // m
|
||||
{ 0, 0, 34, 34, 34, 34, 34, 50, 44, 0, 0, 0 }, // n
|
||||
{ 0, 0, 28, 34, 34, 34, 34, 34, 28, 0, 0, 0 }, // o
|
||||
{ 32, 32, 60, 34, 34, 34, 34, 50, 44, 0, 0, 0 }, // p
|
||||
{ 2, 2, 26, 38, 34, 34, 34, 34, 30, 0, 0, 0 }, // q
|
||||
{ 0, 0, 16, 16, 16, 16, 16, 24, 22, 0, 0, 0 }, // r
|
||||
{ 0, 0, 60, 2, 2, 28, 32, 32, 30, 0, 0, 0 }, // s
|
||||
{ 0, 0, 14, 16, 16, 16, 16, 16, 62, 16, 16, 0 }, // t
|
||||
{ 0, 0, 26, 38, 34, 34, 34, 34, 34, 0, 0, 0 }, // u
|
||||
{ 0, 0, 8, 8, 20, 20, 34, 34, 34, 0, 0, 0 }, // v
|
||||
{ 0, 0, 34, 34, 34, 85, 73, 73, 65, 0, 0, 0 }, // w
|
||||
{ 0, 0, 34, 34, 20, 8, 20, 34, 34, 0, 0, 0 }, // x
|
||||
{ 48, 16, 8, 8, 20, 20, 34, 34, 34, 0, 0, 0 }, // y
|
||||
{ 0, 0, 62, 32, 16, 8, 4, 2, 62, 0, 0, 0 }, // z
|
||||
{ 0, 6, 8, 8, 8, 4, 24, 4, 8, 8, 8, 6 }, // {
|
||||
{ 0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 }, // |
|
||||
{ 0, 48, 8, 8, 8, 16, 12, 16, 8, 8, 8, 48 }, // }
|
||||
{ 0, 0, 0, 0, 0, 0, 78, 57, 0, 0, 0, 0 } // ~
|
||||
};
|
||||
|
||||
SIM::Coin3D::Quarter::SoQTQuarterAdaptor::SoQTQuarterAdaptor(QWidget* parent, const QGLWidget* sharewidget, Qt::WindowFlags f)
|
||||
: QuarterWidget(parent, sharewidget, f), matrixaction(SbViewportRegion(100,100))
|
||||
|
@ -453,4 +550,59 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::resetToHomePosition(void)
|
|||
// otherwise, cameras have changed in ways we don't understand since
|
||||
// the last saveHomePosition() invokation, and so we're just going
|
||||
// to ignore the reset request
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SIM::Coin3D::Quarter::SoQTQuarterAdaptor::draw2DString(const char * str, SbVec2s glsize, SbVec2f position)
|
||||
{
|
||||
// Store GL state.
|
||||
glPushAttrib(GL_ENABLE_BIT|GL_CURRENT_BIT);
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glOrtho(0.0, glsize[0], 0.0, glsize[1], -1, 1);
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
|
||||
// glColor3f(0.0, 0.0, 0.0);
|
||||
// glRasterPos2f(position[0] + 1, position[1]);
|
||||
// printString(str);
|
||||
// glRasterPos2f(position[0] - 1, position[1]);
|
||||
// printString(str);
|
||||
// glRasterPos2f(position[0], position[1] + 1);
|
||||
// printString(str);
|
||||
// glRasterPos2f(position[0], position[1] - 1);
|
||||
// printString(str);
|
||||
|
||||
glColor3f(1.0, 1.0, 0.0);
|
||||
glRasterPos2f(position[0], position[1]);
|
||||
printString(str);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // restore default value
|
||||
|
||||
glPopAttrib();
|
||||
}
|
||||
|
||||
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::printString(const char * s)
|
||||
{
|
||||
int i,n;
|
||||
n = strlen(s);
|
||||
for (i = 0; i < n; i++)
|
||||
glBitmap(8, 12, 0.0, 2.0, 10.0, 0.0, fps2dfont[s[i] - 32]);
|
||||
}
|
|
@ -92,7 +92,7 @@ public:
|
|||
virtual bool processSoEvent(const SoEvent* event) {
|
||||
return QuarterWidget::processSoEvent(event);
|
||||
};
|
||||
|
||||
|
||||
//this functions still need to be ported
|
||||
virtual void afterRealizeHook(void) {}; //enables spacenav and joystick in soqt, dunno if this is needed
|
||||
|
||||
|
@ -120,6 +120,10 @@ private:
|
|||
SoGetMatrixAction matrixaction;
|
||||
// Home position storage.
|
||||
SoNode * m_storedcamera;
|
||||
|
||||
protected:
|
||||
void draw2DString(const char * str, SbVec2s glsize, SbVec2f position);
|
||||
void printString(const char * s);
|
||||
};
|
||||
|
||||
} //Quarter
|
||||
|
|
|
@ -59,6 +59,7 @@
|
|||
# include <Inventor/nodes/SoTransform.h>
|
||||
# include <Inventor/nodes/SoTranslation.h>
|
||||
# include <Inventor/nodes/SoSelection.h>
|
||||
# include <Inventor/nodes/SoText2.h>
|
||||
# include <Inventor/actions/SoBoxHighlightRenderAction.h>
|
||||
# include <Inventor/events/SoEvent.h>
|
||||
# include <Inventor/events/SoKeyboardEvent.h>
|
||||
|
@ -118,6 +119,7 @@
|
|||
#include "View3DViewerPy.h"
|
||||
|
||||
#include <Inventor/draggers/SoCenterballDragger.h>
|
||||
#include <Inventor/annex/Profiler/SoProfiler.h>
|
||||
|
||||
|
||||
//#define FC_LOGGING_CB
|
||||
|
@ -690,11 +692,7 @@ void View3DInventorViewer::setGradientBackgroundColor(const SbColor& fromColor,
|
|||
|
||||
void View3DInventorViewer::setEnabledFPSCounter(bool on)
|
||||
{
|
||||
#if defined (FC_OS_LINUX) || defined(FC_OS_CYGWIN) || defined(FC_OS_MACOSX) || defined(FC_OS_BSD)
|
||||
setenv("COIN_SHOW_FPS_COUNTER", (on?"1":"0"), 1);
|
||||
#else
|
||||
on ? _putenv("COIN_SHOW_FPS_COUNTER=1") : _putenv("COIN_SHOW_FPS_COUNTER=0");
|
||||
#endif
|
||||
fpsEnabled = on;
|
||||
}
|
||||
|
||||
void View3DInventorViewer::setAxisCross(bool on)
|
||||
|
@ -1376,6 +1374,13 @@ void View3DInventorViewer::renderScene(void)
|
|||
|
||||
for(std::list<GLGraphicsItem*>::iterator it = this->graphicsItems.begin(); it != this->graphicsItems.end(); ++it)
|
||||
(*it)->paintGL();
|
||||
|
||||
//fps rendering
|
||||
if(fpsEnabled) {
|
||||
std::stringstream stream;
|
||||
stream << renderTime << " ms / " << 1000./renderTime << " fps";
|
||||
draw2DString(stream.str().c_str(), SbVec2s(10,10), SbVec2f(0.1,0.1));
|
||||
};
|
||||
|
||||
#if 0 // this breaks highlighting of edges
|
||||
glEnable(GL_LIGHTING);
|
||||
|
|
|
@ -38,6 +38,9 @@
|
|||
|
||||
#include <Gui/Selection.h>
|
||||
|
||||
class SoTranslation;
|
||||
class SoTransform;
|
||||
class SoText2;
|
||||
namespace Quarter = SIM::Coin3D::Quarter;
|
||||
|
||||
class SoSeparator;
|
||||
|
@ -335,11 +338,12 @@ public:
|
|||
void setGradientBackgroundColor(const SbColor& fromColor,
|
||||
const SbColor& toColor,
|
||||
const SbColor& midColor);
|
||||
void setEnabledFPSCounter(bool b);
|
||||
void setNavigationType(Base::Type);
|
||||
|
||||
void setAxisCross(bool b);
|
||||
bool hasAxisCross(void);
|
||||
|
||||
void setEnabledFPSCounter(bool b);
|
||||
|
||||
NavigationStyle* navigationStyle() const;
|
||||
|
||||
|
@ -399,7 +403,10 @@ private:
|
|||
// big one in the middle
|
||||
SoShapeScale* axisCross;
|
||||
SoGroup* axisGroup;
|
||||
|
||||
|
||||
//stuff needed to draw the fps counter
|
||||
bool fpsEnabled;
|
||||
SoSeparator* fpsRoot;
|
||||
|
||||
SbBool editing;
|
||||
QCursor editCursor, zoomCursor, panCursor, spinCursor;
|
||||
|
|
Loading…
Reference in New Issue
Block a user