OpenGL state errors with QVTKOpenGLWidget and vtk8.2

Hi,

We have an application based on Qt and Vtk. It runs well on VTK8.1 However, after upgrading to VTK8.2, we experience problems when we first call vtkRenderer::Render(). This call ultimately ends up calling vtkOpenGLState::CheckState, and this fuction emits a lot of error messages which are listed below.

I understand that the vtkOpenGLState is not initialized properly, but I can’t seem to figure out what the proper order of initialization is supposed to be. I am calling QSurfaceFormat::setDefaultFormat() before creating my QApplication object. The render window initialization is pretty straightforward:

_vtkWidget = new QVTKOpenGLWidget((QWidget *)nullptr);

_vtkWidget->setEnableHiDPI(true);

// VTK Renderer

_renderer = vtkSmartPointer<vtkRenderer>::New();

_renderer->SetLayer(0);

_rendererOverlay = vtkSmartPointer<vtkRenderer>::New();

_rendererOverlay->SetLayer(1);

// VTK/Qt wedded

vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;

_qvtkWidget>SetRenderWindow(renderWindow);

renderWindow->SetNumberOfLayers(2);

renderWindow->AddRenderer(_renderer);

renderWindow->AddRenderer(_rendererOverlay);

The vtkOpenGLState::Initialize function is never called

