Page MenuHomePhabricator

VTK 7 & Qt5.6 OpenGL Rendering conflict on OSX 10.11
Closed, ResolvedPublic

Event Timeline

conflict occurs also using 10.10.5.

Currently no rendering is possible on osx, using the in the description mentioned build configuration (that is more or less the state of the art).
Some observations:

  1. It occurs on release and debug mode.
  2. If you scale the MITK main window, the rendering works for one frame - then it's rendered again black.
  3. all four render-windows of the multi-widget are affected

That's not good news. Maybe it works after T19851 is fixed. Can you give it a try, @cordes? Just insert the lines mentioned there and see if it helps.

No it didn't help :-( So, do you have any other hints?

Screen Shot 2016-08-10 at 12.58.02.png (1×1 px, 213 KB)

Not really. Did you already look for a VTK bug report or created one? That would be my hint. :)

This must be a problem within the MitkWorkbench because it is possible to start the MitkExample (Step 8) with only a smaller Retina-based problem - see attached files. Running the MitkStep 8 on a non-Retina display works perfectly fine.

Screen Shot 2016-08-12 at 5.15.12 PM.png (2×2 px, 1 MB)

Screen Shot 2016-08-12 at 5.15.17 PM.png (1×1 px, 172 KB)

The application attribute Qt::AA_EnableHighDpiScaling, introduced in Qt 5.6, enables automatic scaling based on the pixel density of the monitor.

https://doc.qt.io/qt-5/highdpi.html

I've added the corresponding line of code to the Modules/AppUtil/src/mitkBaseApplication.cpp.
Before merge, please check what happens on a non retina display!

Fix seems not to work for tutorial steps. It's not based on BasedApplication and direct code injection doesn't work. This needs further investigation.

A possible way to make (at least) the tutorial steps work would be to use QVTKWidget2 as a base class for QmitkRenderWindow, but according to http://stackoverflow.com/questions/26944831/using-qvtkwidget-and-qopenglwidget-in-the-same-ui QVTKWidget2 is old.

About the Workbench Rendering Problem:

  • Try to start the workbench -> There will be a rendering problem
  • Then close the "Welcome Screen".
  • Close the Workbench
  • Reopen it.

The Rendering issues should have gone.

The problem seems to occur due to QtWebEngine which is responsible for displaying Webpages (as the Welcome-Page). This behaviour is mentioned also here: http://stackoverflow.com/questions/37329922/vtk-7-qt5-6-opengl-rendering-conflict-on-osx-10-11

This bug should be reproduced by this minimal example (taken from step 8 of the tutorials):

#include "Step8.h"

#include "mitkRenderingManager.h"
#include <QmitkRenderWindow.h>

#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QWebEngineView>
#include <vtkPolyData.h>
#include <vtkSphereSource.h>
#include <vtkPolyDataMapper.h>

Step8::Step8(int argc, char* argv[], QWidget *parent) :
  Step6(argc, argv, parent)
{
}

void Step8::SetupWidgets()
{
  QVBoxLayout* vlayout = new QVBoxLayout(this);
  vlayout->setMargin(0);
  vlayout->setSpacing(2);

  QWidget* viewParent = new QWidget(this);
  vlayout->addWidget(viewParent);

  QWebEngineView* webView = new QWebEngineView(this);
  webView->setObjectName(QStringLiteral("webView"));
  webView->setUrl(QUrl(QStringLiteral("http://www.google.de/")));
  vlayout->addWidget(webView);

  QVTKWidget *l_view = new QVTKWidget();

  l_view->setFixedSize( 300, 300 );
  vtkSmartPointer<vtkSphereSource> l_sphere_source = vtkSmartPointer<vtkSphereSource>::New();
  vtkSmartPointer<vtkPolyDataMapper> l_sphere_mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
  l_sphere_mapper->SetInputConnection( l_sphere_source->GetOutputPort() );
  vtkSmartPointer<vtkActor> l_sphere_actor = vtkSmartPointer<vtkActor>::New();
  l_sphere_actor->SetMapper( l_sphere_mapper );
  vtkSmartPointer<vtkRenderer> l_renderer = vtkSmartPointer<vtkRenderer>::New();
  l_renderer->AddActor( l_sphere_actor );
  l_view->GetRenderWindow()->AddRenderer( l_renderer );
  vlayout->addWidget(l_view);
}

