| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2017 The Qt Company Ltd. | 
| 4 | ** Contact: http://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the Qt3D module of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:LGPL3$ | 
| 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 http://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free | 
| 28 | ** Software Foundation and appearing in the file LICENSE.GPL included in | 
| 29 | ** the packaging of this file. Please review the following information to | 
| 30 | ** ensure the GNU General Public License version 2.0 requirements will be | 
| 31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. | 
| 32 | ** | 
| 33 | ** $QT_END_LICENSE$ | 
| 34 | ** | 
| 35 | ****************************************************************************/ | 
| 36 |  | 
| 37 | #include "resourceaccessor_p.h" | 
| 38 |  | 
| 39 | #include <Qt3DRender/qrendertargetoutput.h> | 
| 40 |  | 
| 41 | #include <private/qrendertargetoutput_p.h> | 
| 42 | #include <private/nodemanagers_p.h> | 
| 43 | #include <private/rendertargetoutput_p.h> | 
| 44 | #include <private/managers_p.h> | 
| 45 |  | 
| 46 | #include <Qt3DRender/qt3drender-config.h> | 
| 47 | #include <QtCore/qmutex.h> | 
| 48 |  | 
| 49 | QT_BEGIN_NAMESPACE | 
| 50 |  | 
| 51 | namespace Qt3DRender { | 
| 52 | namespace Render { | 
| 53 |  | 
| 54 | RenderBackendResourceAccessor::~RenderBackendResourceAccessor() | 
| 55 | { | 
| 56 |  | 
| 57 | } | 
| 58 |  | 
| 59 | ResourceAccessor::ResourceAccessor(AbstractRenderer *renderer, NodeManagers *mgr) | 
| 60 |     : m_renderer(renderer) | 
| 61 |     , m_textureManager(mgr->textureManager()) | 
| 62 |     , m_attachmentManager(mgr->attachmentManager()) | 
| 63 |     , m_entityManager(mgr->renderNodesManager()) | 
| 64 | { | 
| 65 |  | 
| 66 | } | 
| 67 |  | 
| 68 | // called by render plugins from arbitrary thread | 
| 69 | bool ResourceAccessor::accessResource(ResourceType type, | 
| 70 |                                       Qt3DCore::QNodeId nodeId, | 
| 71 |                                       void **handle, | 
| 72 |                                       QMutex **lock) | 
| 73 | { | 
| 74 |     switch (type) { | 
| 75 |  | 
| 76 |     // This is purely made so that Scene2D works, this should be completely | 
| 77 |     // redesigned to avoid introducing this kind of coupling and reliance on | 
| 78 |     // OpenGL | 
| 79 |     case RenderBackendResourceAccessor::OGLTextureWrite: | 
| 80 |         Q_FALLTHROUGH(); | 
| 81 |     case RenderBackendResourceAccessor::OGLTextureRead: | 
| 82 |     { | 
| 83 |         if (m_renderer->api() != API::OpenGL) { | 
| 84 |             qWarning() << "Renderer plugin is not compatible with Scene2D" ; | 
| 85 |             return false; | 
| 86 |         } | 
| 87 |         return m_renderer->accessOpenGLTexture(nodeId, | 
| 88 |                                                texture: reinterpret_cast<QOpenGLTexture **>(handle), | 
| 89 |                                                lock, | 
| 90 |                                                readonly: type == RenderBackendResourceAccessor::OGLTextureRead); | 
| 91 |     } | 
| 92 |  | 
| 93 |     case RenderBackendResourceAccessor::OutputAttachment: { | 
| 94 |         RenderTargetOutput *output = m_attachmentManager->lookupResource(id: nodeId); | 
| 95 |         if (output) { | 
| 96 |             Attachment **attachmentData = reinterpret_cast<Attachment **>(handle); | 
| 97 |             *attachmentData = output->attachment(); | 
| 98 |             return true; | 
| 99 |         } | 
| 100 |         break; | 
| 101 |     } | 
| 102 |  | 
| 103 |     case RenderBackendResourceAccessor::EntityHandle: { | 
| 104 |         Entity *entity = m_entityManager->lookupResource(id: nodeId); | 
| 105 |         if (entity) { | 
| 106 |             Entity **pEntity = reinterpret_cast<Entity **>(handle); | 
| 107 |             *pEntity = entity; | 
| 108 |             return true; | 
| 109 |         } | 
| 110 |         break; | 
| 111 |     } | 
| 112 |  | 
| 113 |     default: | 
| 114 |         break; | 
| 115 |     } | 
| 116 |     return false; | 
| 117 | } | 
| 118 |  | 
| 119 | } // namespace Render | 
| 120 | } // namespace Qt3DRender | 
| 121 |  | 
| 122 | QT_END_NAMESPACE | 
| 123 |  |