PDA

View Full Version : Problems with clipping and vsync of OpenGL widget container



dropkickz
6th May 2015, 15:06
Hi all,

after updating my application from Qt 4.8 to Qt 5.4 I was facing problems with my QGLWidget. I got some strange white rectangles and painting problems on OS X (it is a multi-platform application and there were no problems on Windows). Since QGLWidget is deprecated I decided to change my implementation. Unfortunately I can't use the newly introduced QOpenGLWidget since I need full control over the buffer swap and rendering into an FBO is not an option right now. After reading some threads I finally chose to implement it the way it is explained in the OpenGL Window Example of Qt 5.4 (http://doc.qt.io/qt-5/qtgui-openglwindow-example.html). In short, QWindow with OpenGL surface and a QOpenGLContext. For getting a widget out of the window I am using QWidget::createWindowContainer. Everything works pretty good except two problems:

My OpenGL widget can have a fixed size. It is child of a layouting widget which is the central widget of my main window. The OpenGL widget is always put in the center of the layouting widget. I also have dock widgets to the left and right as well as toolbars. Now when resizing the the main window it can happen that the size of the central widget is smaller than the fixed size of my OpenGL render widget. In that case it is moved outside of the central widget area and should be covered by the toolbars and the dock widgets. But this is unfortunately not happening. It is always drawn on top of everything. This scenario was working with the old and now deprecated QGLWidget. I attached some screenshot which show the problem.
11162 11163 11164
The second problem is related to vsync. On my Mac it seems to work if I set the swap interval to zero in the surface format. However I am still limited to 60 fps which reflects my monitor refresh rate. With the QGLWidget I am getting around 200 fps with the same test scene. Is there anything else I need to take care of? However, on my Windows machine setting the swap interval to zero does not seem to have any impact at all. Vsync is always on.


Any help is highly appreciated. If necessary I can post the source code of my demo scene.

Thanks,
Marcus

dropkickz
11th May 2015, 14:14
UPDATE: Ok, I figured out that the use of QWidget::createWindowContainer has limitations regarding stacking order. I found a possible solution where the widget is inserted in a QMdiArea. This solved the clipping problem for Windows. Unfortunately on OS X I am now getting the the same problem as with QGLWidget. On application startup a white rectangle is drawn at the top left corner of my main window. After some research it found the cause for it: It is a hidden toolbar with a widget in it. If I do not hide the the toolbar (in my code), the white rectangle is gone. Also when I show the toolbar in my application, the white rectangle goes away and won't appear again. Another remark, my QGLWidget is child of a parent widget which again is the central widget of my application. If I directly use the QGLWidget as the central widget, the problem also does not occur.

To sum it up:

I have a QGLWidget with a parent QWidget as the central widget of my application.
I have a hidden tool bar with a widget in it.
When I start the application on OS X, a white rectangle appears at the top left corner of my application.
The rectangle goes away after showing the toolbar.
The problem does not occur if I do not hide the toolbar in my code or if I use the QGLWidget directly as the central widget.


Here is some simple demo code which shows the problem:


#include <QApplication>
#include <QMainWindow>
#include <QGLWidget>
#include <QToolBar>
#include <QMenuBar>
#include <QMenu>

int main(int argc, char *argv[])
{
//QCoreApplication::addLibraryPath("Qt/plugins");

QApplication app(argc, argv);

QMainWindow main;

main.setStyleSheet("background-color: black;");

QWidget *central = new QWidget(&main);
QGLWidget *gl = new QGLWidget(central);
main.setCentralWidget(central);

QWidget *w = new QWidget();
QToolBar *tb = new QToolBar("Test");
tb->addWidget(w);
tb->hide();

main.addToolBar(Qt::BottomToolBarArea, tb);

QMenu *m = main.menuBar()->addMenu("View");
m->addAction(tb->toggleViewAction());

main.show();

main.resize(800, 600);

return app.exec();
}


Unfortunately I can't upload an image of the problem because I currently always getting an error while trying to upload the file.

To me this looks like a bug in Qt or am I doing something wrong?

Thank,
Marcus