Uncommenting the 4 lines with the QWebEngine will fix the rendering issues.

An interessting point: if you have both the QVTKWidget and the QWebEngineView in your code, but you don't add them both to the actual UI, the rendering issues will remain for the other Widget.

Thank you for the minimal example, @gaehlert.

BTW, Phabricator has syntax highlighting when you specify the language in the first line. You can even name your snippet, color it red, if it is a counter example, and make it scrollable. See the Remarkup reference for details. :-)

Rendering issues with QWebEngine
#include "Step8.h"

#include "mitkRenderingManager.h"
#include <QmitkRenderWindow.h>

#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QWebEngineView>
#include <vtkPolyData.h>
#include <vtkSphereSource.h>
#include <vtkPolyDataMapper.h>

Step8::Step8(int argc, char* argv[], QWidget *parent) :
  Step6(argc, argv, parent)
{
}

void Step8::SetupWidgets()
{
  QVBoxLayout* vlayout = new QVBoxLayout(this);
  vlayout->setMargin(0);
  vlayout->setSpacing(2);

  QWidget* viewParent = new QWidget(this);
  vlayout->addWidget(viewParent);

  QWebEngineView* webView = new QWebEngineView(this);
  webView->setObjectName(QStringLiteral("webView"));
  webView->setUrl(QUrl(QStringLiteral("http://www.google.de/")));
  vlayout->addWidget(webView);

  QVTKWidget *l_view = new QVTKWidget();

  l_view->setFixedSize( 300, 300 );
  vtkSmartPointer<vtkSphereSource> l_sphere_source = vtkSmartPointer<vtkSphereSource>::New();
  vtkSmartPointer<vtkPolyDataMapper> l_sphere_mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
  l_sphere_mapper->SetInputConnection( l_sphere_source->GetOutputPort() );
  vtkSmartPointer<vtkActor> l_sphere_actor = vtkSmartPointer<vtkActor>::New();
  l_sphere_actor->SetMapper( l_sphere_mapper );
  vtkSmartPointer<vtkRenderer> l_renderer = vtkSmartPointer<vtkRenderer>::New();
  l_renderer->AddActor( l_sphere_actor );
  l_view->GetRenderWindow()->AddRenderer( l_renderer );
  vlayout->addWidget(l_view);
}

I guess the issue arises from the fact that VTK uses OpenGL 1.x and QWebEngine uses modern OpenGL (>= 3.2). macOS in particular has trouble with OpenGL contexts of different versions in a single application. That's why I would suggest to wait for the VTK OpenGL 2 backend upgrade for MITK, which uses OpenGL 3.2. Together with QSurface::defaultFormat() we should be able to ensure OpenGL contexts of the same compatible version.

Hello Everyone,

Can someone try building this on Windows and Linux:
https://github.com/MattClarkson/MITK.git

branch:
19784-mac-rendering

Seems to work on my mac. Does image, surface and point-sets and I can view help pages. Or am I testing it wrong?

Caveats:

I’ve only made the WorkBench work. I haven’t looked at unit tests, or utility programs.
I don’t understand much about OpenGL
I don’t understand why you have those classes QmitkSingleApplication and QmitkSafeApplication so I stuck my code in where I could.

Therefore:

All commits in the commit log will need reviewing.

Hope that helps. Also note that due to a lack of mac builds, your master branch is starting to develop obvious mac build failures. These are also fixed on this branch.

M

StatusSetupUser
OSX 10.10, XCode 7.0, Qt 5.6.2@clarkson
macOS 10.13.2, XCode 9.2, Qt 5.10@kislinsk
CentOS 7, GCC 4.9, Qt 5.6.2@clarkson
Ubuntu 17.10, GCC 7.2, Qt 5.9.3@kislinsk
Windows 10, VS 2017, Qt 5.9@goch

edit: Tested successfully on macOS 10.13.2.

Deleted branch T19784-AddQtAAEnableHighDpiScaling.