| 1 | /**************************************************************************** |
|---|---|
| 2 | ** |
| 3 | ** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt3D module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #include "renderqueue_p.h" |
| 41 | #include <renderview_p.h> |
| 42 | #include <QThread> |
| 43 | |
| 44 | QT_BEGIN_NAMESPACE |
| 45 | |
| 46 | namespace Qt3DRender { |
| 47 | |
| 48 | namespace Render { |
| 49 | |
| 50 | namespace OpenGL { |
| 51 | |
| 52 | RenderQueue::RenderQueue() |
| 53 | : m_noRender(false) |
| 54 | , m_wasReset(true) |
| 55 | , m_targetRenderViewCount(0) |
| 56 | , m_currentRenderViewCount(0) |
| 57 | , m_currentWorkQueue(1) |
| 58 | { |
| 59 | } |
| 60 | |
| 61 | int RenderQueue::currentRenderViewCount() const |
| 62 | { |
| 63 | return m_currentRenderViewCount; |
| 64 | } |
| 65 | |
| 66 | /* |
| 67 | * In case the framegraph changed or when the current number of render queue |
| 68 | * needs to be reset. |
| 69 | */ |
| 70 | void RenderQueue::reset() |
| 71 | { |
| 72 | m_currentRenderViewCount = 0; |
| 73 | m_targetRenderViewCount = 0; |
| 74 | m_currentWorkQueue.clear(); |
| 75 | m_noRender = false; |
| 76 | m_wasReset = true; |
| 77 | } |
| 78 | |
| 79 | void RenderQueue::setNoRender() |
| 80 | { |
| 81 | Q_ASSERT(m_targetRenderViewCount == 0); |
| 82 | m_noRender = true; |
| 83 | } |
| 84 | |
| 85 | /* |
| 86 | * Queue up a RenderView for the frame being built. |
| 87 | * Thread safe as this is called from the renderer which is locked. |
| 88 | * Returns true if the renderView is complete |
| 89 | */ |
| 90 | bool RenderQueue::queueRenderView(RenderView *renderView, uint submissionOrderIndex) |
| 91 | { |
| 92 | Q_ASSERT(!m_noRender); |
| 93 | m_currentWorkQueue[submissionOrderIndex] = renderView; |
| 94 | ++m_currentRenderViewCount; |
| 95 | Q_ASSERT(m_currentRenderViewCount <= m_targetRenderViewCount); |
| 96 | return isFrameQueueComplete(); |
| 97 | } |
| 98 | |
| 99 | /* |
| 100 | * Called by the Rendering Thread to retrieve the a frame queue to render. |
| 101 | * A call to reset is required after rendering of the frame. Otherwise under some |
| 102 | * conditions the current but then invalidated frame queue could be reused. |
| 103 | */ |
| 104 | QVector<RenderView *> RenderQueue::nextFrameQueue() |
| 105 | { |
| 106 | return m_currentWorkQueue; |
| 107 | } |
| 108 | |
| 109 | /* |
| 110 | * Sets the number \a targetRenderViewCount of RenderView objects that make up a frame. |
| 111 | */ |
| 112 | void RenderQueue::setTargetRenderViewCount(int targetRenderViewCount) |
| 113 | { |
| 114 | Q_ASSERT(!m_noRender); |
| 115 | m_targetRenderViewCount = targetRenderViewCount; |
| 116 | m_currentWorkQueue.resize(asize: targetRenderViewCount); |
| 117 | m_wasReset = false; |
| 118 | } |
| 119 | |
| 120 | /* |
| 121 | * Returns true if all the RenderView objects making up the current frame have been queued. |
| 122 | * Returns false otherwise. |
| 123 | * \note a frameQueue or size 0 is considered incomplete. |
| 124 | */ |
| 125 | bool RenderQueue::isFrameQueueComplete() const |
| 126 | { |
| 127 | return (m_noRender |
| 128 | || (m_targetRenderViewCount > 0 && m_targetRenderViewCount == m_currentRenderViewCount)); |
| 129 | } |
| 130 | |
| 131 | } // namespace OpenGL |
| 132 | |
| 133 | } // namespace Render |
| 134 | |
| 135 | } // namespace Qt3DRender |
| 136 | |
| 137 | QT_END_NAMESPACE |
| 138 |
