QOpenGLTexture -- allocateStorage and setData



  • I'm working with Qt 5.5 OpenGL wrapper classes. Specifically trying to get QOpenGLTexture working. Here I am creating a 1x1 2D white texture for masking purposes. This works:

    void Renderer::initTextures()
    {    
        QImage white(1, 1, QImage::Format_RGBA8888);
        white.fill(Qt::white);
        m_whiteTexture.reset(new QOpenGLTexture(QOpenGLTexture::Target2D));
        m_whiteTexture->setSize(1, 1);
        m_whiteTexture->setData(white);
        //m_whiteTexture->allocateStorage(QOpenGLTexture::RGBA, QOpenGLTexture::UInt32);
        //m_whiteTexture->setData(QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, white.bits());
    
        // Print any errors
        QList<QOpenGLDebugMessage> messages = m_logger->loggedMessages();
        if (messages.size())
        {
            qDebug() << "Start of texture errors";
            foreach (const QOpenGLDebugMessage &message, messages)
                qDebug() << message;
            qDebug() << "End of texture errors";
        }
    }
    

    However I am now trying to do two things:

    1. Use allocate + setData sequence as separate commands (the commented out lines), e.g.
    m_whiteTexture->allocateStorage(QOpenGLTexture::RGBA, QOpenGLTexture::UInt32);
    m_whiteTexture->setData(QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, white.bits());
    

    for the purpose of more complicated rendering later where I just update part of the data and not reallocate. Related to this is (2) where I want to move to Target2DArray and push/pop textures in this array.

    1. Create a Target2DArray texture and populate layers using QImages. Eventually I will be pushing/popping textures up to some max size available on the hardware. Regarding (1), I get these errors from QOpenGLDebugMessage logger:
    Start of texture errors
    QOpenGLDebugMessage("APISource", 1280, "Error has been generated. GL error GL_INVALID_ENUM in TextureImage2DEXT: (ID: 2663136273) non-integer <format> 0 has been provided.", "HighSeverity", "ErrorType")
    QOpenGLDebugMessage("APISource", 1280, "Error has been generated. GL error GL_INVALID_ENUM in TextureImage2DEXT: (ID: 1978056088) Generic error", "HighSeverity", "ErrorType")
    QOpenGLDebugMessage("APISource", 1281, "Error has been generated. GL error GL_INVALID_VALUE in TextureImage2DEXT: (ID: 1978056088) Generic error", "HighSeverity", "ErrorType")
    QOpenGLDebugMessage("APISource", 1281, "Error has been generated. GL error GL_INVALID_VALUE in TextureSubImage2DEXT: (ID: 1163869712) Generic error", "HighSeverity", "ErrorType")
    End of texture errors
    

    My mask works with the original code, but I can't get it to work in either (1) and (2) scenarios. For (2) I change the target to Target2DArray, change the size to include depth of 1, adjust my shaders to use vec3 texture coordinates and sampler3D for sampling, etc. I can post a more complete (2) example if that helps. I also don't understand these error codes and obviously difficult to debug on the GPU if that is what is going wrong. I've tried all sorts of PixelType and PixelFormat combinations.

    The other thing is I noticed the setData methods have been declared obsolete, leaving only the QImage setter available. How can I use this for Target2DArray? How can I adjust just some of the data now?

    Thanks!

    Cross-posted with SO: https://stackoverflow.com/questions/33149607/qt-5-5-qopengltexture-copying-data-issue


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.