Commit 6ebba29f authored by Jan Möbius's avatar Jan Möbius

Merge branch 'fixMSAA' into 'master'

fixes #13 by using a non multisampled FBO for picking

Closes #13

See merge request !70
parents 3674f2d6 362324d6
......@@ -138,6 +138,7 @@ glViewer::glViewer( QGraphicsScene* _scene,
glDebugLogger_(0),
#endif
pickCache_(0),
mouseCache_(nullptr),
updatePickCache_(true),
pickCacheSupported_(true),
constrainedRotationAxis_(std::numeric_limits<double>::quiet_NaN(), 0, 0),
......@@ -217,6 +218,8 @@ glViewer::~glViewer()
delete glstate_;
deleteGLDebugLogger();
if (mouseCache_ != nullptr)
deleteQFBO(mouseCache_);
}
......@@ -1563,12 +1566,31 @@ void glViewer::contextMenuEvent(QGraphicsSceneContextMenuEvent* _e)
void glViewer::mousePressEvent(QGraphicsSceneMouseEvent* _e)
{
makeCurrent();
QPoint p (_e->scenePos().x(), _e->scenePos().y());
QMouseEvent me(QEvent::MouseButtonPress ,p, _e->screenPos(), _e->button(),
_e->buttons(), _e->modifiers());
_e->accept ();
emit signalMakeActive();
const GLuint prevFBO = ACG::GLState::getFramebufferDraw();
//recreate FBO if gl area was resized
if (mouseCache_ != nullptr && QFBOResized(mouseCache_))
{
deleteQFBO(mouseCache_);
mouseCache_ = nullptr;
}
if (mouseCache_ == nullptr)
{
GLuint fboHandle;
int samples = 0;
createQFBO(mouseCache_, &fboHandle, glWidth() , glHeight(), &samples);
}
bindQFBO(mouseCache_);
glScene_->update ();
// right button pressed => popup menu (ignore here)
......@@ -1608,6 +1630,8 @@ void glViewer::mousePressEvent(QGraphicsSceneMouseEvent* _e)
break;
}
}
//restore old FBO
ACG::GLState::bindFramebuffer(GL_FRAMEBUFFER_EXT,prevFBO);
}
......@@ -1894,7 +1918,7 @@ void glViewer::handleNormalNavigation( QMouseEvent* _event ) {
switch (_event->type()) {
case QEvent::MouseButtonPress: {
// Get the depth at the current mouse position ( projected )
// This is used to do the translation in world coordinates
// As the scene is rendered, we can get the depth directly from the framebuffer.
......
......@@ -573,6 +573,8 @@ private:
// wrapper to create QFramebufferObject returns true if QFBO is valid if samples is -1 the default samples are retrieved
bool createQFBO(QOpenGLFramebufferObject*& _ptr, GLuint* _handle, int _width, int _height, int* _samples);
bool bindQFBO(QOpenGLFramebufferObject* _ptr);
bool QFBOResized(QOpenGLFramebufferObject* _ptr);
void blitQFBO(QOpenGLFramebufferObject* _ptr1, const QRect& _size1, QOpenGLFramebufferObject* _ptr2, const QRect& _size2);
void deleteQFBO(QOpenGLFramebufferObject* _ptr);
......@@ -889,6 +891,7 @@ private:
/// Framebuffer object that holds the pick cache
QFramebufferObject* pickCache_;
QFramebufferObject* mouseCache_;
/// Should the pick cache be updated
bool updatePickCache_;
......
......@@ -214,6 +214,20 @@ void glViewer::blitQFBO(QOpenGLFramebufferObject* _ptr1, const QRect& _size1, QO
//-----------------------------------------------------------------------------
bool glViewer::bindQFBO(QOpenGLFramebufferObject* _ptr)
{
return _ptr->bind();
}
//-----------------------------------------------------------------------------
bool glViewer::QFBOResized(QOpenGLFramebufferObject* _ptr1)
{
return _ptr1->size() != QSize(glWidth(), glHeight());
}
//-----------------------------------------------------------------------------
void glViewer::deleteQFBO(QOpenGLFramebufferObject* _ptr)
{
delete _ptr;
......
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