VR-Engage  2.2
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 Installs the Qt Quick renderer system
71 //! \param de Reference to the graphics engine
72 static void install(makVrv::DtDe& de);
73
74 //! \brief Cleans up and shuts down the Qt Quick renderer system
75 //!
76 //! Releases all resources and destroys loaded QML interfaces
77 virtual void shutdown();
78
79 //! \brief Loads a QML file and calls a function when loaded
80 //! \param owner The object that owns this QML interface
81 //! \param filepath Path to the QML file to load
82 //! \param file_loaded_func Callback function called when the file is loaded
83 virtual void loadQMLFile(
84 QObject* owner, const std::string& filepath, const std::function<void(QQuickItem*)>& file_loaded_func);
85
86 //! \brief Loads a QML file to a specific window and calls a function when loaded
87 //! \param owner The object that owns this QML interface
88 //! \param windowName Name of the window to load the QML into
89 //! \param filepath Path to the QML file to load
90 //! \param file_loaded_func Callback function called when the file is loaded
91 virtual void loadQMLFile(QObject* owner, const std::string& windowName, const std::string& filepath,
92 const std::function<void(QQuickItem*)>& file_loaded_func);
93
94 //! \brief Loads a QML file for render-to-texture and calls a function when loaded
95 //!
96 //! Loads a QML file and renders it to a texture target. The callback function will be
97 //! called with the "fbo" property set to the OpenGL texture being rendered into.
98 //!
99 //! \param owner The object that owns this QML interface
100 //! \param filepath Path to the QML file to load
101 //! \param target OpenGL texture to render the QML content into
102 //! \param func Callback function called when the file is loaded
103 virtual void loadQMLFileRTT(QObject* owner, const std::string& filepath, osg::Texture2D* target,
104 const std::function<void(QQuickItem*)>& func);
105
106 //! \brief Reloads the QML file associated with the specified owner
107 //! \param owner The object that owns the QML interface to reload
108 virtual void reloadQMLFile(QObject* owner);
109
110 //! \brief Closes the UI associated with the specified root item
111 //! \param root The root QQuickItem of the UI to close
112 virtual void closeUIByRoot(QQuickItem* root);
113
114 //! \brief Closes the UI associated with the specified owner
115 //! \param owner The object that owns the UI to close
116 virtual void closeUIByOwner(QObject* owner);
117
118 //! \brief Gets the root QML context
119 //!
120 //! This context is needed to allow C++ to send JavaScript and QML engine objects
121 //! \return Pointer to the root QML context
122 virtual QQmlContext* rootContext();
123
124 //! \brief Gets the render-to-texture geode
125 //! \return Pointer to the OSG geode used for render-to-texture
126 virtual osg::Geode* geodeRtt();
127
128 //! \brief Gets the graphics engine reference
129 //! \return Reference to the graphics engine
130 virtual makVrv::DtDe& de() { return myDe; }
131
132 //! \brief Sets the virtual reality render target
133 //! \param texture Pointer to the texture to use as the VR render target
134 virtual void setVirtualRealityRenderTarget(osg::Texture2D* texture);
135
136 //! \brief Synchronizes the virtual reality render target with all file data
137 //!
138 //! Finds any file data using the virtual reality target and updates their render texture
139 //! \param ctxid The context ID to synchronize
140 virtual void syncVirtualRealityRenderTarget(unsigned int ctxid);
141
142 //! \brief Slot called when VR running state changes
143 //! \param running True if VR is running, false otherwise
144 virtual void slot_vrRunningChanged(bool running);
145
146 //! \brief Slot called when VR overlay settings change
147 virtual void slot_vrOverlayChanged();
148
149 //! \brief Adds a category to the debug map
150 //! \param logCat The logging category to add
151 virtual void addToDebugMap(const std::string& logCat);
152
153 //! \brief Gets the number of UIs that are in queue to load
154 //! \return The number of pending UI loads
155 virtual const int numberOfUIsToLoad() const;
156
157 //! \brief Gets a reference to a child QObject in QML
158 //! \param parent The parent QObject to search in
159 //! \param objectName The name of the child object to find
160 //! \return Pointer to the found child object, or nullptr if not found
161 static QObject* getChildObject(const QObject* parent, const QString& objectName);
162
163 //! \brief Gets the dimensions of the specified window
164 //! \param windowName Name of the window to get dimensions for
165 //! \return Reference to a QRect containing the window dimensions
166 virtual const QRect& getWindowDimensions(const std::string& windowName) const;
167
168protected:
169 //! Friends that need access to protected members
171 friend class DtQQuickWindow;
172
173protected:
174 //! \brief Constructor for Qt Quick renderer
175 //! \param de Reference to the graphics engine
176 DtQtQuickRenderer(makVrv::DtDe& de);
177
178 //! \brief Virtual destructor
180
181 //! \brief Initializes Qt Quick rendering components
182 //! \param renderInfo Render information from OSG
183 virtual void initQtQuickRenderingComponents(osg::RenderInfo& renderInfo);
184 //! \brief Gets Qt Quick data for the specified graphics context
185 //! \param gc The graphics context to get data for
186 //! \return Pointer to the Qt Quick data for the context
187 virtual DtPerWindowQtQuickData* getWindowData(osg::GraphicsContext* gc);
188
189 //! \brief Installs default properties for all root QML objects
190 //!
191 //! Sets up properties that every root QML object should have
193
194 //! \brief Updates the Qt Quick rendering in OSG
195 //! \param renderInfo Render information from OSG
196 virtual void updateQuick(osg::RenderInfo& renderInfo);
197
198 //! \brief Handles a window being destroyed
199 //! \param win Pointer to the window being destroyed
200 virtual void onWindowToBeDestroyed(makVrv::DtWindow* win);
201
202 //! \brief Sets up the debug configuration
203 virtual void setDebugConfig();
204 //! \brief Callback for debug manager
205 virtual void debugManagerCallback();
206
207 //! \brief Reloads a QML file from file data
208 //! \param data The file data to reload
209 virtual void reloadQMLFile(DtQtQuickFileData* data);
210 //! \brief Closes a UI from file data
211 //! \param data The file data for the UI to close
212 virtual void closeUI(DtQtQuickFileData* data);
213 //! \brief Loads a QML file immediately
214 //! \param gc The graphics context to load into
215 //! \param fileData The file data to load
216 //! \return Pointer to the root QML item
217 virtual QQuickItem* loadFileNow(osg::GraphicsContext* gc, DtQtQuickFileData* fileData);
218
219protected:
220 //! \brief Singleton instance of the Qt Quick renderer
222
223 //! \brief Reference to the graphics engine
224 makVrv::DtDe& myDe;
225
226 //! \brief Standard OSG geode for Qt Quick rendering
227 osg::ref_ptr<osg::Geode> myGeode;
228 //! \brief Standard OSG drawable for Qt Quick rendering
229 osg::ref_ptr<osg::Drawable> myDrawable;
230
231 //! \brief Render-to-texture OSG geode
232 osg::ref_ptr<osg::Geode> myGeodeRTT;
233 //! \brief Render-to-texture OSG drawable
234 osg::ref_ptr<osg::Drawable> myDrawableRTT;
235
236 //! \brief QML engine for loading and rendering QML
237 QQmlEngine* myQmlEngine;
238
239 //! \brief Default graphics context
240 osg::GraphicsContext* myDefaultContext;
241 //! \brief Map of graphics contexts to Qt Quick data
243
244 //! \brief List of UIs waiting to be loaded
245 std::vector<DtQtQuickFileData*> myUIsToLoadList;
246 //! \brief List of UIs that have been loaded
247 std::vector<DtQtQuickFileData*> myUIsLoadedList;
248
249 //! \brief Signal connection manager for Qt signals
250 makVrv::DtSignalConnectionManager myConnections;
251
252 //! \brief Texture to synchronize for VR rendering
253 osg::Texture2D* myRenderTargetToSync;
254
255 //! \brief Debug map for QML event debugging
256 std::map<std::string, bool> myQmlDebugMap;
257};
258
259} // 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:229
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:256
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:250
std::vector< DtQtQuickFileData * > myUIsLoadedList
List of UIs that have been loaded.
Definition DtQtQuickRenderer.h:247
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:170
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:237
virtual makVrv::DtDe & de()
Gets the graphics engine reference.
Definition DtQtQuickRenderer.h:130
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:171
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:221
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:227
makVrv::DtDe & myDe
Reference to the graphics engine.
Definition DtQtQuickRenderer.h:224
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:242
static DtQtQuickRenderer * instance()
Gets the singleton Qt Quick renderer instance.
osg::ref_ptr< osg::Drawable > myDrawableRTT
Render-to-texture OSG drawable.
Definition DtQtQuickRenderer.h:234
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:240
osg::ref_ptr< osg::Geode > myGeodeRTT
Render-to-texture OSG geode.
Definition DtQtQuickRenderer.h:232
std::vector< DtQtQuickFileData * > myUIsToLoadList
List of UIs waiting to be loaded.
Definition DtQtQuickRenderer.h:245
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:253
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.
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
Definition appLauncherComponent.h:28