Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QOpenGLFunctions moved to another class, shader subroutine stop working
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 993 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    glararan
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved