Results 1 to 16 of 16

Thread: how to make updateGL() realtime in QT

  1. #1
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default how to make updateGL() realtime in QT

    I wonder if calling updateGL() in fixed timer intervals may slow down the rendering process. So, I want to try making the render real time. I do not the function to make it execute automatically. Anyone knows that?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to make updateGL() realtime in QT

    Quote Originally Posted by saman_artorious View Post
    I wonder if calling updateGL() in fixed timer intervals may slow down the rendering process.
    No, why would it?

    So, I want to try making the render real time.
    real time or Real Time?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: how to make updateGL() realtime in QT

    i added
    Qt Code:
    1. this->format().setSwapInterval(1);
    To copy to clipboard, switch view to plain text mode 
    in the constructor and
    swapbuffers()
    at the end of paintGL() function. but it had no effect. how to make it render 60fps?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to make updateGL() realtime in QT

    Quote Originally Posted by saman_artorious View Post
    i added
    Qt Code:
    1. this->format().setSwapInterval(1);
    To copy to clipboard, switch view to plain text mode 
    in the constructor and swapbuffers() at the end of paintGL() function. but it had no effect.
    Why would it have any effect? Did you read the docs for that method?

    how to make it render 60fps?
    Render less (or more efficiently) or buy faster hardware.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: how to make updateGL() realtime in QT

    why would render consume this much CPU ? I thought it was only handled by GPU.
    is there any way to optimize it?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to make updateGL() realtime in QT

    Quote Originally Posted by saman_artorious View Post
    why would render consume this much CPU ? I thought it was only handled by GPU.
    Before data can be rendered by the GPU it has to be computed and transfered there. How do you know that rendering consumes much of your CPU power?

    is there any way to optimize it?
    Probably yes. All depends what your drawing code looks like.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: how to make updateGL() realtime in QT

    well, I monitor CPU usage with htop in linux. render rate and CPU usage have a direct relation.
    if I render less, it drops. but I don't want to do that. it's a display program, imagine a circle, each degree containing 1000 or 2000 pixels (small rectangles), total 360 * 1000 pixels on the screen.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to make updateGL() realtime in QT

    Quote Originally Posted by saman_artorious View Post
    well, I monitor CPU usage with htop in linux. render rate and CPU usage have a direct relation.
    Such measurements are unreliable.

    if I render less, it drops. but I don't want to do that. it's a display program, imagine a circle, each degree containing 1000 or 2000 pixels (small rectangles), total 360 * 1000 pixels on the screen.
    Show your rendering code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: how to make updateGL() realtime in QT

    Quote Originally Posted by wysota View Post
    Such measurements are unreliable.
    Then how could I monitor a reliable one?

    Qt Code:
    1. void GlWidget::paintGL()
    2. {
    3. glClearColor(0, 0, 0, 1.0f);
    4. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    5.  
    6. QMatrix4x4 vMatrix;
    7.  
    8. float sg = pow(2, camera.zoom);
    9.  
    10. float sx = 256.0 / width();
    11. float sy = 256.0 / height();
    12.  
    13. vMatrix.setToIdentity();
    14.  
    15. vMatrix.scale(sx * sg, sy * sg, 1);
    16. vMatrix.translate(-2 * camera.panX + 1, 2 * camera.panY - 1, 0);
    17.  
    18. shaderProgramPixels.bind();
    19.  
    20. shaderProgramPixels.setUniformValue("mvpMatrix", vMatrix);
    21.  
    22. ppi->render(&shaderProgramPixels);
    23.  
    24.  
    25. shaderProgramPixels.disableAttributeArray("vertex");
    26. shaderProgramPixels.disableAttributeArray("color" );
    27. shaderProgramPixels.release();
    28.  
    29. shaderProgram.bind();
    30.  
    31. shaderProgram.setUniformValue("mvpMatrix", vMatrix);
    32.  
    33. ppi->RenderRange(&shaderProgram);
    34.  
    35. RenderLines();
    36.  
    37. shaderProgram.disableAttributeArray("vertex");
    38. shaderProgram.disableAttributeArray("color" );
    39. shaderProgram.release();
    40. }
    To copy to clipboard, switch view to plain text mode 

    Vertices are created at initialization once and then only used. All render functions inside paint do the following:
    Qt Code:
    1. void PlanPositionIndicator::render(QGLShaderProgram* shaderProgram)
    2. {
    3. // qDebug() << vertices.size();
    4.  
    5. shaderProgram->setAttributeArray("vertex", vertices.constData());
    6. shaderProgram->enableAttributeArray("vertex");
    7. shaderProgram->setAttributeArray("color", GL_FLOAT,colors,1);
    8. // shaderProgram->setAttributeArray("color", GL_FLOAT,colors.data(),1);
    9. shaderProgram->enableAttributeArray("color");
    10.  
    11. glEnable (GL_BLEND);
    12. glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    13.  
    14. glDrawArrays(GL_TRIANGLES, 0, vertices.size());
    15. }
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to make updateGL() realtime in QT

    Quote Originally Posted by saman_artorious View Post
    Then how could I monitor a reliable one?
    That's a very good question. Probably using some dedicated instrumentation tool.

    Vertices are created at initialization once and then only used. All render functions inside paint do the following:
    Qt Code:
    1. void PlanPositionIndicator::render(QGLShaderProgram* shaderProgram)
    2. {
    3. // qDebug() << vertices.size();
    4.  
    5. shaderProgram->setAttributeArray("vertex", vertices.constData());
    6. shaderProgram->enableAttributeArray("vertex");
    7. shaderProgram->setAttributeArray("color", GL_FLOAT,colors,1);
    8. // shaderProgram->setAttributeArray("color", GL_FLOAT,colors.data(),1);
    9. shaderProgram->enableAttributeArray("color");
    10.  
    11. glEnable (GL_BLEND);
    12. glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    13.  
    14. glDrawArrays(GL_TRIANGLES, 0, vertices.size());
    15. }
    To copy to clipboard, switch view to plain text mode 
    What is "vertices"? Is it a vertex buffer? Did you tell OpenGL that these values are static?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: how to make updateGL() realtime in QT

    Yes, it is a vertex buffer.
    QVector<QVector3D> vertices;
    Did you tell OpenGL that these values are static?
    If by this you mean VBO, in which we allocate these vertices and colors inside GPU, No, I haven't yet done it with VBO.
    But, I want to try it now, I hope it reduces CPU usage.

    by the way, I know how to use VBO with standard C++ opengl and not Qt, do you have any samples in Qt for this?

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to make updateGL() realtime in QT

    Quote Originally Posted by saman_artorious View Post
    Yes, it is a vertex buffer.
    Seems more like a QVector.

    If by this you mean VBO, in which we allocate these vertices and colors inside GPU, No, I haven't yet done it with VBO.
    This implies that you copy the vertices again and again to the GPU upon rendering every frame. If the list of vertices is fixed, that's a pure waste of CPU power.

    by the way, I know how to use VBO with standard C++ opengl and not Qt, do you have any samples in Qt for this?
    There are examples in the docs. The usage is similar, only that the API is wrapped into Qt calls.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: how to make updateGL() realtime in QT

    by the way do you know

    how to bind two vertex buffers into different slots (slot0 and slot1),

    I want something like this in OpenGL(QT):

    Qt Code:
    1. QGLBuffer VB0, VB1;
    2.  
    3. VB0.bind(0);
    4. VB1.bind(1);
    To copy to clipboard, switch view to plain text mode 

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to make updateGL() realtime in QT

    If I understand you correctly then you need to bind the first buffer, then use a call similar to QOpenGLShaderProgram::setAttributeBuffer() and then repeat for the other buffer (bind and assign).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #15
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: how to make updateGL() realtime in QT

    Does etAttributeBuffer accept the QGLBuffer parameter?!

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to make updateGL() realtime in QT

    No, it uses the currently bound buffer.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. updateGL() Help
    By Halpha in forum Newbie
    Replies: 1
    Last Post: 16th April 2013, 17:31
  2. Not able to use updateGL()
    By chintu in forum Qt Programming
    Replies: 2
    Last Post: 24th January 2011, 18:57
  3. update() & updateGL()
    By rick_st3 in forum Newbie
    Replies: 7
    Last Post: 23rd June 2008, 13:57
  4. QGLWidget::updateGL( )
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 2nd November 2006, 19:21
  5. QGLWidget updateGL()
    By Lele in forum Qt Programming
    Replies: 7
    Last Post: 30th May 2006, 15:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.