Пример #1
0
CustomWindow::CustomWindow( QWindow *parent ) : QQuickWindow( parent ) {
    connect( this, &CustomWindow::vsyncChanged, this, &CustomWindow::vsyncChangedHandler );

    // Reinitalize the scene graph when the OpenGL context gets destroyed
    // Needed because only when the context gets recreated is the format read
    setPersistentOpenGLContext( false );
    setPersistentSceneGraph( false );

    // Grab window surface format as the OpenGL context will not be created yet
    QSurfaceFormat fmt = format();

#if defined( Q_OS_WIN )

    // Set buffering mode
    // Testing shows that on Windows, vsync stays on (swapBuffers() blocks) while single buffered
    // even when the swap interval is 0 and even while fullscreen! So, we have to turn on double buffering if we
    // want vsync to actually be off, but turn on single buffering while vsynced to avoid unnecessary additional latency
    fmt.setSwapBehavior( vsync ? QSurfaceFormat::SingleBuffer : QSurfaceFormat::DoubleBuffer );
    emit doubleBufferedChanged( fmt.swapBehavior() == QSurfaceFormat::DoubleBuffer );

#elif defined( Q_OS_MACX )

    fmt.setSwapBehavior( QSurfaceFormat::SingleBuffer );
    emit doubleBufferedChanged( fmt.swapBehavior() == QSurfaceFormat::DoubleBuffer );

    // For proper OS X fullscreen
    setFlags( flags() | Qt::WindowFullscreenButtonHint );

#endif

    // Enforce the default value for vsync
    fmt.setSwapInterval( vsync ? 1 : 0 );
    setFormat( fmt );

}
Пример #2
0
SketchDeclarativeView::SketchDeclarativeView(const QUrl &url, QWindow *parent)
    : QQuickView(url, parent)
    , m_drawCanvas(false)
    , m_canvasWidget(0)
    , m_GLInitialized(false)
{
    // QT5TODO
//     setCacheMode(QGraphicsView::CacheNone);
//     setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
// 
//     setViewport(new QGLWidget(this));
// 
//     setAttribute(Qt::WA_AcceptTouchEvents);
//     setAttribute(Qt::WA_OpaquePaintEvent);
//     setAttribute(Qt::WA_NoSystemBackground);
//     viewport()->setAttribute(Qt::WA_OpaquePaintEvent);
//     viewport()->setAttribute(Qt::WA_NoSystemBackground);
//     viewport()->installEventFilter(this);

    // prevent image painted on background cleared again
    setClearBeforeRendering(false);
    // for now avoid having to deal with context being temporarily destroyed
    setPersistentOpenGLContext(true);

    connect(this, &QQuickWindow::sceneGraphInitialized, this, &SketchDeclarativeView::initializeImageRenderer, Qt::DirectConnection);
    connect(this, &QQuickWindow::sceneGraphInvalidated, this, &SketchDeclarativeView::invalidateImageRenderer, Qt::DirectConnection);
    connect(this, &QQuickWindow::beforeSynchronizing, this, &SketchDeclarativeView::synchronizeImageRenderer, Qt::DirectConnection);
    connect(this, &QQuickWindow::beforeRendering, this, &SketchDeclarativeView::renderImageOnBackground, Qt::DirectConnection);
}
Пример #3
0
Window::Window()
      : QQuickView()
      , m_terrain(nullptr)
      , m_mouseDown(false)
      , m_speed(0.01)
      , m_needsUpdate(true)
      , m_generate(false)
      , m_paused(false)
      , m_curTimeId(0)
{
    updateUi();
    rootContext()->setContextProperty("Game", this);

    setSurfaceType(QWindow::OpenGLSurface);
    setClearBeforeRendering(false);
    setPersistentOpenGLContext(true);
    setResizeMode(QQuickView::SizeRootObjectToView);
    setSource(QUrl::fromLocalFile(FileFinder::findFile(FileFinder::Type::Qml, "ui.qml")));

    QSurfaceFormat format = requestedFormat();
    format.setProfile(QSurfaceFormat::CoreProfile);
    format.setMajorVersion(3);
    format.setMinorVersion(3);
    format.setDepthBufferSize(24);
    format.setOption(QSurfaceFormat::DebugContext);
    setFormat(format);

    resize(1024, 768);

    connect(this, &QQuickWindow::beforeRendering, this, &Window::renderNow, Qt::DirectConnection);
    connect(this, &QQuickWindow::beforeSynchronizing, this, &Window::sync, Qt::DirectConnection);
    connect(this, &QQuickWindow::afterRendering, this, &Window::updateUi);
    connect(this, &QQuickWindow::afterRendering, this, &Window::update);

    show();
}