Commit 89d2c3ae authored by Jan Möbius's avatar Jan Möbius

Moved locking to ViewerProperties

Added glState to ViewerProperties ( but keep local Pointer...)

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@4517 383ad7c9-94d9-4d36-a494-682f7c89f535
parent f0664c11
...@@ -303,7 +303,7 @@ bool scenegraph_pick( const unsigned int _examiner, ACG::SceneGraph::PickTarget ...@@ -303,7 +303,7 @@ bool scenegraph_pick( const unsigned int _examiner, ACG::SceneGraph::PickTarget
//Warning : Dont use template function as external static pointer for examiner widget is not resolved correctly!! //Warning : Dont use template function as external static pointer for examiner widget is not resolved correctly!!
void traverse( ACG::SceneGraph::MouseEventAction &_action ) { void traverse( ACG::SceneGraph::MouseEventAction &_action ) {
ACG::SceneGraph::traverse(sceneGraph_root_node_, ACG::SceneGraph::traverse(sceneGraph_root_node_,
_action,PluginFunctions::examiner_widgets_[activeExaminer_]->glState() ); _action,viewerProperties().glState() );
} }
//Warning : Dont use template function as external static pointer for examiner widget is not resolved correctly!! //Warning : Dont use template function as external static pointer for examiner widget is not resolved correctly!!
...@@ -314,7 +314,7 @@ void traverse( const unsigned int _examiner, ACG::SceneGraph::MouseEventAction ...@@ -314,7 +314,7 @@ void traverse( const unsigned int _examiner, ACG::SceneGraph::MouseEventAction
return; return;
} }
ACG::SceneGraph::traverse(sceneGraph_root_node_, _action,PluginFunctions::examiner_widgets_[_examiner]->glState() ); ACG::SceneGraph::traverse(sceneGraph_root_node_, _action,viewerProperties(_examiner).glState() );
} }
...@@ -344,7 +344,7 @@ void actionMode ( Viewer::ActionMode _mode) { ...@@ -344,7 +344,7 @@ void actionMode ( Viewer::ActionMode _mode) {
} }
ACG::GLState& glState() { ACG::GLState& glState() {
return examiner_widget_->glState(); return viewerProperties().glState();
} }
void getCurrentViewImage(QImage& _image) { void getCurrentViewImage(QImage& _image) {
...@@ -421,15 +421,15 @@ void viewAll() { ...@@ -421,15 +421,15 @@ void viewAll() {
} }
ACG::Vec3d viewingDirection() { ACG::Vec3d viewingDirection() {
return examiner_widget_->glState().viewing_direction(); return viewerProperties().glState().viewing_direction();
} }
ACG::Vec3d eyePos() { ACG::Vec3d eyePos() {
return examiner_widget_->glState().eye(); return viewerProperties().glState().eye();
} }
ACG::Vec3d upVector() { ACG::Vec3d upVector() {
return examiner_widget_->glState().up(); return viewerProperties().glState().up();
} }
......
...@@ -48,7 +48,7 @@ void Core::resetScenegraph() { ...@@ -48,7 +48,7 @@ void Core::resetScenegraph() {
for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) { for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
// update scene graph // update scene graph
coreWidget_->examiner_widgets_[i]->lockUpdate(); PluginFunctions::viewerProperties(i).lockUpdate();
coreWidget_->examiner_widgets_[i]->sceneGraph(root_node_scenegraph_); coreWidget_->examiner_widgets_[i]->sceneGraph(root_node_scenegraph_);
coreWidget_->examiner_widgets_[i]->viewAll(); coreWidget_->examiner_widgets_[i]->viewAll();
coreWidget_->examiner_widgets_[i]->setScenePos( coreWidget_->examiner_widgets_[i]->scene_center() , coreWidget_->examiner_widgets_[i]->setScenePos( coreWidget_->examiner_widgets_[i]->scene_center() ,
...@@ -56,7 +56,7 @@ void Core::resetScenegraph() { ...@@ -56,7 +56,7 @@ void Core::resetScenegraph() {
coreWidget_->examiner_widgets_[i]->setHome(); coreWidget_->examiner_widgets_[i]->setHome();
coreWidget_->examiner_widgets_[i]->drawMode( OpenFlipper::Options::standardDrawMode() ); coreWidget_->examiner_widgets_[i]->drawMode( OpenFlipper::Options::standardDrawMode() );
coreWidget_->examiner_widgets_[i]->unlockUpdate(); PluginFunctions::viewerProperties(i).unLockUpdate();
coreWidget_->examiner_widgets_[i]->updateGL(); coreWidget_->examiner_widgets_[i]->updateGL();
} }
......
...@@ -52,13 +52,18 @@ namespace Viewer { ...@@ -52,13 +52,18 @@ namespace Viewer {
CCWFront_(true), CCWFront_(true),
backgroundColor_(0.0f,0.0f,0.0f,0.0f), backgroundColor_(0.0f,0.0f,0.0f,0.0f),
renderPicking_(false), renderPicking_(false),
pickRendererMode_(ACG::SceneGraph::PICK_ANYTHING) pickRendererMode_(ACG::SceneGraph::PICK_ANYTHING),
locked_(0),
glState_(0)
{ {
} }
ViewerProperties::~ViewerProperties() { ViewerProperties::~ViewerProperties() {
if ( glState_ != 0 )
delete glState_;
} }
void ViewerProperties::actionMode(Viewer::ActionMode _am) { void ViewerProperties::actionMode(Viewer::ActionMode _am) {
......
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
#include <QObject> #include <QObject>
#include <ACG/Math/VectorT.hh> #include <ACG/Math/VectorT.hh>
#include <ACG/Scenegraph/SceneGraph.hh> #include <ACG/Scenegraph/SceneGraph.hh>
#include <ACG/GL/GLState.hh>
namespace Viewer { namespace Viewer {
...@@ -203,6 +204,46 @@ namespace Viewer { ...@@ -203,6 +204,46 @@ namespace Viewer {
*/ */
ACG::SceneGraph::PickTarget pickRendererMode_; ACG::SceneGraph::PickTarget pickRendererMode_;
//===========================================================================
public slots:
/** Lock update of display.
If locked (isUpdateLocked()) then all calls to updateDisplayList()
and updateGL() will have no effect! This is true until the display is
unlockUpdate()'ed.
*/
void lockUpdate() { locked_++; };
/// Unlock display locked by updateLock().
void unLockUpdate(){
locked_-- ;
if ( locked_ <0 ) {
std::cerr << "More unlocks then locks" << std::endl;
locked_ = 0;
}
};
/** Are updateDisplayList() and updateGL() locked?
(c.f. lockUpdate()) */
bool updateLocked() { return (locked_ != 0); };
private:
int locked_;
//===========================================================================
public:
/// Get the glState of the Viewer
ACG::GLState& glState() { return (*glState_); };
void setglState(ACG::GLState* _glState) { glState_ = _glState; };
private:
/// Pointer to the glState of the Viewer
ACG::GLState* glState_;
/** @} */ /** @} */
signals: signals:
...@@ -211,6 +252,8 @@ namespace Viewer { ...@@ -211,6 +252,8 @@ namespace Viewer {
void updated(); void updated();
void actionModeChanged( Viewer::ActionMode ); void actionModeChanged( Viewer::ActionMode );
}; };
} }
......
...@@ -122,8 +122,8 @@ glViewer::glViewer( QWidget* _parent, ...@@ -122,8 +122,8 @@ glViewer::glViewer( QWidget* _parent,
projectionUpdateLocked_(false), projectionUpdateLocked_(false),
blending_(true), blending_(true),
pick_mode_name_(""), pick_mode_name_(""),
pick_mode_idx_(-1) pick_mode_idx_(-1),
glstate_(0)
{ {
// check for OpenGL support // check for OpenGL support
if ( !QGLFormat::hasOpenGL() ) if ( !QGLFormat::hasOpenGL() )
...@@ -140,6 +140,8 @@ glViewer::glViewer( QWidget* _parent, ...@@ -140,6 +140,8 @@ glViewer::glViewer( QWidget* _parent,
// bind GL context to GL state class // bind GL context to GL state class
glstate_ = new ACG::GLState(); glstate_ = new ACG::GLState();
properties_.setglState( glstate_ );
// state // state
orthoWidth_ = 2.0; orthoWidth_ = 2.0;
...@@ -282,30 +284,6 @@ void glViewer::sceneGraph(ACG::SceneGraph::BaseNode* _root) ...@@ -282,30 +284,6 @@ void glViewer::sceneGraph(ACG::SceneGraph::BaseNode* _root)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void glViewer::lockUpdate()
{
updateLocked_ = true;
// QToolTip::add(moveButton_, "Switch to <b>move</b> mode (display locked)");
}
void glViewer::unlockUpdate()
{
// QToolTip::add(moveButton_,"Switch to <b>move</b> mode");
updateLocked_ = false;
}
void glViewer::unlockAndUpdate()
{
unlockUpdate();
updateGL();
}
//-----------------------------------------------------------------------------
void glViewer::trackMouse(bool _track) void glViewer::trackMouse(bool _track)
{ {
trackMouse_ = _track; trackMouse_ = _track;
...@@ -560,7 +538,7 @@ void glViewer::drawNow() ...@@ -560,7 +538,7 @@ void glViewer::drawNow()
void glViewer::updateGL() void glViewer::updateGL()
{ {
if (!isUpdateLocked() && !isHidden() ) if (!properties_.updateLocked() && !isHidden() )
{ {
glScene_->update(); glScene_->update();
} }
...@@ -623,8 +601,6 @@ void glViewer::drawScene() ...@@ -623,8 +601,6 @@ void glViewer::drawScene()
void glViewer::drawScene_mono() void glViewer::drawScene_mono()
{ {
emit(signalDrawScene(glstate_));
if (sceneGraphRoot_) if (sceneGraphRoot_)
{ {
if (! properties_.renderPicking() ) { if (! properties_.renderPicking() ) {
...@@ -771,7 +747,7 @@ void glViewer::flyTo(const QPoint& _pos, bool _move_back) ...@@ -771,7 +747,7 @@ void glViewer::flyTo(const QPoint& _pos, bool _move_back)
{ {
if (projectionMode_ == PERSPECTIVE_PROJECTION) if (projectionMode_ == PERSPECTIVE_PROJECTION)
{ {
ACG::Vec3d eye(glState().eye()); ACG::Vec3d eye(glstate_->eye());
ACG::Vec3d t = hitPoint - eye; ACG::Vec3d t = hitPoint - eye;
ACG::Vec3d e = eye + t * (_move_back ? -0.5f : 0.5f); ACG::Vec3d e = eye + t * (_move_back ? -0.5f : 0.5f);
flyTo(e, hitPoint, 300); flyTo(e, hitPoint, 300);
...@@ -892,7 +868,7 @@ void glViewer::initializeGL() ...@@ -892,7 +868,7 @@ void glViewer::initializeGL()
// lock update // lock update
lockUpdate(); properties_.lockUpdate();
// init GL state // init GL state
glstate_->initialize(); glstate_->initialize();
...@@ -944,7 +920,7 @@ void glViewer::initializeGL() ...@@ -944,7 +920,7 @@ void glViewer::initializeGL()
// unlock update (we started locked) // unlock update (we started locked)
unlockUpdate(); properties_.unLockUpdate();
} }
...@@ -1004,7 +980,7 @@ void glViewer::paintGL() ...@@ -1004,7 +980,7 @@ void glViewer::paintGL()
glewInit(); glewInit();
// lock update // lock update
lockUpdate(); properties_.lockUpdate();
// init GL state // init GL state
glstate_->initialize(); glstate_->initialize();
...@@ -1035,14 +1011,14 @@ void glViewer::paintGL() ...@@ -1035,14 +1011,14 @@ void glViewer::paintGL()
emit(signalInitializeGL()); emit(signalInitializeGL());
// unlock update (we started locked) // unlock update (we started locked)
unlockUpdate(); properties_.unLockUpdate();
initialized = true; initialized = true;
} }
if (!isUpdateLocked()) if (!properties_.updateLocked())
{ {
lockUpdate(); properties_.lockUpdate();
glPushAttrib (GL_ALL_ATTRIB_BITS); glPushAttrib (GL_ALL_ATTRIB_BITS);
...@@ -1074,7 +1050,7 @@ void glViewer::paintGL() ...@@ -1074,7 +1050,7 @@ void glViewer::paintGL()
if (!stereo_) if (!stereo_)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
unlockUpdate(); properties_.unLockUpdate();
// draw scene // draw scene
drawScene(); drawScene();
...@@ -1821,7 +1797,7 @@ glViewer::viewMouseEvent(QMouseEvent* _event) ...@@ -1821,7 +1797,7 @@ glViewer::viewMouseEvent(QMouseEvent* _event)
if (fast_pick(_event->pos(), c)) if (fast_pick(_event->pos(), c))
{ {
trackball_center_ = c; trackball_center_ = c;
trackball_radius_ = std::max(scene_radius_, (c-glState().eye()).norm()*0.9f); trackball_radius_ = std::max(scene_radius_, (c-glstate_->eye()).norm()*0.9f);
} }
} }
...@@ -2122,7 +2098,7 @@ void glViewer::slotAnimation() ...@@ -2122,7 +2098,7 @@ void glViewer::slotAnimation()
rotate( lastRotationAxis_, lastRotationAngle_ ); rotate( lastRotationAxis_, lastRotationAngle_ );
updateGL(); updateGL();
if (!isUpdateLocked()) { if (!properties_.updateLocked()) {
msecs += t.elapsed(); msecs += t.elapsed();
if (count==10) { if (count==10) {
assert(statusbar_!=0); assert(statusbar_!=0);
......
...@@ -153,32 +153,6 @@ public: ...@@ -153,32 +153,6 @@ public:
/// Swaps the screen contents with the off-screen buffer. /// Swaps the screen contents with the off-screen buffer.
virtual void swapBuffers(); virtual void swapBuffers();
/// get OpenGL state
ACG::GLState& glState() { return *glstate_; }
/** Lock update of display.
If locked (isUpdateLocked()) then all calls to updateDisplayList()
and updateGL() will have no effect! This is true until the display is
unlockUpdate()'ed.
*/
virtual void lockUpdate();
/// Unlock display locked by updateLock().
virtual void unlockUpdate();
/** Convenient unlock and update.
Calls unlockUpdate() and then updateDisplayList() and updateGL()
(Note that this has only an effect if !isUpdateLocked().)
*/
virtual void unlockAndUpdate();
/** Are updateDisplayList() and updateGL() locked?
(c.f. lockUpdate()) */
bool isUpdateLocked() const { return updateLocked_; }
/// Lock update of projection matrix. /// Lock update of projection matrix.
void lockProjectionUpdate( void ) { projectionUpdateLocked_ = true; } void lockProjectionUpdate( void ) { projectionUpdateLocked_ = true; }
...@@ -451,9 +425,6 @@ signals: ...@@ -451,9 +425,6 @@ signals:
void signalNodeChanged(ACG::SceneGraph::BaseNode* _node); void signalNodeChanged(ACG::SceneGraph::BaseNode* _node);
/// action mode was changed /// action mode was changed
void signalActionModeChanged( Viewer::ActionMode _m); void signalActionModeChanged( Viewer::ActionMode _m);
/// render callback
void signalDrawScene(ACG::GLState* _state);
signals: signals:
...@@ -576,8 +547,7 @@ protected: ...@@ -576,8 +547,7 @@ protected:
GLdouble near_, far_, fovy_; GLdouble near_, far_, fovy_;
// scenegraph
ACG::GLState *glstate_;
// helper // helper
...@@ -977,8 +947,12 @@ private: ...@@ -977,8 +947,12 @@ private:
Viewer::ViewerProperties* properties(){ return &properties_; }; Viewer::ViewerProperties* properties(){ return &properties_; };
private: private:
/// All properties for this viewer
Viewer::ViewerProperties properties_; Viewer::ViewerProperties properties_;
/// Gl State
ACG::GLState *glstate_;
private slots: private slots:
/** Called when properties for the viewer require a redraw /** Called when properties for the viewer require a redraw
* The slot will trigger the redraw after setting the right properties. * The slot will trigger the redraw after setting the right properties.
......
...@@ -71,8 +71,8 @@ bool glViewer::pick( ACG::SceneGraph::PickTarget _pickTarget, ...@@ -71,8 +71,8 @@ bool glViewer::pick( ACG::SceneGraph::PickTarget _pickTarget,
GLuint selectionBuffer[ SELECTION_BUFFER_SIZE ], GLuint selectionBuffer[ SELECTION_BUFFER_SIZE ],
nameBuffer[ NAME_STACK_SIZE ]; nameBuffer[ NAME_STACK_SIZE ];
const ACG::GLMatrixd& modelview = glstate_->modelview(); const ACG::GLMatrixd& modelview = properties_.glState().modelview();
const ACG::GLMatrixd& projection = glstate_->projection(); const ACG::GLMatrixd& projection = properties_.glState().projection();
// prepare GL state // prepare GL state
...@@ -93,7 +93,7 @@ bool glViewer::pick( ACG::SceneGraph::PickTarget _pickTarget, ...@@ -93,7 +93,7 @@ bool glViewer::pick( ACG::SceneGraph::PickTarget _pickTarget,
// do the picking // do the picking
ACG::SceneGraph::PickAction action(_pickTarget); ACG::SceneGraph::PickAction action(_pickTarget);
ACG::SceneGraph::traverse(sceneGraphRoot_, action, *glstate_); ACG::SceneGraph::traverse(sceneGraphRoot_, action, properties_.glState());
int hits = glRenderMode(GL_RENDER); int hits = glRenderMode(GL_RENDER);
// restore GL state // restore GL state
...@@ -141,7 +141,7 @@ bool glViewer::pick( ACG::SceneGraph::PickTarget _pickTarget, ...@@ -141,7 +141,7 @@ bool glViewer::pick( ACG::SceneGraph::PickTarget _pickTarget,
GLdouble min_zz = ((GLdouble)min_z) / ((GLdouble)zscale); GLdouble min_zz = ((GLdouble)min_z) / ((GLdouble)zscale);
GLdouble max_zz = ((GLdouble)max_z) / ((GLdouble)zscale); GLdouble max_zz = ((GLdouble)max_z) / ((GLdouble)zscale);
GLdouble zz = 0.5F * (min_zz + max_zz); GLdouble zz = 0.5F * (min_zz + max_zz);
*_hitPointPtr = glstate_->unproject(ACG::Vec3d(x,y,zz)); *_hitPointPtr = properties_.glState().unproject(ACG::Vec3d(x,y,zz));
} }
return true; return true;
...@@ -175,7 +175,7 @@ fast_pick( const QPoint& _mousePos, ...@@ -175,7 +175,7 @@ fast_pick( const QPoint& _mousePos,
if (z < 0.99999) if (z < 0.99999)
{ {
_hitPoint = glstate_->unproject( ACG::Vec3d(x, y, z) ); _hitPoint = properties_.glState().unproject( ACG::Vec3d(x, y, z) );
return true; return true;
} }
else return false; else return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment