PDA

View Full Version : QGraphicsView with OpenGL viewport keeps clearing the colorbuffer to white



Stukfruit
12th February 2008, 16:31
I'm using QGraphicsView with a viewport set to a QGLWidget. In addition to that, I'm overriding the virtual drawBackground, drawForeground and drawItems-methods from QGraphicsView to implement custom painting using OpenGL, as recommended.

I know I could also paint using the OpenGL painter engine, and I'm actually doing that as well, but I need to render things myself as well (specifically 3d items, but also 2d things that cannot be rendered using the Qt OpenGL painter engine because it requires acces to textures from fragment programs and some more random voodoo magic).

The QGLWidget, set as viewport for QGraphicsView, has its autoFillBackground property set to false. However, the colorbuffer (from the QGLWidget) is still getting cleared to white each frame.

Does someone know how I can make QGraphicsView, or the viewport widget (QGLWidget) stop clearing my colorbuffer each time? What I'm basically looking for is that Qt leaves my viewport background alone before and after those overridden drawing calls. When I render something in the viewport using OpenGL, I'd like it to stay there until the next frame update, unless I glClear it myself. Just like it would work when using a QGLWidget alone and no autoFillBackground.

I've done some research on where the white clear seems to be coming from as well. When I re-implemented the paintEvent, I noticed how the view was still going white at each frame update, even though I didn't do much more than calling those overridden methods (drawBackground, etc) which do not clear the view at all.

As far as I can see it's not just the color buffer that gets cleared to white, the depth buffer seems to be cleared automatically as well. Unfortunately, that's (again) not what I'm looking for. I would like to have full control over it between frame updates without having Qt clear it for me.

However, after a few days of searching around in the Qt source code, I really can't find anything that would do something like this. There's no background color, there's no background cache, there's simply nothing, but it keeps clearing the background...

Thanks for any suggestions and/or help :)

wysota
12th February 2008, 18:33
Try either setting the background role to transparent or set the widget's opaque paint event attribute to true.

Stukfruit
12th February 2008, 20:01
I've tried setting the background roles, but didn't seem to work. OpaquePaintEvent doesn't work either, nor does the NoSystemBackground hint.

An hour ago I also checked using gDEbugger and QOpenGLPaintEngine::begin(..) seems to be the method that does the clearing to <1.0, 1.0, 1.0, 1.0>.

Guess I'll be browsing the Qt code tonight, I want to know why it's so stubborn :)

Stukfruit
12th February 2008, 21:17
All right, fixed :)

I needed to set autoFillBackground to false. I did that, but I did it using the QGraphicsView::setupViewport(..)-method. Unfortunately, it's not emitted after setting a new viewport in my Qt-snapshot from 18/01/08, while it should be according to the documentation. So that means the autoFillBackground was still on, even though I told it to be off.

That's my fault for wanting to be on the bleeding edge, I guess :)