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 | |
12 | QT_BEGIN_NAMESPACE |
13 | |
14 | namespace Qt3DRender { |
15 | namespace Render { |
16 | |
17 | /*! \internal */ |
18 | OffscreenSurfaceHelper::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 | */ |
33 | void 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 | |
46 | QT_END_NAMESPACE |
47 | |
48 | #include "moc_offscreensurfacehelper_p.cpp" |
49 |