[Kstars-devel] Re: Planet textures with OpenGL

Akarsh Simha akarshsimha at gmail.com
Thu Apr 7 08:37:12 CEST 2011


> But here's an observation:
> 
> QGLContext::setDevice( QPaintDevice *pd ) is an internal function
> that's called on a QGLContext by a QGLWidget when the QGLWidget takes
> ownership of the QGLContext.
> 
> Now, QGLContext::setDevice() also resets the GL context if it was
> already valid, and creates a new one.
> 
> I read this somewhere on the internet (don't know how far it's true):
> 
> "If the GL context was destroyed, all textures become white. All
> textures have to be generated again."
> 
> This might be what's happening. To check if this is true, I put in an
> arbitrary reset() and create() on the context in the middle of the
> painting, and suddenly, all textures were replaced by colored (colored
> because we tint the white textures while painting them) squares.

Okay, I did a more controlled experiment.

After the QGLWidget was set up, I put in the following code into
QGLWidget::initializeGL():

TextureManager::getTexture( "globular-cluster" );
TextureManager::getContext()->reset();
TextureManager::getContext()->create();

And just as I expected, the globular cluster symbols did not render
correctly. The rest of the symbols rendered perfectly.

So reset() seems to be the culprit. Here's the code from QGLContext
that resets the context.

void QGLContext::setDevice(QPaintDevice *pDev)
{
    Q_D(QGLContext);
    if (isValid())
        reset();
    d->paintDevice = pDev;
    if (d->paintDevice && (d->paintDevice->devType() != QInternal::Widget
                           && d->paintDevice->devType() != QInternal::Pixmap
                           && d->paintDevice->devType() != QInternal::Pbuffer)) {
        qWarning("QGLContext: Unsupported paint device type");
    }
}

So when the paint device changes, the context is reset. So the point
of passing a QGLContext to the QGLWidget is more so that you can pass
QGLContext subclasses, like the documentation says.

Please correct me if I'm wrong here. My understanding is still fuzzy.

Regards
Akarsh


More information about the Kstars-devel mailing list