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

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