Exemple #1
1
void Context::setupDebugLogging(QOpenGLContext *context) {
    QOpenGLDebugLogger *logger = new QOpenGLDebugLogger(context);
    QObject::connect(logger, &QOpenGLDebugLogger::messageLogged, nullptr, [](const QOpenGLDebugMessage& message){
        Context::debugMessageHandler(message);
    });
    if (logger->initialize()) {
        logger->enableMessages();
        logger->startLogging(QOpenGLDebugLogger::SynchronousLogging);
    } else {
        qCWarning(glLogging) <<  "OpenGL context does not support debugging";
    }
}
Exemple #2
0
void Window::sync()
{
    QMutexLocker lock(&m_mutex);

    if (!m_terrain) {
        m_terrain = new Terrain;
        m_timer.start();

        QOpenGLDebugLogger *logger = new QOpenGLDebugLogger;
        logger->initialize();
        connect(logger, &QOpenGLDebugLogger::messageLogged, [](const QOpenGLDebugMessage &debugMessage) {
            qDebug() << debugMessage.message();
        });
        logger->startLogging(QOpenGLDebugLogger::SynchronousLogging);

        m_terrain->init();

        qreal aspect = qreal(size().width()) / qreal(size().height());
        const qreal zNear = 1., zFar = 7000.0, fov = 60.0;
        m_projection.perspective(fov, aspect, zNear, zFar);

        m_camera.distance = 4800;
//         m_camera.orientation = QQuaternion(0.354394, -0.24355, 0.825291, -0.366037);
//         m_camera.rotation = QQuaternion(0.593273, 0.507288, 0.114765, -0.614423);
//         m_camera.rotation = QQuaternion(0, 0, 1, 45);

        glClearColor(1, 1, 1, 1);
    }

    if (m_generate) {
        m_terrain->generateMap(m_mapSeed);
        m_needsUpdate = true;
        m_generate = false;
    }

    updateView();

    m_frameTime = m_timer.restart();

    m_times[m_curTimeId] = m_frameTime;
    if (++m_curTimeId >= 20) {
        m_curTimeId = 0;
    }

    unsigned int totTime = 0;
    for (unsigned int t: m_times) {
        totTime += t;
    }
    m_fps = 20 * 1000. / (double)totTime;
}