All my shader uniforms are reporting back -1 on their openGL location.



  • I have the following code that prepares my openGL shaders:

    @GPUShaderOGL::GPUShaderOGL(const QString &_name, BotSource *_bot, const ShaderProto& _shaderproto)
    : GPUShader(_name, _bot, _shaderproto)
    {
    m_programOGL = new QOpenGLShaderProgram();
    if( !m_programOGL->addShaderFromSourceCode(QOpenGLShader::Vertex, _bot->vsh().toStdString().c_str()))
    {
    qDebug() << _bot->vsh_linenumbers();
    QString theLog = m_programOGL->log();
    qDebug() << theLog;
    qDebug() << "Failed to compile VERTEX program: " << m_name;
    Q_ASSERT(0);
    }

    QString fsh = _bot->fsh();
    if(!m_programOGL->addShaderFromSourceCode(QOpenGLShader::Fragment, fsh.toStdString().c_str())) {
    qDebug() << _bot->fsh_linenumbers();
    qDebug() << m_programOGL->log();
    qDebug() << "Failed to compile FRAGMENT program:" << m_name;
    Q_ASSERT(0);
    }

    if( !m_programOGL->link() )
    {
    qDebug() << m_programOGL->log();
    qDebug() << "Failed to link program:" << m_name;
    Q_ASSERT(0);
    }

    m_programOGL->bind();

    if( m_uniform ) {
    Uniform::UniformArray& uniforms = m_uniform->uniformlist();
    for( Uniform::UniformArray::iterator it=uniforms.begin(); it!=uniforms.end(); ++it )
    {
    Uniform::UniformEntry& uni = *it;
    uni.glLocation = m_programOGL->attributeLocation(uni.name);
    qDebug() << uni.name << " location: " << uni.glLocation;
    }
    }
    }
    @

    When I run this, all my uniforms are reporting back -1 on their uniforms. What am I missing here?



  • Hi,

    maybe you should try to call "uniformLocation()":http://qt-project.org/doc/qt-5/qopenglshaderprogram.html#uniformLocation for uniform variables.



  • Doh! You're awesome! That fixed it. I've been staring at this for a hour.


Log in to reply
 

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