March 24, 2012

Sfiet_Konstantin Sfiet_Konsta..
Lab Rat
29 posts

OpenGL and frame drop

 

Hi
I’m currently working on an application that have to display pictures very quickly (1/60 s). I need to have 60 fps so I decided to use a QGLWidget and enabled VSync with

  1. format.setSwapInterval(1);

But currently there are two strange problems.
1. I have on my laptop (Lenovo X200 – Intel X4500 HD) 30FPS instead of 60. I can get 60 FPS with

  1. format.setSwapInterval(0);

2. More important. I sometimes have “frame drop”. When I need to display a picture for the 1/60s (ie on 1 frame), sometimes it is not displayed at all. Is there any way to force drawing it or at least detect this drop ?

My testing code :

  1. MainWindow::MainWindow(QWidget *parent) :
  2.     QMainWindow(parent),
  3.     ui(new Ui::MainWindow)
  4. {
  5.     ui->setupUi(this);
  6.  
  7.  
  8.     QGLWidget *widget = new QGLWidget(this);
  9.     QGLFormat format = QGLFormat();
  10.     format.setSwapInterval(0);
  11.     widget->setFormat(format);
  12.  
  13.     ui->graphicsView->setViewport(widget);
  14.  
  15.     m_scene = new QGraphicsScene(this);
  16.     m_scene->setBackgroundBrush(Qt::black);
  17.  
  18.     ui->graphicsView->setScene(m_scene);
  19.  
  20.     m_mainItem = m_scene->addRect(0, 0, 100, 100, QPen(), QBrush(Qt::blue));
  21.     m_subItem = m_scene->addRect(0, 0, 100, 100, QPen(), QBrush(Qt::red));
  22.     m_subItem->setVisible(false);
  23.  
  24.     QTimer *timer = new QTimer(this);
  25.     timer->setInterval(0);
  26.     timer->start();
  27.  
  28.     connect(timer, SIGNAL(timeout()), this, SLOT(slotTimeout()));
  29. }
  30.  
  31. MainWindow::~MainWindow()
  32. {
  33.     delete ui;
  34. }
  35.  
  36. void MainWindow::slotTimeout()
  37. {
  38.     // Redraw
  39.     m_counter ++;
  40.  
  41.     m_subItem->setVisible(m_counter % 60 == 0);
  42.     ui->graphicsView->viewport()->update();
  43. }

0 replies

 
  ‹‹ Qt- Web service Requests      qTouchEvent propagation. ››

You must log in to post a reply. Not a member yet? Register here!