1 | // Copyright (C) 2017 The Qt Company Ltd. |
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 "resourceaccessor_p.h" |
5 | |
6 | #include <Qt3DRender/qrendertargetoutput.h> |
7 | |
8 | #include <private/qrendertargetoutput_p.h> |
9 | #include <private/nodemanagers_p.h> |
10 | #include <private/rendertargetoutput_p.h> |
11 | #include <private/managers_p.h> |
12 | |
13 | #include <QtCore/qmutex.h> |
14 | |
15 | QT_BEGIN_NAMESPACE |
16 | |
17 | namespace Qt3DRender { |
18 | namespace Render { |
19 | |
20 | RenderBackendResourceAccessor::~RenderBackendResourceAccessor() |
21 | { |
22 | |
23 | } |
24 | |
25 | ResourceAccessor::ResourceAccessor(AbstractRenderer *renderer, NodeManagers *mgr) |
26 | : m_renderer(renderer) |
27 | , m_textureManager(mgr->textureManager()) |
28 | , m_attachmentManager(mgr->attachmentManager()) |
29 | , m_entityManager(mgr->renderNodesManager()) |
30 | { |
31 | |
32 | } |
33 | |
34 | // called by render plugins from arbitrary thread |
35 | bool ResourceAccessor::accessResource(ResourceType type, |
36 | Qt3DCore::QNodeId nodeId, |
37 | void **handle, |
38 | QMutex **lock) |
39 | { |
40 | switch (type) { |
41 | |
42 | // This is purely made so that Scene2D works, this should be completely |
43 | // redesigned to avoid introducing this kind of coupling and reliance on |
44 | // OpenGL |
45 | case RenderBackendResourceAccessor::OGLTextureWrite: |
46 | Q_FALLTHROUGH(); |
47 | case RenderBackendResourceAccessor::OGLTextureRead: |
48 | { |
49 | if (m_renderer->api() != API::OpenGL) { |
50 | qWarning() << "Renderer plugin is not compatible with Scene2D" ; |
51 | return false; |
52 | } |
53 | return m_renderer->accessOpenGLTexture(nodeId, |
54 | texture: reinterpret_cast<QOpenGLTexture **>(handle), |
55 | lock, |
56 | readonly: type == RenderBackendResourceAccessor::OGLTextureRead); |
57 | } |
58 | |
59 | case RenderBackendResourceAccessor::OutputAttachment: { |
60 | RenderTargetOutput *output = m_attachmentManager->lookupResource(id: nodeId); |
61 | if (output) { |
62 | Attachment **attachmentData = reinterpret_cast<Attachment **>(handle); |
63 | *attachmentData = output->attachment(); |
64 | return true; |
65 | } |
66 | break; |
67 | } |
68 | |
69 | case RenderBackendResourceAccessor::EntityHandle: { |
70 | Entity *entity = m_entityManager->lookupResource(id: nodeId); |
71 | if (entity) { |
72 | Entity **pEntity = reinterpret_cast<Entity **>(handle); |
73 | *pEntity = entity; |
74 | return true; |
75 | } |
76 | break; |
77 | } |
78 | |
79 | default: |
80 | break; |
81 | } |
82 | return false; |
83 | } |
84 | |
85 | } // namespace Render |
86 | } // namespace Qt3DRender |
87 | |
88 | QT_END_NAMESPACE |
89 | |