I have tried switching from QVTKOpenGLWidget to QVTKOpenGLNativeWidget, which fixes the state initialization problems (but I am unable to use it, since it causes problems with line drawing as documented here: https://gitlab.kitware.com/vtk/vtk/issues/17154).

So the code works with 8.1 and also works with QVTKOpenGLNativeWidget.

Can someone help me understand what I am doing wrong with the initialization of QVTKOpenGLWidget or the render window?

Generic Warning: In d:\projects\flow-2\tools\conan\thirdparty\build\libvtk\rendering\opengl2\vtkopenglstate.cxx, line 95

Error in cache state for GL_DEPTH_WRITEMASK

Generic Warning: In d:\projects\flow-2\tools\conan\thirdparty\build\libvtk\rendering\opengl2\vtkopenglstate.cxx, line 106

Error in cache state for GL_COLOR_WRITEMASK

Generic Warning: In d:\projects\flow-2\tools\conan\thirdparty\build\libvtk\rendering\opengl2\vtkopenglstate.cxx, line 124

Error in cache state for GL_CULL_FACE

Generic Warning: In d:\projects\flow-2\tools\conan\thirdparty\build\libvtk\rendering\opengl2\vtkopenglstate.cxx, line 131

Error in cache state for GL_MULTISAMPLE

Generic Warning: In d:\projects\flow-2\tools\conan\thirdparty\build\libvtk\rendering\opengl2\vtkopenglstate.cxx, line 144

Error in cache state for GL_STENCIL_TEST

Generic Warning: In d:\projects\flow-2\tools\conan\thirdparty\build\libvtk\rendering\opengl2\vtkopenglstate.cxx, line 162

Error in cache state for GL_VIEWPORT

Generic Warning: In d:\projects\flow-2\tools\conan\thirdparty\build\libvtk\rendering\opengl2\vtkopenglstate.cxx, line 173

Error in cache state for GL_SCISSOR_BOX

Generic Warning: In d:\projects\flow-2\tools\conan\thirdparty\build\libvtk\rendering\opengl2\vtkopenglstate.cxx, line 179

Error in cache state for GL_CULL_FACE_MODE

Generic Warning: In d:\projects\flow-2\tools\conan\thirdparty\build\libvtk\rendering\opengl2\vtkopenglstate.cxx, line 185

Error in cache state for GL_DEPTH_FUNC

Generic Warning: In d:\projects\flow-2\tools\conan\thirdparty\build\libvtk\rendering\opengl2\vtkopenglstate.cxx, line 191

Error in cache state for GL_BLEND_SRC_RGB

Generic Warning: In d:\projects\flow-2\tools\conan\thirdparty\build\libvtk\rendering\opengl2\vtkopenglstate.cxx, line 197

Error in cache state for GL_BLEND_SRC_ALPHA

Generic Warning: In d:\projects\flow-2\tools\conan\thirdparty\build\libvtk\rendering\opengl2\vtkopenglstate.cxx, line 203

Error in cache state for GL_BLEND_DST_RGB

Generic Warning: In d:\projects\flow-2\tools\conan\thirdparty\build\libvtk\rendering\opengl2\vtkopenglstate.cxx, line 209

Error in cache state for GL_BLEND_DST_ALPHA

Generic Warning: In d:\projects\flow-2\tools\conan\thirdparty\build\libvtk\rendering\opengl2\vtkopenglstate.cxx, line 222

Error in cache state for GL_COLOR_CLEAR_VALUE
1 Like

Is your widget in a scrolling region? You may be able to use the non-native widget depending on what parent widgets it is placed into.

Andras,

I am using the non-native widget. That’s the one that doesn’t work. If I use QVTKOpenGLNativeWidget, since it inherits from QOpenGLWidget, the QT calls to initialize OpenGL are made (initializeGL). But if I use QVTKOpenGLWidget, the Qt OpenGL initialization never seems to occur. I have been poking through the source code and I can’t figure out how it is supposed to happen. QVTKOpenGLWidget has a QVTKOPenGLWIndow* inside of it. This class has an initilalizeGL call but it is never called and there doesn’t seem to be any external way to call it.

thank you for any help.

According to QVTKOpenGLWidget documentation, the non-native widget works only in special cases (the widget is not in a scrolling area, etc.).

QVTKOpenGLNativeWidget should work well (we use it extensively in 3D Slicer for very complex visualizations). You can try to tune anti-aliasing settings to improve appearance of lines. You may need to change the default surface format for the application if you want to use MSAA. We currently don’t use MSAA in 3D Slicer, so I cannot confirm if it works well, but there are VTK tests for that, so I assume that it does.

Andras,

Thank you for the advice. I believe the conditions we are using QVTKOpenGLWidget are appropriate, but still it doesn’t work with 8.2. I can get QVTLOpenGLNativeWidget to work, but certain visualizations being done via glsl fragment shader code don’t seem to work right. Simple stuff like drawing lines and shading volumes. I guess it may be easier to try and get QVTLOpenGLNativeWidget to work, But does anyone understand how QVTKOpenGLWidget is supposed to initialize OpenGL? It doesn’t inherit from qopenglwidget, so there must be a different mechanism for initialization, but I can’t find it…

Hello, and welcome to the VTK community.

There are multiples QVTKOpenGLWidget example usage in GUISupport/Qt/Testing/Cxx directory.
This may help you understand how to use it.

Mathieu,

Thanks, I found the answer there:

// Make sure that the widget context is valid before making OpenGL calls.
// This should only take up to 4 calls to processEvents(). If this test keeps
// timing out, consider that the widget initialization is broken.
while (!_qvtkWidget->isValid()) {
    app.processEvents();
}

The OpenGL initialization occurs as a result of a Qt event! DOH!

1 Like

Hi,

I am running into this same issue, but haven’t been able to get proper OpenGL initialization to take place even when adding a block of code similar to the posted solution:

while (!_qvtkWidget->isValid()) {
    app.processEvents();
}

After doing a deep debug dive, it looks like QVTKOpenGLWindow::initializeGL is indeed getting called right before the first call to vtkGenericOpenGLRenderWindow::Render. But I am still seeing the long list of errors in cache state.

Any ideas on what could be going wrong or other things that need to happen for the widget to initialize properly?

Are you able to use the example I referenced ?

Yes - the example works OK without any issues. One thing to note is that I am working with a stereo based application. So the example perhaps does not take into account all of the necessary factors.

I have also noticed that rather than the entire list of errors that Geoff was seeing in his initial problem statement, I am only seeing errors in the cache state for

GL_SCISSOR_BOX

and

GL_VIEWPORT

Please, open your own topic then, if the errors are different.