VR-Engage  2.2
Loading...
Searching...
No Matches
debugRenderer.h
Go to the documentation of this file.
1/*********************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*********************************************************************************/
5
6//! \file debugRenderer.h
7//! \ingroup vreDebugManager
8//! \brief Contains the debug renderer class for the VREngage debug system.
9//!
10//! This file defines the debug renderer classes which handle 2D and 3D visual debug
11//! elements in the VREngage environment. The renderer manages debug draw commands,
12//! layer visibility, and integration with the graphics engine.
13
14#pragma once
15
18
19#include "vreUtil/color.h"
20
21#include <matrix/vlVector.h>
22
23#include <osg/Drawable>
24
25#include <list>
26
27
28namespace makVrv
29{
30class DtDe;
31class DtOsgChannel;
32} // namespace makVrv
33
34namespace makVre
35{
36class DtDebugCanvas;
38
39//! \brief Base class for all debug draw commands
40//!
41//! This abstract base class defines the interface for all debug drawing commands.
42//! It provides common functionality for handling color, fill mode, clipping, and
43//! lifetime management of debug visuals.
45{
46public:
47 //! \brief Constructor for debug draw commands
48 //! \param color Color of the debug visual
49 //! \param fill Fill mode (solid, wireframe, etc.)
50 //! \param clip Whether to clip against the view frustum
51 //! \param time Duration in seconds for this command to remain active
52 //! \param is3D Whether this is a 3D or 2D debug visual
53 DtDebugDrawCommand(DtColor color, DtColor::Fill fill, bool clip, const double& time, bool is3D)
54 : myColor(color)
55 , myFill(fill)
56 , myTime(time)
57 , myClip(clip)
58 , my3D(is3D)
59 {
60 }
61 //! \brief Virtual destructor
63
64 //! \brief Pure virtual draw method that must be implemented by derived classes
65 //! \param drawList Canvas to draw the debug visual on
66 virtual void draw(DtDebugCanvas& drawList) = 0;
67 //! \brief Reduces the remaining display time for this command
68 //! \param delta Time in seconds to subtract from the remaining time
69 virtual void reduceTime(double delta) { myTime -= delta; }
70 //! \brief Checks if this command has expired
71 //! \return True if the command's display time has elapsed
72 virtual bool ended() { return myTime <= 0; }
73 //! \brief Checks if this is a 3D visual
74 //! \return True if this is a 3D visual, false if 2D
75 virtual bool get3D() { return my3D; }
76
77protected:
78 //! \brief Eye position for view-dependent debug visuals
79 DtVector myEyepoint;
80 //! \brief Color of the debug visual
82 //! \brief Fill mode for the debug visual
84 //! \brief Remaining time in seconds for display
85 double myTime;
86 //! \brief Whether to clip against the view frustum
87 bool myClip;
88 //! \brief Whether this is a 3D visual
89 bool my3D;
90};
91
92//! \brief Parameters for debug rendering
93//!
94//! Contains all the necessary parameters for rendering debug visuals,
95//! including screen dimensions, view matrices, and observer position.
97{
98 //! \brief Width of the screen in pixels
100 //! \brief Height of the screen in pixels
102 //! \brief Whether rendering in 3D mode
103 bool is3d;
104 //! \brief Orthographic projection matrix
105 float ortho[16];
106 //! \brief Perspective projection matrix
107 float perspective[16];
108 //! \brief View matrix
109 float view[16];
110 //! \brief Observer position
111 DtVector obsPos;
112
113 //! \brief Default constructor
114 //!
115 //! Initializes all parameters to zero
117 {
118 // initialize all memory to 0
119 memset(this, 0, sizeof(DtDebugRenderParameters));
120 }
121};
122
123//! \brief Debug renderer for 2D and 3D debug visuals
124//!
125//! This class manages the rendering of all debug visuals in the VREngage environment.
126//! It handles layers, visibility controls, and integration with the graphics engine.
128{
129public:
130 //! \brief Constructor for debug renderer
131 //! \param de Reference to the graphics engine
132 DtDebugRenderer(makVrv::DtDe& de);
133
134 //! \brief Virtual destructor
136
137 //! \brief Main rendering function for debug visuals
138 //! \param context Graphics context for rendering
139 //! \param params Rendering parameters including view and projection matrices
140 //! \return True if rendering was successful
141 virtual bool render(void* context, DtDebugRenderParameters& params);
142
143 //! \brief Checks if debug rendering is enabled
144 //! \return True if debug rendering is enabled
145 virtual bool isEnabled();
146 //! \brief Enables or disables debug rendering
147 //! \param setting True to enable debug rendering, false to disable
148 virtual void setEnabled(bool setting);
149
150 //! \brief Gets the names of all available debug layers
151 //! \param timeoutTime Timeout in seconds to filter inactive layers
152 //! \param group Group name to filter layers by
153 //! \return Vector of pairs containing layer ID and display name
154 virtual std::vector<std::pair<std::string, std::string>> layerNames(
155 double timeoutTime = 0.f, const std::string& group = "");
156 //! \brief Enables or disables a specific debug layer
157 //! \param layerName Name of the layer to modify
158 //! \param setting True to enable the layer, false to disable
159 virtual void setLayerEnabled(const std::string& layerName, bool setting);
160 //! \brief Checks if a specific debug layer is enabled
161 //! \param layerName Name of the layer to check
162 //! \return True if the layer is enabled
163 virtual bool isLayerEnabled(const std::string& layerName);
164
165 //! \brief Debug callback function
166 //!
167 //! Called to trigger any debug-specific processing
168 virtual void debugCallback();
169
170 //! \brief Gets the render timeout value
171 //! \return Timeout value in seconds
173
174 //! \brief Sets the render timeout value
175 //! \param timeout Timeout value in seconds
176 void setRenderTimeout(float timeout);
177
178protected:
180
181 //! \brief Adds a draw command to a specific layer
182 //! \param layerId ID of the layer
183 //! \param layerName Display name of the layer
184 //! \param cmd Pointer to the draw command to add
185 void addDrawCmd(const std::string& layerId, const std::string& layerName, DtDebugDrawCommand* cmd);
186
187 //! \brief Handles sphere drawing messages
188 //! \param msg Pointer to the message containing sphere drawing parameters
189 //! \return Result of the message handling
191
192 //! \brief Handles line drawing messages
193 //! \param msg Pointer to the message containing line drawing parameters
194 //! \return Result of the message handling
196
197 //! \brief Handles cube drawing messages
198 //! \param msg Pointer to the message containing cube drawing parameters
199 //! \return Result of the message handling
201
202 //! \brief Handles triangle drawing messages
203 //! \param msg Pointer to the message containing triangle drawing parameters
204 //! \return Result of the message handling
206
207 //! \brief Handles 3D text drawing messages
208 //! \param msg Pointer to the message containing 3D text drawing parameters
209 //! \return Result of the message handling
211
212 //! \brief Handles 2D text drawing messages
213 //! \param msg Pointer to the message containing 2D text drawing parameters
214 //! \return Result of the message handling
216
217 //! \brief Handles graph drawing messages
218 //! \param msg Pointer to the message containing graph drawing parameters
219 //! \return Result of the message handling
221
222 //! \brief Handles text panel drawing messages
223 //! \param msg Pointer to the message containing text panel drawing parameters
224 //! \return Result of the message handling
226
227protected:
228 //! \brief Reference to the graphics engine
229 makVrv::DtDe& myDe;
230
231 //! \brief Main screen height in pixels
233 //! \brief Main screen width in pixels
235 //! \brief Timeout for debug menu visibility
237
238 //! \brief Structure for a debug rendering layer
239 //!
240 //! Contains all the settings and draw commands for a single debug layer
242 {
243 //! \brief Display name of the layer
245 //! \brief Whether the layer is enabled
247 //! \brief Time since last update
249 //! \brief Whether this is a 3D layer
250 bool myIs3D;
251 //! \brief List of draw commands for this layer
252 std::list<DtDebugDrawCommand*> myDrawList;
253
254 //! \brief Default constructor initializing layer as disabled
256 : myIsEnabled(false)
258 , myIs3D(false)
259 {
260 }
261 };
262 //! \brief Map of layer IDs to layer data
263 using DrawLayerMap = std::map<std::string, DrawLayer>;
264 //! \brief Iterator for the draw layer map
265 using DrawLayerMapIter = DrawLayerMap::iterator;
266 //! \brief Map of all debug layers
268
269 //! \brief Flag indicating if debug rendering is enabled
271
272 //! \brief Map of canvases for different rendering contexts
273 using CanvasMap = std::map<std::pair<void*, bool>, DtDebugCanvas*>;
274 //! \brief Map of all debug canvases
276
277 //! \brief 2D drawable for rendering debug elements
278 osg::ref_ptr<osg::Drawable> my2dDrawable;
279 //! \brief 3D drawable for rendering debug elements
280 osg::ref_ptr<osg::Drawable> my3dDrawable;
281
282 //! \brief Font filename for text rendering
283 DtFilename myFontFilename;
284 //! \brief Vertex shader filename
285 DtFilename myVsFilename;
286 //! \brief Fragment shader filename
287 DtFilename myFsFilename;
288};
289
290} // namespace makVre
Class for representing and manipulating RGBA colors.
Definition color.h:22
Fill
Fill mode enumeration for rendering.
Definition color.h:26
Base class for all debug draw commands.
Definition debugRenderer.h:45
bool myClip
Whether to clip against the view frustum.
Definition debugRenderer.h:87
double myTime
Remaining time in seconds for display.
Definition debugRenderer.h:85
DtVector myEyepoint
Eye position for view-dependent debug visuals.
Definition debugRenderer.h:79
DtColor::Fill myFill
Fill mode for the debug visual.
Definition debugRenderer.h:83
bool my3D
Whether this is a 3D visual.
Definition debugRenderer.h:89
virtual bool ended()
Checks if this command has expired.
Definition debugRenderer.h:72
virtual ~DtDebugDrawCommand()
Virtual destructor.
Definition debugRenderer.h:62
virtual void reduceTime(double delta)
Reduces the remaining display time for this command.
Definition debugRenderer.h:69
DtDebugDrawCommand(DtColor color, DtColor::Fill fill, bool clip, const double &time, bool is3D)
Constructor for debug draw commands.
Definition debugRenderer.h:53
virtual void draw(DtDebugCanvas &drawList)=0
Pure virtual draw method that must be implemented by derived classes.
virtual bool get3D()
Checks if this is a 3D visual.
Definition debugRenderer.h:75
DtColor myColor
Color of the debug visual.
Definition debugRenderer.h:81
virtual makVre::DtVreMessageResult handleDrawTris(makVre::DtVreMessage *msg)
Handles triangle drawing messages.
float myDebugMenuTimeout
Timeout for debug menu visibility.
Definition debugRenderer.h:236
virtual void setEnabled(bool setting)
Enables or disables debug rendering.
virtual makVre::DtVreMessageResult handleDrawCube(makVre::DtVreMessage *msg)
Handles cube drawing messages.
virtual void setLayerEnabled(const std::string &layerName, bool setting)
Enables or disables a specific debug layer.
osg::ref_ptr< osg::Drawable > my2dDrawable
2D drawable for rendering debug elements
Definition debugRenderer.h:278
virtual makVre::DtVreMessageResult handleDrawLine(makVre::DtVreMessage *msg)
Handles line drawing messages.
float myMainScreenHeight
Main screen height in pixels.
Definition debugRenderer.h:232
float myMainScreenWidth
Main screen width in pixels.
Definition debugRenderer.h:234
virtual makVre::DtVreMessageResult handleDrawTextPanel(makVre::DtVreMessage *msg)
Handles text panel drawing messages.
virtual makVre::DtVreMessageResult handleDrawSphere(makVre::DtVreMessage *msg)
Handles sphere drawing messages.
std::map< std::pair< void *, bool >, DtDebugCanvas * > CanvasMap
Map of canvases for different rendering contexts.
Definition debugRenderer.h:273
void setRenderTimeout(float timeout)
Sets the render timeout value.
friend DtVreDebugManager
Definition debugRenderer.h:179
DtFilename myFontFilename
Font filename for text rendering.
Definition debugRenderer.h:283
std::map< std::string, DrawLayer > DrawLayerMap
Map of layer IDs to layer data.
Definition debugRenderer.h:263
float getRenderTimeout()
Gets the render timeout value.
void addDrawCmd(const std::string &layerId, const std::string &layerName, DtDebugDrawCommand *cmd)
Adds a draw command to a specific layer.
osg::ref_ptr< osg::Drawable > my3dDrawable
3D drawable for rendering debug elements
Definition debugRenderer.h:280
CanvasMap myCanvasMap
Map of all debug canvases.
Definition debugRenderer.h:275
bool myIsEnabled
Flag indicating if debug rendering is enabled.
Definition debugRenderer.h:270
DtFilename myVsFilename
Vertex shader filename.
Definition debugRenderer.h:285
virtual bool isEnabled()
Checks if debug rendering is enabled.
virtual std::vector< std::pair< std::string, std::string > > layerNames(double timeoutTime=0.f, const std::string &group="")
Gets the names of all available debug layers.
DrawLayerMap::iterator DrawLayerMapIter
Iterator for the draw layer map.
Definition debugRenderer.h:265
makVrv::DtDe & myDe
Reference to the graphics engine.
Definition debugRenderer.h:229
virtual makVre::DtVreMessageResult handleDrawText2d(makVre::DtVreMessage *msg)
Handles 2D text drawing messages.
DtDebugRenderer(makVrv::DtDe &de)
Constructor for debug renderer.
virtual void debugCallback()
Debug callback function.
DrawLayerMap myDrawLayerMap
Map of all debug layers.
Definition debugRenderer.h:267
virtual bool isLayerEnabled(const std::string &layerName)
Checks if a specific debug layer is enabled.
virtual makVre::DtVreMessageResult handleDrawText3d(makVre::DtVreMessage *msg)
Handles 3D text drawing messages.
virtual bool render(void *context, DtDebugRenderParameters &params)
Main rendering function for debug visuals.
virtual ~DtDebugRenderer()
Virtual destructor.
virtual makVre::DtVreMessageResult handleDrawGraph(makVre::DtVreMessage *msg)
Handles graph drawing messages.
DtFilename myFsFilename
Fragment shader filename.
Definition debugRenderer.h:287
Main debug manager class for VREngage.
Definition debugManager.h:132
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Provides color representation and manipulation functionality.
Contains debug rendering macros for the VREngage debug system.
Defines export macros for the VREngage Debug Manager library.
#define DEBUGMANAGER_DLL
Export/import macro for non-Windows platforms.
Definition export.h:40
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Definition appLauncherComponent.h:28
makVrv::DtDe * de()
Gets the display element pointer used by the plugin.
Parameters for debug rendering.
Definition debugRenderer.h:97
float perspective[16]
Perspective projection matrix.
Definition debugRenderer.h:107
bool is3d
Whether rendering in 3D mode.
Definition debugRenderer.h:103
float screenHeight
Height of the screen in pixels.
Definition debugRenderer.h:101
DtDebugRenderParameters()
Default constructor.
Definition debugRenderer.h:116
float ortho[16]
Orthographic projection matrix.
Definition debugRenderer.h:105
float screenWidth
Width of the screen in pixels.
Definition debugRenderer.h:99
DtVector obsPos
Observer position.
Definition debugRenderer.h:111
float view[16]
View matrix.
Definition debugRenderer.h:109
std::string myLayerMapDisplayName
Display name of the layer.
Definition debugRenderer.h:244
double mySinceLastUpdateTime
Time since last update.
Definition debugRenderer.h:248
DrawLayer()
Default constructor initializing layer as disabled.
Definition debugRenderer.h:255
bool myIsEnabled
Whether the layer is enabled.
Definition debugRenderer.h:246
bool myIs3D
Whether this is a 3D layer.
Definition debugRenderer.h:250
std::list< DtDebugDrawCommand * > myDrawList
List of draw commands for this layer.
Definition debugRenderer.h:252