From: BenoƮt Jacob Date: Mon, 26 Jun 2006 10:18:33 +0000 (+0000) Subject: Changes in kalziumglwidget: X-Git-Tag: v3.80.3~103^2~42 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=75022ae5531ecd22b01fe27fbf8cdb31f34841e4;p=libqmvoc.git Changes in kalziumglwidget: - added FPS (frames per second) counter. Enable it by #defining USE_FPS_COUNTER. (Currently enabled). - added option to cache the rendering of the molecule using a GL display list. This improves speed, especially for rendering complex molecules; I have measured a speed increase above +35% in some cases (depends also on the style and the widget size). Enable it by #defining USE_DISPLAY_LIST. (Currently enabled). Change in latticedialog: - I allowed myself to comment out ui.glWidget->update(); in LatticeDialog::slotUpdateView() because normally this is being taken care of by slotSetMolecule; also I think that for a GL widget, one should call updateGL() instead of update(); not 100% sure here. Carsten, I didn't see the "blank widget" bug in the lattice viewer; have you already solved it? M kalzium/src/kalziumglwidget.h M kalzium/src/kalziumglwidget.cpp M kalzium/src/latticedialog.cpp svn path=/trunk/KDE/kdeedu/kalzium/src/kalziumglwidget.h; revision=555113 --- diff --git a/kalzium/kalziumglwidget.cpp b/kalzium/kalziumglwidget.cpp index 7dfb285..15543d5 100644 --- a/kalzium/kalziumglwidget.cpp +++ b/kalzium/kalziumglwidget.cpp @@ -20,6 +20,10 @@ #include #include +#ifdef USE_FPS_COUNTER +#include +#endif + #include #include @@ -28,6 +32,7 @@ using namespace OpenBabel; KalziumGLWidget::KalziumGLWidget( QWidget * parent ) : QGLWidget( parent ) { + m_displayList = 0; m_isDragging = false; m_molecule = 0; m_detail = 0; @@ -43,6 +48,14 @@ KalziumGLWidget::~KalziumGLWidget() { } +void KalziumGLWidget::deleteDisplayList() +{ +#ifdef USE_DISPLAY_LIST + if( m_displayList) glDeleteLists( m_displayList, 1 ); + m_displayList = 0; +#endif +} + void KalziumGLWidget::initializeGL() { glClearColor( 0.0, 0.0, 0.0, 1.0 ); @@ -119,6 +132,13 @@ void KalziumGLWidget::paintGL() } else glDisable( GL_FOG ); +#ifdef USE_DISPLAY_LIST + if ( ! m_displayList ) + { + m_displayList = glGenLists( 1 ); + glNewList( m_displayList, GL_COMPILE ); +#endif + // render the atoms if( m_atomStyle == ATOM_SPHERE ) { @@ -204,6 +224,13 @@ void KalziumGLWidget::paintGL() } } +#ifdef USE_DISPLAY_LIST + glEndList(); + } + + glCallList( m_displayList ); +#endif + // now, paint a semitransparent sphere around the selected atom if( m_selectedAtom ) @@ -228,8 +255,41 @@ void KalziumGLWidget::paintGL() c); glDisable( GL_BLEND ); + } +#ifdef USE_FPS_COUNTER + QTime t; + + static bool firstTime = true; + static int old_time, new_time; + static int frames; + static QString s; + if( firstTime ) + { + t.start(); + firstTime = false; + old_time = t.elapsed(); + frames = 0; + } + + new_time = t.elapsed(); + + frames++; + + if( new_time - old_time > 200 ) + { + s = QString::number( 1000 * frames / + double( new_time - old_time ), + 'f', 1 ); + s += " frames per second"; + frames = 0; + old_time = new_time; } + + renderText ( 20, 20, s ); + + update(); +#endif } void KalziumGLWidget::resizeGL( int width, int height ) @@ -291,6 +351,8 @@ void KalziumGLWidget::setupObjects() m_sphere.setup( sphere_detail, atomRadius() ); m_cylinder.setup( cylinder_faces, bondRadius() ); + + deleteDisplayList(); } void KalziumGLWidget::drawSphere( GLdouble x, GLdouble y, GLdouble z, @@ -417,7 +479,11 @@ void KalziumGLWidget::ChooseStylePreset( StylePreset stylePreset ) void KalziumGLWidget::prepareMoleculeData() { // translate the molecule so that center has coords 0,0,0 - m_molecule->Center(); + //m_molecule->Center(); + std::map m; + m["c"] = "c"; + m_molecule->DoTransformations(&m); + // calculate the radius of the molecule // that is, the maximal distance between an atom of the molecule diff --git a/kalzium/kalziumglwidget.h b/kalzium/kalziumglwidget.h index aad5389..3e046a6 100644 --- a/kalzium/kalziumglwidget.h +++ b/kalzium/kalziumglwidget.h @@ -18,6 +18,8 @@ #include #define USE_DOUBLE_PRECISION +#define USE_DISPLAY_LIST +#define USE_FPS_COUNTER #ifdef USE_DOUBLE_PRECISION #define FLOAT double @@ -216,6 +218,10 @@ class KalziumGLWidget : public QGLWidget Q_OBJECT protected: + + GLuint m_displayList; + void deleteDisplayList(); + /** * The geometric model of the sphere (used for atoms). */