Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. QOpenGLFunctions_4_5_Core static variables
QtWS25 Last Chance

QOpenGLFunctions_4_5_Core static variables

Scheduled Pinned Locked Moved Solved Qt 6
4 Posts 3 Posters 146 Views
  • 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.
  • P Offline
    P Offline
    Pekoyo
    wrote on 23 Mar 2025, 03:54 last edited by
    #1

    Having a
    static QOpenGLFunctions_4_5_Core * GL;
    struct Viewport : QOpenGLWindow, protected QOpenGLFunctions_4_5_Core {
    Viewport() {
    GL = this;
    }
    }

    and maintaining a reference to

    attempting to assign anything to a static GLuint fails / goes out of scope.
    eg. creating a shader program or a VAO / VBO to a static variable the data is deleted instanly after being assigned.

    The purpose is to have many classes that each render a different kind of primitive but managing context is confusing and each class instance should use the same shaderprogram. is there a way to maintain OpenGL variables inside static variables?

    J 1 Reply Last reply 24 Mar 2025, 08:07
    0
    • P Pekoyo
      23 Mar 2025, 03:54

      Having a
      static QOpenGLFunctions_4_5_Core * GL;
      struct Viewport : QOpenGLWindow, protected QOpenGLFunctions_4_5_Core {
      Viewport() {
      GL = this;
      }
      }

      and maintaining a reference to

      attempting to assign anything to a static GLuint fails / goes out of scope.
      eg. creating a shader program or a VAO / VBO to a static variable the data is deleted instanly after being assigned.

      The purpose is to have many classes that each render a different kind of primitive but managing context is confusing and each class instance should use the same shaderprogram. is there a way to maintain OpenGL variables inside static variables?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 24 Mar 2025, 08:07 last edited by
      #2

      @Pekoyo said in QOpenGLFunctions_4_5_Core static variables:

      is there a way to maintain OpenGL variables inside static variables?

      You should rather use a common base class for all these classes where you put that GLuint variable.

      From your description it is also not clear how you're using that static variable.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • P Pekoyo has marked this topic as solved on 28 Mar 2025, 14:07
      • P Offline
        P Offline
        Pekoyo
        wrote on 28 Mar 2025, 14:09 last edited by
        #3

        My other solution was not as ideal but putting the OpenGL variables inside an unordered_map in the QOpenGlWidget and using a static pointer to the viewport

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 28 Mar 2025, 20:35 last edited by
          #4

          Hi,

          You realize that using all this static stuff is a really good start to a pretty nightmarish maintenance and debugging experience ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          4/4

          28 Mar 2025, 20:35

          • Login

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