Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Qt5 crash (GLSL try to get uniforms)

Qt5 crash (GLSL try to get uniforms)

Scheduled Pinned Locked Moved Game Development
5 Posts 2 Posters 2.1k 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.
  • F Offline
    F Offline
    fsmoke
    wrote on last edited by
    #1

    I need to get uniform names from ogl shaders(for simple editor project). I did not want to parse shaders by hands, so I writed some tricky code :) In Qt4 this code works just fine, but in Qt5 appears crash at ctx.create(). This crash deep in Qt Gui library, somewhere in QWindow...

    @
    QGLFormat fmt = QGLFormat::defaultFormat();
    fmt.setVersion(2, 0);
    fmt.setProfile(QGLFormat::CompatibilityProfile);
    QWidget temp;
    QGLContext ctx(fmt, &temp);

    if (ctx.create())
    {
    ctx.makeCurrent();
    QGLFunctions fncs(&ctx);
    QGLShaderProgram prg(&ctx);

    bool needToLink = false;
    QGLShader vs(QGLShader::Vertex, &ctx);
    if (!vertex.isEmpty() && (needToLink |= vs.compileSourceCode(vertex)))
    prg.addShader(&vs);

    QGLShader fs(QGLShader::Fragment, &ctx);
    if (!fragment.isEmpty() && (needToLink |= fs.compileSourceCode(fragment)))
    prg.addShader(&fs);

    if (!needToLink)
    return;

    Q_ASSERT(prg.link());

    const QGLContext *context = QGLContext::currentContext();

    GLint total = -1;
    fncs.glGetProgramiv( prg.programId(), GL_ACTIVE_UNIFORMS, &total );
    for(GLint i = 0; i < total; ++i)
    {
    GLsizei nameLen = -1;
    GLint num = -1;
    GLenum type = GL_ZERO;
    char name[100];
    fncs.glGetActiveUniform( prg.programId(), i, sizeof(name)-1,
    &nameLen, &num, &type, name );
    name[nameLen] = 0;

    uniforms << glsl_var_type(shaderParamType(type), name, num);
    

    }
    }@

    What you think about it? May be it is bug in library. Or it's my bug. Anyway, how can I get uniform names - may be exists more beautiful solutions for this task?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Cmdr
      wrote on last edited by
      #2

      In the docs I don't see a constructor for QGLContext taking a pointer to a QWidget at all. Which Qt5 version are you using? Maybe it has been deprecated.

      Generally in recent Qt5 versions the QGL... family of classes has been superseded by QOpenGL... classes. Maybe you should give them a try. They are a bit harder to use right now, so you should probably stick to an example like this one: http://qt-project.org/doc/qt-5/qtgui-openglwindow-example.html

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fsmoke
        wrote on last edited by
        #3

        [quote author="Cmdr" date="1406813572"]In the docs I don't see a constructor for QGLContext taking a pointer to a QWidget at all. Which Qt5 version are you using? Maybe it has been deprecated.[/quote]

        this way using of QGLContext i found in sample - but it was long time ago

        from qgl.h of 4.8.6 and 5.3.1
        @
        class Q_OPENGL_EXPORT QGLContext
        {
        Q_DECLARE_PRIVATE(QGLContext)
        public:
        QGLContext(const QGLFormat& format, QPaintDevice device);*
        QGLContext(const QGLFormat& format);
        virtual ~QGLContext();
        .............
        .............
        @

        and this constructor does not marked as QT_DEPRECATED_SINCE

        [quote author="Cmdr" date="1406813572"]
        Generally in recent Qt5 versions the QGL... family of classes has been superseded by QOpenGL... classes. Maybe you should give them a try. They are a bit harder to use right now, so you should probably stick to an example like this one: http://qt-project.org/doc/qt-5/qtgui-openglwindow-example.html[/quote]

        Of course i will try this new classes, but i have many old sources with using of qgl.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Cmdr
          wrote on last edited by
          #4

          Another thing that I noticed: AFAIK QWidgets without a parent are initally invisible. Depending on your platform it might be impossible to create an OpenGL context for an invisible window. So you might try to call temp.show() prior to context initialization.

          Mixing QGL and QOpenGL should be no problem btw.

          1 Reply Last reply
          0
          • F Offline
            F Offline
            fsmoke
            wrote on last edited by
            #5

            [quote author="Cmdr" date="1406816772"]Another thing that I noticed: AFAIK QWidgets without a parent are initally invisible. Depending on your platform it might be impossible to create an OpenGL context for an invisible window. So you might try to call temp.show() prior to context initialization.
            [/quote]

            It works on 4.8.6 without show, and this code works on ~10 PCs with different hardware(Intel, nVidia, AMD) no problems. But on Qt5 this code causes crash on all machines. Problem in Qt5 it seems.

            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