Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Changing pixeldata during runtime with QOpenGLTexture



  • Hi,

    What would be the best practice of changing pixel data of a bound texture using the new QOpenGLTexture?
    I'm doing runtime calculations (by CPU) that changes the pixel values of a texture already bound and used by a shader. My current method feels a little wrong, but there's not much information on QOpenGLTexture at the moment, so I'm really not sure? Anyway, I do something like this:

    @// Init step:
    // create new QImage and create a QOpenGLTexture by passing the QImage to it.
    QImage imageMap = QImage(200, 200, QImage::Format_RGB32);
    imageMap.fill(QColor(255, 255, 255);
    QOpenGLTexture* textureMap = new QOpenGLTexture(imageMap, QOpenGLTexture::GenerateMipMaps);

    // Frame Update step:
    // Perform calculations that changes pixeldata values of QImage and update the bound texture.
    doSomePixelCalculations(imageMap);
    textureMap.setData(imageMap);@

    setData generates warnings but the result works as expected without issues. Warnings:
    @// QOpenGLTexture::setFormat(): Cannot change format once storage has been allocated
    // Cannot resize a texture that already has storage allocated.
    // To do so, destroy() the texture and then create() and setSize()
    // Cannot set mip levels on a texture that already has storage allocated.
    // To do so, destroy() the texture and then create() and setMipLevels()@

    I'm really not changing size of format. Should I do this differently?


Log in to reply