Commit 91a89349 authored by Emmanuel Promayon's avatar Emmanuel Promayon
Browse files

fix-bug#181 RendererWidget inherits from QVTKWidget2



There is also some specific OpenGL Format/context forced
reinitialization for integrated card (as well as a mean
to avoir this reinitialization, using CAMITK_NO_OPENGL_RESET=1
environment variable.
Note: use primusrun instead of optirun for GPU/discrete card
configuration on Linux (bumblebee)

Signed-off-by: Emmanuel Promayon's avatarEmmanuel Promayon <Emmanuel.Promayon@imag.fr>
parent 00f1e102
......@@ -33,6 +33,8 @@
#include <QKeyEvent>
#include <QFileInfo>
#include <QCursor>
#include <QProcessEnvironment>
#include <QOpenGLContext>
// -- VTK stuff
#include <vtkObjectFactory.h>
......@@ -362,7 +364,7 @@ void vtkInteractorStylePick::PrintSelf ( ostream& os, vtkIndent indent ) {
QMap <RendererWidget::ScreenshotFormat , RendererWidget::ScreenshotFormatInfo*> screenshotMap;
//---------------------- Constructor ------------------------
RendererWidget::RendererWidget(QWidget* parent, ControlMode mode) : QVTKWidget(parent) {
RendererWidget::RendererWidget(QWidget* parent, ControlMode mode) : QVTKWidget2(parent) {
setObjectName( "RendererWidget" );
//-- initialize screenshotMap only at the first invocation of constructor
......@@ -379,7 +381,65 @@ RendererWidget::RendererWidget(QWidget* parent, ControlMode mode) : QVTKWidget(p
policy.setHeightForWidth(false);
setSizePolicy(policy);
//-- display options (this is not a state manage by the renderer, but a property of the actors
//-- OpenGL context on integrated card
// For more information about this problem
// see https://bugzilla-timc.imag.fr/show_bug.cgi?id=181
// Description of the bugfix:
// In order to make it work on integrated cards as well as on GPU (using primusrun
// see below for optirun), RendererWidget is now inheriting from QVTKWidget2 (which
// in turns inherits from QGLWidget, which is deprecated...)
//
// Unfortunately this trigger another bug where, although everything is alright
// when running on the GPU (using primusrun), it does not work on the integrated card.
//
// To make it work on both, the OpenGL format has to be reinitialized.
//
// This might lead to performance issue (not investigated). If this is the case,
// set the environment variable CAMITK_NO_OPENGL_RESET to 1.
// For instance:
// CAMITK_NO_OPENGL_RESET=1 primusrun bin/camitk-imp
// or
// CAMITK_NO_OPENGL_RESET=1 bin/camitk-imp
//
// If the CAMITK_NO_OPENGL_RESET environment variable is set to 1, then the OpenGL context will not be
// reset.
// Note for bumblebee users on Linux:
// There is a bug in bumblebee/optirun, see https://bugreports.qt.io/browse/QTBUG-33258
// you need to use primusrun (which is also the bumblebee developer team recommendation)
/*
qDebug() << "------------------------ OpenGL information -------------------------" ;
qDebug() << "OpenGL Versions Supported: " << QGLFormat::openGLVersionFlags() ;
qDebug() << "Current format:" << format();
qDebug() << "Context valid: " << context()->isValid() ;
qDebug() << "Direct rendering: " << context()->format().directRendering();
qDebug() << "Context OpenGL Version: " << context()->format().majorVersion() << "." << context()->format().minorVersion() ;
qDebug() << "Vendor: " << (const char*)glGetString(GL_VENDOR);
qDebug() << "Renderer: " << (const char*)glGetString(GL_RENDERER);
qDebug() << "Version: " << (const char*)glGetString(GL_VERSION) ;
qDebug() << "GLSL version: " << (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION) ;
qDebug() << "---------------------------------------------------------------------\n";
*/
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
bool resetOpenGL = true;
if (env.contains("CAMITK_NO_OPENGL_RESET") && env.value("CAMITK_NO_OPENGL_RESET") == "1") {
CAMITK_INFO("RendererWidget", "constructor", "CAMITK_NO_OPENGL_RESET on: QGLFormat is not reset\n");
resetOpenGL = false;
}
if (resetOpenGL) {
// recreate a format, using some default from the current context
QGLFormat newFormat;
newFormat.setProfile(context()->format().profile());
newFormat.setDepthBufferSize(context()->format().depthBufferSize());
newFormat.setStencilBufferSize(context()->format().stencilBufferSize());
context()->setFormat(newFormat);
}
//-- display options (this is not a state managed by the renderer, but a property of the actors)
backfaceCulling = false;
displayCopyright = true;
rendering3DRedBlue = false;
......@@ -1263,13 +1323,13 @@ void RendererWidget::mousePressEvent ( QMouseEvent* event ) {
if ( event->button() == Qt::RightButton ) {
emit rightButtonPressed();
}
QVTKWidget::mousePressEvent ( event );
QVTKWidget2::mousePressEvent ( event );
}
}
//--------------------- mouseReleaseEvent ----------------------------------
void RendererWidget::mouseReleaseEvent(QMouseEvent* event) {
QVTKWidget::mouseReleaseEvent ( event );
QVTKWidget2::mouseReleaseEvent ( event );
endPicking();
}
......@@ -1309,7 +1369,7 @@ void RendererWidget::mouseMoveEvent(QMouseEvent* event) {
// just keep the button pressed
//pick();
}
QVTKWidget::mouseMoveEvent(event);
QVTKWidget2::mouseMoveEvent(event);
}
......
......@@ -30,9 +30,13 @@
#include "CamiTKAPI.h"
// -- VTK stuff
#include <QVTKWidget.h>
#include <QVTKWidget2.h>
#include <vtkSmartPointer.h>
#include <vtkInteractorStyle.h>
// additional needed headers for QVTKWidget2
#include <vtkGenericOpenGLRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <QVTKInteractor.h>
// -- VTK stuff classes
class vtkRenderer;
......@@ -112,14 +116,14 @@ namespace camitk{
*
* The Core companion class is InteractiveViewer (which delegates all vtk stuff to RendererWidget.
*
* It is directly based on QVTKWidget, the GUI support class available in Vtk version >= 5.0
* It is directly based on QVTKWidget2, the GUI support class available in Vtk version >= 5.0
* This is a pure Qt/vtk wrapper class (no Core stuff).
*
* For developers: please check the coding policy in InteractiveViewer API documentation first.
*
*
**/
class CAMITK_API RendererWidget : public QVTKWidget {
class CAMITK_API RendererWidget : public QVTKWidget2 {
Q_OBJECT
Q_ENUMS(ControlMode CameraOrientation); // so that it can be used in property editor
......
Supports Markdown
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