VR-Engage  2.3
Loading...
Searching...
No Matches
DtQtQuickRenderer.h
Go to the documentation of this file.
1/*********************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*********************************************************************************/
5
6#pragma once
7
8//! \file DtQtQuickRenderer.h
9//! \ingroup vreQtQuickRenderer
10//! \brief Main singleton responsible for managing QML files in the VREngage system.
11//!
12//! This class manages QML files being rendered, QML files that need to be loaded,
13//! and all associated data. It provides the interface for loading, rendering, and
14//! interacting with QML-based user interfaces within the VREngage environment.
15
17
18#include "vreUtil/initializer.h"
19
20#include <vrvUtil/DtSignalConnectionManager.h>
21
22#include <vrvOsg/DtImguiDrawable.h>
23
24#include <osg/Geode>
25#include <osg/Texture2D>
26
27#include <QObject>
28
29
30class QObject;
31class QOpenGLContext;
32class QWindow;
33class QQuickWindow;
34class QQmlEngine;
35class QQmlComponent;
36class QQmlContext;
37class QQuickItem;
38
39namespace makVrv
40{
41class DtDe;
42class DtOsgChannel;
43class DtGlRenderTexture;
44class DtWindow;
45} // namespace makVrv
46
47namespace makVre
48{
50class DtQQuickWindow;
53
54//! \brief Core renderer for QML content in the VREngage environment
55//!
56//! This singleton class manages the loading, rendering, and interaction with
57//! QML-based user interfaces. It integrates Qt Quick with OSG rendering to provide
58//! seamless UI capabilities within 3D environments.
60{
61public:
62 //! \brief Type definition for mapping graphics contexts to Qt Quick data
63 using RenderControlMap = std::map<osg::GraphicsContext*, DtPerWindowQtQuickData*>;
64
65public:
66 //! \brief Gets the singleton Qt Quick renderer instance
67 //! \return Pointer to the singleton renderer instance
69
70 //! \brief Returns the QML module URI for C++ components registered by VR-Engage
71 //! \return The module URI string ("VRE.Components")
72 static const char* componentsModuleUri();
73
74 //! \brief Installs the Qt Quick renderer system
75 //! \param de Reference to the graphics engine
76 static void install(makVrv::DtDe& de);
77
78 //! \brief Cleans up and shuts down the Qt Quick renderer system
79 //!
80 //! Releases all resources and destroys loaded QML interfaces
81 virtual void shutdown();
82
83 //! \brief Loads a QML file and calls a function when loaded
84 //! \param owner The object that owns this QML interface
85 //! \param filepath Path to the QML file to load
86 //! \param file_loaded_func Callback function called when the file is loaded
87 virtual void loadQMLFile(
88 QObject* owner, const std::string& filepath, const std::function<void(QQuickItem*)>& file_loaded_func);
89
90 //! \brief Loads a QML file to a specific window and calls a function when loaded
91 //! \param owner The object that owns this QML interface
92 //! \param windowName Name of the window to load the QML into
93 //! \param filepath Path to the QML file to load
94 //! \param file_loaded_func Callback function called when the file is loaded
95 virtual void loadQMLFile(QObject* owner, const std::string& windowName, const std::string& filepath,
96 const std::function<void(QQuickItem*)>& file_loaded_func);
97
98 //! \brief Loads a QML file for render-to-texture and calls a function when loaded
99 //!
100 //! Loads a QML file and renders it to a texture target. The callback function will be
101 //! called with the "fbo" property set to the OpenGL texture being rendered into.
102 //!
103 //! \param owner The object that owns this QML interface
104 //! \param filepath Path to the QML file to load
105 //! \param target OpenGL texture to render the QML content into
106 //! \param func Callback function called when the file is loaded
107 virtual void loadQMLFileRTT(QObject* owner, const std::string& filepath, osg::Texture2D* target,
108 const std::function<void(QQuickItem*)>& func);
109
110 //! \brief Reloads the QML file associated with the specified owner
111 //! \param owner The object that owns the QML interface to reload
112 virtual void reloadQMLFile(QObject* owner);
113
114 //! \brief Closes the UI associated with the specified root item
115 //! \param root The root QQuickItem of the UI to close
116 virtual void closeUIByRoot(QQuickItem* root);
117
118 //! \brief Closes the UI associated with the specified owner
119 //! \param owner The object that owns the UI to close
120 virtual void closeUIByOwner(QObject* owner);
121
122 //! \brief Gets the root QML context
123 //!
124 //! This context is needed to allow C++ to send JavaScript and QML engine objects
125 //! \return Pointer to the root QML context
126 virtual QQmlContext* rootContext();
127
128 //! \brief Gets the render-to-texture geode
129 //! \return Pointer to the OSG geode used for render-to-texture
130 virtual osg::Geode* geodeRtt();
131
132 //! \brief Gets the graphics engine reference
133 //! \return Reference to the graphics engine
134 virtual makVrv::DtDe& de() { return myDe; }
135
136 //! \brief Sets the virtual reality render target
137 //! \param texture Pointer to the texture to use as the VR render target
138 virtual void setVirtualRealityRenderTarget(osg::Texture2D* texture);
139
140 //! \brief Synchronizes the virtual reality render target with all file data
141 //!
142 //! Finds any file data using the virtual reality target and updates their render texture
143 //! \param ctxid The context ID to synchronize
144 virtual void syncVirtualRealityRenderTarget(unsigned int ctxid);
145
146 //! \brief Slot called when VR running state changes
147 //! \param running True if VR is running, false otherwise
148 virtual void slot_vrRunningChanged(bool running);
149
150 //! \brief Slot called when VR overlay settings change
151 virtual void slot_vrOverlayChanged();
152
153 //! \brief Adds a category to the debug map
154 //! \param logCat The logging category to add
155 virtual void addToDebugMap(const std::string& logCat);
156
157 //! \brief Gets the number of UIs that are in queue to load
158 //! \return The number of pending UI loads
159 virtual const int numberOfUIsToLoad() const;
160
161 //! \brief Gets a reference to a child QObject in QML
162 //! \param parent The parent QObject to search in
163 //! \param objectName The name of the child object to find
164 //! \return Pointer to the found child object, or nullptr if not found
165 static QObject* getChildObject(const QObject* parent, const QString& objectName);
166
167 //! \brief Gets the dimensions of the specified window
168 //! \param windowName Name of the window to get dimensions for
169 //! \return Reference to a QRect containing the window dimensions
170 virtual const QRect& getWindowDimensions(const std::string& windowName) const;
171
172protected:
173 //! Friends that need access to protected members
175 friend class DtQQuickWindow;
176
177protected:
178 //! \brief Constructor for Qt Quick renderer
179 //! \param de Reference to the graphics engine
180 DtQtQuickRenderer(makVrv::DtDe& de);
181
182 //! \brief Virtual destructor
184
185 //! \brief Initializes Qt Quick rendering components
186 //! \param renderInfo Render information from OSG
187 virtual void initQtQuickRenderingComponents(osg::RenderInfo& renderInfo);
188 //! \brief Gets Qt Quick data for the specified graphics context
189 //! \param gc The graphics context to get data for
190 //! \return Pointer to the Qt Quick data for the context
191 virtual DtPerWindowQtQuickData* getWindowData(osg::GraphicsContext* gc);
192
193 //! \brief Installs default properties for all root QML objects
194 //!
195 //! Sets up properties that every root QML object should have
197
198 //! \brief Updates the Qt Quick rendering in OSG
199 //! \param renderInfo Render information from OSG
200 virtual void updateQuick(osg::RenderInfo& renderInfo);
201
202 //! \brief Handles a window being destroyed
203 //! \param win Pointer to the window being destroyed
204 virtual void onWindowToBeDestroyed(makVrv::DtWindow* win);
205
206 //! \brief Sets up the debug configuration
207 virtual void setDebugConfig();
208 //! \brief Callback for debug manager
209 virtual void debugManagerCallback();
210
211 //! \brief Reloads a QML file from file data
212 //! \param data The file data to reload
213 virtual void reloadQMLFile(DtQtQuickFileData* data);
214 //! \brief Closes a UI from file data
215 //! \param data The file data for the UI to close
216 virtual void closeUI(DtQtQuickFileData* data);
217 //! \brief Loads a QML file immediately
218 //! \param gc The graphics context to load into
219 //! \param fileData The file data to load
220 //! \return Pointer to the root QML item
221 virtual QQuickItem* loadFileNow(osg::GraphicsContext* gc, DtQtQuickFileData* fileData);
222
223protected:
224 //! \brief Singleton instance of the Qt Quick renderer
226
227 //! \brief Reference to the graphics engine
228 makVrv::DtDe& myDe;
229
230 //! \brief Standard OSG geode for Qt Quick rendering
231 osg::ref_ptr<osg::Geode> myGeode;
232 //! \brief Standard OSG drawable for Qt Quick rendering
233 osg::ref_ptr<osg::Drawable> myDrawable;
234
235 //! \brief Render-to-texture OSG geode
236 osg::ref_ptr<osg::Geode> myGeodeRTT;
237 //! \brief Render-to-texture OSG drawable
238 osg::ref_ptr<osg::Drawable> myDrawableRTT;
239
240 //! \brief QML engine for loading and rendering QML
241 QQmlEngine* myQmlEngine;
242
243 //! \brief Default graphics context
244 osg::GraphicsContext* myDefaultContext;
245 //! \brief Map of graphics contexts to Qt Quick data
247
248 //! \brief List of UIs waiting to be loaded
249 std::vector<DtQtQuickFileData*> myUIsToLoadList;
250 //! \brief List of UIs that have been loaded
251 std::vector<DtQtQuickFileData*> myUIsLoadedList;
252
253 //! \brief Signal connection manager for Qt signals
254 makVrv::DtSignalConnectionManager myConnections;
255
256 //! \brief Texture to synchronize for VR rendering
257 osg::Texture2D* myRenderTargetToSync;
258
259 //! \brief Debug map for QML event debugging
260 std::map<std::string, bool> myQmlDebugMap;
261};
262
263} // namespace makVre
Container for per-window Qt Quick rendering data.
Definition vrePerWindowQtQuickData.h:41
Extended QQuickWindow for VREngage integration.
Definition vreQQuickWindow.h:29
Extended rendering control for Qt Quick in VREngage.
Definition vreQtQRenderControl.h:28
Container for QML file rendering data.
Definition vreQtQuickFileData.h:36
osg::ref_ptr< osg::Drawable > myDrawable
Standard OSG drawable for Qt Quick rendering.
Definition DtQtQuickRenderer.h:233
static void install(makVrv::DtDe &de)
Installs the Qt Quick renderer system.
std::map< std::string, bool > myQmlDebugMap
Debug map for QML event debugging.
Definition DtQtQuickRenderer.h:260
static const char * componentsModuleUri()
Returns the QML module URI for C++ components registered by VR-Engage.
virtual const int numberOfUIsToLoad() const
Gets the number of UIs that are in queue to load.
makVrv::DtSignalConnectionManager myConnections
Signal connection manager for Qt signals.
Definition DtQtQuickRenderer.h:254
std::vector< DtQtQuickFileData * > myUIsLoadedList
List of UIs that have been loaded.
Definition DtQtQuickRenderer.h:251
virtual void closeUIByRoot(QQuickItem *root)
Closes the UI associated with the specified root item.
virtual void setDebugConfig()
Sets up the debug configuration.
virtual osg::Geode * geodeRtt()
Gets the render-to-texture geode.
virtual void reloadQMLFile(DtQtQuickFileData *data)
Reloads a QML file from file data.
friend class DtQtQuickRendererDrawable
Friends that need access to protected members.
Definition DtQtQuickRenderer.h:174
virtual void onWindowToBeDestroyed(makVrv::DtWindow *win)
Handles a window being destroyed.
virtual void addToDebugMap(const std::string &logCat)
Adds a category to the debug map.
QQmlEngine * myQmlEngine
QML engine for loading and rendering QML.
Definition DtQtQuickRenderer.h:241
virtual makVrv::DtDe & de()
Gets the graphics engine reference.
Definition DtQtQuickRenderer.h:134
virtual void loadQMLFile(QObject *owner, const std::string &filepath, const std::function< void(QQuickItem *)> &file_loaded_func)
Loads a QML file and calls a function when loaded.
virtual void updateQuick(osg::RenderInfo &renderInfo)
Updates the Qt Quick rendering in OSG.
virtual ~DtQtQuickRenderer()
Virtual destructor.
friend class DtQQuickWindow
Definition DtQtQuickRenderer.h:175
virtual void reloadQMLFile(QObject *owner)
Reloads the QML file associated with the specified owner.
DtQtQuickRenderer(makVrv::DtDe &de)
Constructor for Qt Quick renderer.
virtual void slot_vrRunningChanged(bool running)
Slot called when VR running state changes.
static DtQtQuickRenderer * theQtQuickRenderer
Singleton instance of the Qt Quick renderer.
Definition DtQtQuickRenderer.h:225
virtual QQuickItem * loadFileNow(osg::GraphicsContext *gc, DtQtQuickFileData *fileData)
Loads a QML file immediately.
osg::ref_ptr< osg::Geode > myGeode
Standard OSG geode for Qt Quick rendering.
Definition DtQtQuickRenderer.h:231
makVrv::DtDe & myDe
Reference to the graphics engine.
Definition DtQtQuickRenderer.h:228
virtual void debugManagerCallback()
Callback for debug manager.
virtual const QRect & getWindowDimensions(const std::string &windowName) const
Gets the dimensions of the specified window.
RenderControlMap myRenderControlMap
Map of graphics contexts to Qt Quick data.
Definition DtQtQuickRenderer.h:246
static DtQtQuickRenderer * instance()
Gets the singleton Qt Quick renderer instance.
osg::ref_ptr< osg::Drawable > myDrawableRTT
Render-to-texture OSG drawable.
Definition DtQtQuickRenderer.h:238
virtual void shutdown()
Cleans up and shuts down the Qt Quick renderer system.
virtual void slot_vrOverlayChanged()
Slot called when VR overlay settings change.
virtual void loadQMLFile(QObject *owner, const std::string &windowName, const std::string &filepath, const std::function< void(QQuickItem *)> &file_loaded_func)
Loads a QML file to a specific window and calls a function when loaded.
osg::GraphicsContext * myDefaultContext
Default graphics context.
Definition DtQtQuickRenderer.h:244
osg::ref_ptr< osg::Geode > myGeodeRTT
Render-to-texture OSG geode.
Definition DtQtQuickRenderer.h:236
std::vector< DtQtQuickFileData * > myUIsToLoadList
List of UIs waiting to be loaded.
Definition DtQtQuickRenderer.h:249
std::map< osg::GraphicsContext *, DtPerWindowQtQuickData * > RenderControlMap
Type definition for mapping graphics contexts to Qt Quick data.
Definition DtQtQuickRenderer.h:63
osg::Texture2D * myRenderTargetToSync
Texture to synchronize for VR rendering.
Definition DtQtQuickRenderer.h:257
static QObject * getChildObject(const QObject *parent, const QString &objectName)
Gets a reference to a child QObject in QML.
virtual void loadQMLFileRTT(QObject *owner, const std::string &filepath, osg::Texture2D *target, const std::function< void(QQuickItem *)> &func)
Loads a QML file for render-to-texture and calls a function when loaded.
virtual QQmlContext * rootContext()
Gets the root QML context.
virtual void syncVirtualRealityRenderTarget(unsigned int ctxid)
Synchronizes the virtual reality render target with all file data.
virtual void closeUIByOwner(QObject *owner)
Closes the UI associated with the specified owner.
virtual DtPerWindowQtQuickData * getWindowData(osg::GraphicsContext *gc)
Gets Qt Quick data for the specified graphics context.
virtual void installDefaultProperties()
Installs default properties for all root QML objects.
virtual void setVirtualRealityRenderTarget(osg::Texture2D *texture)
Sets the virtual reality render target.
virtual void closeUI(DtQtQuickFileData *data)
Closes a UI from file data.
virtual void initQtQuickRenderingComponents(osg::RenderInfo &renderInfo)
Initializes Qt Quick rendering components.
Defines export macros for the VREngage Qt Quick Renderer library.
#define QTQUICKRENDERER_DLL
Export/import macro for non-Windows platforms.
Definition export.h:40
Provides configuration initialization for VREngage components.
!
Definition glsVreMessageUtil.h:50
Definition appLauncherComponent.h:28