[SOLVED] QOpenGLFunctions moved to another class, shader subroutine stop working



  • Hi,

    As topic say I moved QOpenGLFunction from class called MapView(QGLWidget) to class World(QObject).

    I get same subroutine indexs, but when I'm calling:
    @world->getGLFunctions()->glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, &eDisplaySubroutines[eDisplay]);@

    Result in QGLWidget isn't, it using default Display subroutine in fragment shader, I'm not able to change it :(

    Code before:
    @// MapView constructor : eDisplaySubroutines(DisplayModeCount) /QVector/, eDisplay(TEXTURED) // index shadeTexturedAndLit, show correct
    // QStringList
    eDisplayNames << QStringLiteral("shadeSimpleWireFrame")
    << QStringLiteral("shadeTexturedAndLit")
    << QStringLiteral("shadeWorldTexturedWireframed")
    << QStringLiteral("shadeHidden");

    // MapView initializeGL
    this->makeCurrent();

    GLfuncs = GLcontext->versionFunctions<QOpenGLFunctions_4_0_Core>();
    
    if(!GLfuncs)
    {
        qFatal("Requires OpenGL >= 4.0");
        exit(1);
    }
    
    GLfuncs->initializeOpenGLFunctions();
    // ....
    // Get subroutine indices
    for(int i = 0; i < DisplayModeCount; ++i)
        eDisplaySubroutines[i] = GLfuncs->glGetSubroutineIndex(shader->programId(), GL_FRAGMENT_SHADER, eDisplayNames.at(i).toLatin1());
    

    // MapView paintGL
    this->makeCurrent();

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    material->bind();
    
    QOpenGLShaderProgramPtr shader = material->shader();
    shader->bind();
    
    // Set the fragment shader display mode subroutine
    GLfuncs->glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, &eDisplaySubroutines[eDisplay]);
    

    @

    Code after:
    @// MapView constructor : eDisplaySubroutines(world->DisplayModeCount) /QVector/, eDisplay(world->TEXTURED) // eDiplay is moved to world!!! index shadeTexturedAndLit, btw show wireframe in frag its default
    // QStringList
    eDisplayNames << QStringLiteral("shadeSimpleWireFrame")
    << QStringLiteral("shadeTexturedAndLit")
    << QStringLiteral("shadeWorldTexturedWireframed")
    << QStringLiteral("shadeHidden");

    // MapView initializeGL
    this->makeCurrent();

    // Initialize World
    world->initialize(GLcontext);
    // ....
    // Get subroutine indices
    for(int i = 0; i < world->DisplayModeCount; ++i)
        eDisplaySubroutines[i] = world->getGLFunctions()->glGetSubroutineIndex(shader->programId(), GL_FRAGMENT_SHADER, eDisplayNames.at(i).toLatin1());
    

    // MapView paintGL
    this->makeCurrent();

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    world->material->bind();
    
    QOpenGLShaderProgramPtr shader = world->material->shader();
    shader->bind();
    
    // Set the fragment shader display mode subroutine
    world->getGLFunctions()->glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, &eDisplaySubroutines[world->displayMode()]);
    

    // World initialize
    void World::initialize(QOpenGLContext* context)
    {
    GLfuncs = context->versionFunctions<QOpenGLFunctions_4_0_Core>();

    if(!GLfuncs)
    {
        qFatal("Requires OpenGL >= 4.0");
        exit(1);
    }
    
    GLfuncs->initializeOpenGLFunctions();
    
    // prepare Shaders
    material = MaterialPtr(new Material);
    material->setShaders(":/shaders/terraintessellation.vert",
                         ":/shaders/terraintessellation.tcs",
                         ":/shaders/terraintessellation.tes",
                         ":/shaders/terraintessellation.geom",
                         ":/shaders/terraintessellation.frag");
    

    // ...
    }

    // World getGLFunctions()
    QOpenGLFunctions_4_0_Core* getGLFunctions() { return GLfuncs; }
    @

    I don't see any trouble in code, but there must be. But what?

    Thanks

    SOLUTION: I needed that for MapTile class which was in array in World.. call it in MapTile body


Log in to reply
 

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