Better_Software_Header_MobileBetter_Software_Header_Web

Find what you need - explore our website and developer resources

OpenGL in Qt 5.1 – Part 3

void Scene::initialize()
{
    // Create a timer query object
    m_timeMonitor = new QOpenGLTimeMonitor( this );
    m_timeMonitor->setSampleCount( 5 );
    if ( !m_timeMonitor->create() )
        qWarning() << "Failed to create timer query object";

    // Generate some names for the various stages of rendering
    m_renderStages << "Clear Buffer" << "VAO Binding"
                   << "Shader Program Binding" << "Drawing";
}

void Scene::render()
{
    // Start the timer query
    m_timeMonitor->recordSample();

    // Do some rendering
    m_funcs->glClear( GL_COLOR_BUFFER_BIT );
    m_timeMonitor->recordSample();
    m_vao.bind();
    m_timeMonitor->recordSample();
    m_shaderProgram.bind();
    m_timeMonitor->recordSample();
    m_funcs->glDrawArrays( GL_TRIANGLES, 0, 3 );

    // End the timer query
    m_timeMonitor->recordSample();

    // Block until the results are available
    QVector<GLuint64> timeSamples = m_timeMonitor->waitForSamples();
    qDebug() << "timeSamples =" << timeSamples;

    QVector<GLuint64> intervals = m_timeMonitor->waitForIntervals();
    for ( int i = 0; i <= intervals.count(); ++i )
        qDebug() << i << m_renderStages.at( i )
                 << double( intervals.at( i ) ) / 1.0e6 << "msecs";

    // Clear the query results ready for the next frame
    m_timeMonitor->reset();
}
timeSamples = QVector(5850713788736, 5850713794176, 5850713794848, 5850713795552, 5850713801952)
 0 "Clear Buffer" 0.00544 msecs
 1 "VAO Binding" 0.000672 msecs
 2 "Shader Program Binding" 0.000704 msecs
 3 "Drawing" 0.0064 msecs

About KDAB


10 Comments

18 - Mar - 2013

Tim Angus

18 - Mar - 2013

Sean Harmer

18 - Mar - 2013

Tim Angus

18 - Mar - 2013

Sean Harmer

10 - Apr - 2013

HGH

10 - Apr - 2013

Sean Harmer

27 - May - 2013

Tim Angus

27 - May - 2013

Tim Angus

11 - Jun - 2013

Sean Harmer

14 - Jun - 2013

Tim Angus

SeanHarmer

Sean Harmer

Managing Director KDAB UK