1// Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "offscreensurfacehelper_p.h"
5
6#include <Qt3DRender/private/abstractrenderer_p.h>
7#include <QtGui/qoffscreensurface.h>
8#include <QtGui/qsurfaceformat.h>
9#include <QtCore/qcoreapplication.h>
10#include <QtCore/qthread.h>
11
12QT_BEGIN_NAMESPACE
13
14namespace Qt3DRender {
15namespace Render {
16
17/*! \internal */
18OffscreenSurfaceHelper::OffscreenSurfaceHelper(AbstractRenderer *renderer,
19 QObject *parent)
20 : QObject(parent)
21 , m_renderer(renderer)
22 , m_offscreenSurface(nullptr)
23{
24 Q_ASSERT(renderer);
25}
26
27/*!
28 * \internal
29 * Called in context of main thread to create an offscreen surface
30 * which can later be made current with the Qt 3D OpenGL context to
31 * then allow graphics resources to be released cleanly.
32 */
33void OffscreenSurfaceHelper::createOffscreenSurface()
34{
35 Q_ASSERT(QThread::currentThread() == QCoreApplication::instance()->thread());
36 m_offscreenSurface = new QOffscreenSurface;
37 m_offscreenSurface->setParent(this);
38 m_offscreenSurface->setFormat(m_renderer->format());
39 m_offscreenSurface->setScreen(m_renderer->screen());
40 m_offscreenSurface->create();
41}
42
43} // namespace Render
44} // namespace Qt3DRender
45
46QT_END_NAMESPACE
47
48#include "moc_offscreensurfacehelper_p.cpp"
49

source code of qt3d/src/render/backend/offscreensurfacehelper.cpp