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
//Warning : Dont use template function as external static pointer for examiner widget is not resolved correctly!!
void traverse( ACG::SceneGraph::MouseEventAction &_action ) {
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!!
......@@ -314,7 +314,7 @@ void traverse( const unsigned int _examiner, ACG::SceneGraph::MouseEventAction
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) {
}
ACG::GLState& glState() {
return examiner_widget_->glState();
return viewerProperties().glState();
}
void getCurrentViewImage(QImage& _image) {
......@@ -421,15 +421,15 @@ void viewAll() {
}
ACG::Vec3d viewingDirection() {
return examiner_widget_->glState().viewing_direction();
return viewerProperties().glState().viewing_direction();
}
ACG::Vec3d eyePos() {
return examiner_widget_->glState().eye();
return viewerProperties().glState().eye();
}
ACG::Vec3d upVector() {
return examiner_widget_->glState().up();
return viewerProperties().glState().up();
}
......
......@@ -48,7 +48,7 @@ void Core::resetScenegraph() {
for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
// update scene graph
coreWidget_->examiner_widgets_[i]->lockUpdate();
PluginFunctions::viewerProperties(i).lockUpdate();
coreWidget_->examiner_widgets_[i]->sceneGraph(root_node_scenegraph_);
coreWidget_->examiner_widgets_[i]->viewAll();
coreWidget_->examiner_widgets_[i]->setScenePos( coreWidget_->examiner_widgets_[i]->scene_center() ,
......@@ -56,7 +56,7 @@ void Core::resetScenegraph() {
coreWidget_->examiner_widgets_[i]->setHome();
coreWidget_->examiner_widgets_[i]->drawMode( OpenFlipper::Options::standardDrawMode() );
coreWidget_->examiner_widgets_[i]->unlockUpdate();
PluginFunctions::viewerProperties(i).unLockUpdate();
coreWidget_->examiner_widgets_[i]->updateGL();
}
......
......@@ -52,13 +52,18 @@ namespace Viewer {
CCWFront_(true),
backgroundColor_(0.0f,0.0f,0.0f,0.0f),
renderPicking_(false),
pickRendererMode_(ACG::SceneGraph::PICK_ANYTHING)
pickRendererMode_(ACG::SceneGraph::PICK_ANYTHING),
locked_(0),
glState_(0)
{
}
ViewerProperties::~ViewerProperties() {
if ( glState_ != 0 )
delete glState_;
}
void ViewerProperties::actionMode(Viewer::ActionMode _am) {
......
......@@ -50,6 +50,7 @@
#include <QObject>
#include <ACG/Math/VectorT.hh>
#include <ACG/Scenegraph/SceneGraph.hh>
#include <ACG/GL/GLState.hh>
namespace Viewer {
......@@ -203,6 +204,46 @@ namespace Viewer {
*/
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:
......@@ -211,6 +252,8 @@ namespace Viewer {
void updated();
void actionModeChanged( Viewer::ActionMode );
};
}
......
......@@ -122,8 +122,8 @@ glViewer::glViewer( QWidget* _parent,
projectionUpdateLocked_(false),
blending_(true),
pick_mode_name_(""),
pick_mode_idx_(-1)
pick_mode_idx_(-1),
glstate_(0)
{
// check for OpenGL support
if ( !QGLFormat::hasOpenGL() )
......@@ -140,6 +140,8 @@ glViewer::glViewer( QWidget* _parent,
// bind GL context to GL state class
glstate_ = new ACG::GLState();
properties_.setglState( glstate_ );
// state
orthoWidth_ = 2.0;
......@@ -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)
{
trackMouse_ = _track;
......@@ -560,7 +538,7 @@ void glViewer::drawNow()
void glViewer::updateGL()
{
if (!isUpdateLocked() && !isHidden() )
if (!properties_.updateLocked() && !isHidden() )
{
glScene_->update();
}
......@@ -623,8 +601,6 @@ void glViewer::drawScene()
void glViewer::drawScene_mono()
{
emit(signalDrawScene(glstate_));
if (sceneGraphRoot_)
{
if (! properties_.renderPicking() ) {
......@@ -771,7 +747,7 @@ void glViewer::flyTo(const QPoint& _pos, bool _move_back)
{
if (projectionMode_ == PERSPECTIVE_PROJECTION)
{
ACG::Vec3d eye(glState().eye());
ACG::Vec3d eye(glstate_->eye());
ACG::Vec3d t = hitPoint - eye;
ACG::Vec3d e = eye + t * (_move_back ? -0.5f : 0.5f);
flyTo(e, hitPoint, 300);
......@@ -892,7 +868,7 @@ void glViewer::initializeGL()
// lock update
lockUpdate();
properties_.lockUpdate();
// init GL state
glstate_->initialize();
......@@ -944,7 +920,7 @@ void glViewer::initializeGL()
// unlock update (we started locked)
unlockUpdate();
properties_.unLockUpdate();
}
......@@ -1004,7 +980,7 @@ void glViewer::paintGL()
glewInit();
// lock update
lockUpdate();
properties_.lockUpdate();
// init GL state
glstate_->initialize();
......@@ -1035,14 +1011,14 @@ void glViewer::paintGL()
emit(signalInitializeGL());
// unlock update (we started locked)
unlockUpdate();
properties_.unLockUpdate();
initialized = true;
}
if (!isUpdateLocked())
if (!properties_.updateLocked())
{
lockUpdate();
properties_.lockUpdate();
glPushAttrib (GL_ALL_ATTRIB_BITS);
......@@ -1074,7 +1050,7 @@ void glViewer::paintGL()
if (!stereo_)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
unlockUpdate();
properties_.unLockUpdate();
// draw scene
drawScene();
......@@ -1821,7 +1797,7 @@ glViewer::viewMouseEvent(QMouseEvent* _event)
if (fast_pick(_event->pos(), 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()
rotate( lastRotationAxis_, lastRotationAngle_ );
updateGL();
if (!isUpdateLocked()) {
if (!properties_.updateLocked()) {
msecs += t.elapsed();
if (count==10) {
assert(statusbar_!=0);
......
......@@ -153,32 +153,6 @@ public:
/// Swaps the screen contents with the off-screen buffer.
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.
void lockProjectionUpdate( void ) { projectionUpdateLocked_ = true; }
......@@ -451,9 +425,6 @@ signals:
void signalNodeChanged(ACG::SceneGraph::BaseNode* _node);
/// action mode was changed
void signalActionModeChanged( Viewer::ActionMode _m);
/// render callback
void signalDrawScene(ACG::GLState* _state);
signals:
......@@ -576,8 +547,7 @@ protected:
GLdouble near_, far_, fovy_;
// scenegraph
ACG::GLState *glstate_;
// helper
......@@ -977,8 +947,12 @@ private:
Viewer::ViewerProperties* properties(){ return &properties_; };
private:
/// All properties for this viewer
Viewer::ViewerProperties properties_;
/// Gl State
ACG::GLState *glstate_;
private slots:
/** Called when properties for the viewer require a redraw
* The slot will trigger the redraw after setting the right properties.
......
......@@ -71,8 +71,8 @@ bool glViewer::pick( ACG::SceneGraph::PickTarget _pickTarget,
GLuint selectionBuffer[ SELECTION_BUFFER_SIZE ],
nameBuffer[ NAME_STACK_SIZE ];
const ACG::GLMatrixd& modelview = glstate_->modelview();
const ACG::GLMatrixd& projection = glstate_->projection();
const ACG::GLMatrixd& modelview = properties_.glState().modelview();
const ACG::GLMatrixd& projection = properties_.glState().projection();
// prepare GL state
......@@ -93,7 +93,7 @@ bool glViewer::pick( ACG::SceneGraph::PickTarget _pickTarget,
// do the picking
ACG::SceneGraph::PickAction action(_pickTarget);
ACG::SceneGraph::traverse(sceneGraphRoot_, action, *glstate_);
ACG::SceneGraph::traverse(sceneGraphRoot_, action, properties_.glState());
int hits = glRenderMode(GL_RENDER);
// restore GL state
......@@ -141,7 +141,7 @@ bool glViewer::pick( ACG::SceneGraph::PickTarget _pickTarget,
GLdouble min_zz = ((GLdouble)min_z) / ((GLdouble)zscale);
GLdouble max_zz = ((GLdouble)max_z) / ((GLdouble)zscale);
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;
......@@ -175,7 +175,7 @@ fast_pick( const QPoint& _mousePos,
if (z < 0.99999)
{
_hitPoint = glstate_->unproject( ACG::Vec3d(x, y, z) );
_hitPoint = properties_.glState().unproject( ACG::Vec3d(x, y, z) );
return true;
}
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