Radium Engine  1.5.0
Ra::Gui::Viewer Class Reference

#include <Gui/Viewer/Viewer.hpp>

+ Inheritance diagram for Ra::Gui::Viewer:
+ Collaboration diagram for Ra::Gui::Viewer:

Public Slots

void reloadShaders ()
 Tell the renderer to reload all shaders.
 
void displayTexture (const QString &tex)
 Set the final display texture.
 
bool changeRenderer (int index)
 Set the renderer.
 
void enablePostProcess (int enabled)
 Toggle the post-process effetcs.
 
void enableDebugDraw (int enabled)
 Toggle the debug drawing.
 
void setBackgroundColor (const Core::Utils::Color &background)
 
void displayHelpDialog ()
 
- Public Slots inherited from Ra::Gui::WindowQt
void cleanupGL ()
 call deinitializeGL if needed, with context activated
 
void screenChanged ()
 

Signals

void requestEngineOpenGLInitialization ()
 
bool glInitialized ()
 
void rendererReady ()
 Emitted when GL context is ready. We except call to addRenderer here.
 
void rightClickPicking (const Ra::Engine::Rendering::Renderer::PickingResult &result)
 Emitted when the rendered is correctly initialized. More...
 
void toggleBrushPicking (bool on)
 Emitted when the corresponding key is released (see keyReleaseEvent)
 
void needUpdate ()
 
void onMousePress (QMouseEvent *event)
 Event sent after a mouse press event has been processed, but before emitting needUpdate()
 
void onMouseRelease (QMouseEvent *event)
 Event sent after a mouse release event has been processed, but before emitting needUpdate()
 
void onMouseMove (QMouseEvent *event)
 Event sent after a mouse move event has been processed, but before emitting needUpdate()
 
- Signals inherited from Ra::Gui::WindowQt
void dpiChanged ()
 Emitted when physical device changes. Useful for tracking devicePixelRatio() change.
 

Public Member Functions

 Viewer (QScreen *screen=nullptr)
 Constructor.
 
 ~Viewer () override
 Destructor.
 
virtual void setupKeyMappingCallbacks ()
 add observers to keyMappingManager for gizmo, camera and viewer.
 
virtual bool prepareDisplay ()
 
QOpenGLContext * getContext () const
 Access to the OpenGL context of the Viewer.
 
void setCameraManipulator (CameraManipulator *ci)
 Set the current camera interface.
 
CameraManipulatorgetCameraManipulator ()
 Access to camera interface.
 
void resetToDefaultCamera ()
 
GizmoManagergetGizmoManager ()
 Access to gizmo manager.
 
const Engine::Rendering::RenderergetRenderer () const
 Read-only access to renderer.
 
Engine::Rendering::RenderergetRenderer ()
 Read-write access to renderer.
 
int addRenderer (const std::shared_ptr< Engine::Rendering::Renderer > &e)
 
PickingManager * getPickingManager ()
 Access to the feature picking manager.
 
virtual void update (const Scalar dt)
 Update the internal viewer state to the (application) time dt.
 
void startRendering (const Scalar dt)
 Start rendering (potentially asynchronously in a separate thread) More...
 
void swapBuffers ()
 Blocks until rendering is finished.
 
Scalar getDepthUnderMouse () const
 
Core::Vector2 toDevice (const Core::Vector2 &logicCoordinates)
 

Misc functions

void processPicking ()
 Emits signals corresponding to picking requests.
 
void fitCameraToScene (const Core::Aabb &sceneAabb)
 Moves the camera so that the whole scene is visible.
 
void fitCamera ()
 
std::vector< std::string > getRenderersName () const
 Returns the names of the different registred renderers.
 
void grabFrame (const std::string &filename)
 Write the current frame as an image. Supports either BMP or PNG file names.
 
void enableDebug ()
 
const Core::Utils::ColorgetBackgroundColor () const
 get the currently used background color
 
KeyMappingManager::KeyMappingAction addCustomAction (const std::string &actionName, const KeyMappingManager::EventBinding &binding, std::function< void(QEvent *)> callback)
 Add a custom event callback.
 
- Public Member Functions inherited from Ra::Gui::WindowQt
 WindowQt (QScreen *screen)
 
void resizeEvent (QResizeEvent *event) override
 
void showEvent (QShowEvent *event) override
 
void exposeEvent (QExposeEvent *event) override
 
virtual void enterEvent (QEvent *event)
 paintgl is done by main rendering loop
 
virtual void leaveEvent (QEvent *event)
 
void makeCurrent ()
 
void doneCurrent ()
 
ScopedGLContext activateScopedContext ()
 
QOpenGLContext * context ()
 
bool isOpenGlInitialized () const
 

Protected Types

enum  KeyEventType { KeyPressed = 0 , KeyReleased , KeyEventTypeCount }
 Name of the customisable key actions.
 

Protected Member Functions

void createGizmoManager ()
 create gizmos
 
void initializeRenderer (Engine::Rendering::Renderer *renderer)
 Initialize renderer internal state + configure lights.
 
bool initializeGL () override
 
void resizeGL (QResizeEvent *event) override
 Resize the view port and the camera. Called by the resize event.
 
Engine::Rendering::Renderer::PickingMode getPickingMode (const Ra::Gui::KeyMappingManager::KeyMappingAction &action) const
 
void showEvent (QShowEvent *ev) override
 
void focusOutEvent (QFocusEvent *event) override
 reset key pressed, in case a key is pressed when focus lost
 

If GL is initialized, do the viewer stuff, and call handle*Event to perform actual event handling, according to keyMapping. If event is not processed by Viewer, it's forwarded to parent() (if any).

void keyPressEvent (QKeyEvent *event) override
 
void keyReleaseEvent (QKeyEvent *event) override
 
void mousePressEvent (QMouseEvent *event) override
 
void mouseReleaseEvent (QMouseEvent *event) override
 
void mouseMoveEvent (QMouseEvent *event) override
 
void wheelEvent (QWheelEvent *event) override
 

handle the events, called by *Event, do the actual work, should be overriden in derived classes.

virtual bool handleKeyPressEvent (QKeyEvent *event)
 
virtual bool handleKeyReleaseEvent (QKeyEvent *event)
 
virtual void handleMousePressEvent (QMouseEvent *event, Ra::Engine::Rendering::Renderer::PickingResult &result)
 
virtual void handleMouseReleaseEvent (QMouseEvent *event)
 
virtual void handleMouseMoveEvent (QMouseEvent *event, Ra::Engine::Rendering::Renderer::PickingResult &result)
 
virtual void handleWheelEvent (QWheelEvent *event)
 
- Protected Member Functions inherited from Ra::Gui::WindowQt
void initialize ()
 
void resizeInternal (QResizeEvent *event)
 
virtual void deinitializeGL ()
 DeInitialize the OpenGL.
 
- Protected Member Functions inherited from Ra::Gui::KeyMappingManageable< Viewer >
Viewerself ()
 

Protected Attributes

std::vector< std::shared_ptr< Engine::Rendering::Renderer > > m_renderers
 
std::vector< std::shared_ptr< Engine::Rendering::Renderer > > m_pendingRenderers
 
Engine::Rendering::Rendererm_currentRenderer
 
PickingManager * m_pickingManager
 Owning Pointer to the feature picking manager.
 
bool m_isBrushPickingEnabled
 
Scalar m_brushRadius
 
std::unique_ptr< CameraManipulatorm_camera
 Owning pointer to the camera.
 
GizmoManagerm_gizmoManager
 Owning (QObject child) pointer to gizmo manager.
 
Core::Utils::Color m_backgroundColor { Core::Utils::Color::Grey( 0.0392_ra, 0_ra ) }
 
std::array< std::map< Core::Utils::Index, std::function< void(QKeyEvent *)> >, KeyEventTypeCount > m_customKeyActions
 
KeyMappingCallbackManager m_keyMappingCallbackManager
 
KeyMappingManager::Context m_activeContext {}
 
- Protected Attributes inherited from Ra::Gui::WindowQt
std::unique_ptr< QOpenGLContext > m_context
 
bool m_updatePending
 
std::atomic_bool m_glInitialized
 

Friends

class KeyMappingManageable< Viewer >
 

Additional Inherited Members

- Static Public Member Functions inherited from Ra::Gui::KeyMappingManageable< Viewer >
static KeyMappingManager::Context getContext ()
 
static void configureKeyMapping ()
 
- Static Protected Member Functions inherited from Ra::Gui::WindowQt
static glbinding::ProcAddress getProcAddress (const char *name)
 
- Static Protected Member Functions inherited from Ra::Gui::KeyMappingManageable< Viewer >
static void setContext (const KeyMappingManager::Context &c)
 

Detailed Description

The Viewer is the main display class. It could be used as an independant window or can be set as a central widget on a more complex gui by using the adapter from QWindow to QWidget To do that, the following code could be used :

m_viewer = new Ra::Gui::Viewer();
QWidget * viewerwidget = QWidget::createWindowContainer(m_viewer);
setCentralWidget(viewerwidget);

Whatever its usage (QWindow or QWidget) the Viewer has the same funtionalities. Its acts as a bridge between the interface, the engine and the renderer Among its responsibilities are :

  • Owning the renderer and camera, and managing their lifetime.
  • setting up the renderer and camera by keeping it informed of interfaces changes (e.g. resize).
  • catching user interaction (mouse clicks) at the lowest level and forward it to the camera and the rest of the application
  • Expose the asynchronous rendering interface

Definition at line 53 of file Viewer.hpp.

Member Function Documentation

◆ addRenderer()

int Ra::Gui::Viewer::addRenderer ( const std::shared_ptr< Engine::Rendering::Renderer > &  e)

Add a renderer and return its index. Need to be called when catching

Parameters
e: your own renderer
Returns
index of the newly added renderer
int rendererId = addRenderer(new MyRenderer(width(), height()));
changeRenderer(rendererId);
auto light = Ra::Core::make_shared<Engine::Data::DirectionalLight>();
m_camera->attachLight( light );
void initialize(uint width, uint height)
Initialize renderer.
Definition: Renderer.cpp:56
std::unique_ptr< CameraManipulator > m_camera
Owning pointer to the camera.
Definition: Viewer.hpp:311
int addRenderer(const std::shared_ptr< Engine::Rendering::Renderer > &e)
Definition: Viewer.cpp:187
bool changeRenderer(int index)
Set the renderer.
Definition: Viewer.cpp:376
const Engine::Rendering::Renderer * getRenderer() const
Read-only access to renderer.
Definition: Viewer.cpp:179

Definition at line 187 of file Viewer.cpp.

+ Here is the call graph for this function:

◆ handleMousePressEvent()

void Ra::Gui::Viewer::handleMousePressEvent ( QMouseEvent *  event,
Ra::Engine::Rendering::Renderer::PickingResult result 
)
protectedvirtual
Todo:
something like explained here if under mouse objects grabs the action, just send it to the object so we need to have something like grabber = renderobject(ro id)->getMouseManipulator if(grabber && grabber->handleEvent(event, buttons, modifiers, key){ context = grabber->getContext currentGrabber = grabber (we need to store it for mouse move)

[event dispatch]

[event dispatch]

Definition at line 695 of file Viewer.cpp.

+ Here is the call graph for this function:

◆ initializeGL()

bool Ra::Gui::Viewer::initializeGL ( )
overrideprotectedvirtual

Initialize openGL. Called on by the first "show" call to the main window.

Warning
This function is NOT reentrant, and may behave incorrectly if called at the same time than #intializeRenderer
Note
Must be called only when a valid openGLContext is bound (see WindowsQt::initialize)

Reimplemented from Ra::Gui::WindowQt.

Definition at line 459 of file Viewer.cpp.

+ Here is the call graph for this function:

◆ mouseMoveEvent()

void Ra::Gui::Viewer::mouseMoveEvent ( QMouseEvent *  event)
overrideprotected
Todo:
propagateToParent

Definition at line 597 of file Viewer.cpp.

+ Here is the call graph for this function:

◆ mousePressEvent()

void Ra::Gui::Viewer::mousePressEvent ( QMouseEvent *  event)
overrideprotected

We intercept the mouse events in this widget to get the coordinates of the mouse in screen space.

Definition at line 574 of file Viewer.cpp.

+ Here is the call graph for this function:

◆ mouseReleaseEvent()

void Ra::Gui::Viewer::mouseReleaseEvent ( QMouseEvent *  event)
overrideprotected
Todo:
propagateToParent

Definition at line 591 of file Viewer.cpp.

◆ prepareDisplay()

bool Ra::Gui::Viewer::prepareDisplay ( )
virtual

Prepare the viewer to display a scene. This will ask the renderer to build its specific OenGL related objects and set the camera to its default state

Returns
true if the scene is ready to display.

Definition at line 824 of file Viewer.cpp.

+ Here is the call graph for this function:

◆ requestEngineOpenGLInitialization

void Ra::Gui::Viewer::requestEngineOpenGLInitialization ( )
signal

Emitted when GL context is ready and the engine OpenGL part must be initialized. Renderers might be added here using addRenderer.

◆ rightClickPicking

void Ra::Gui::Viewer::rightClickPicking ( const Ra::Engine::Rendering::Renderer::PickingResult result)
signal

Emitted when the rendered is correctly initialized.

Emitted when the resut of a right click picking is known (for selection)

◆ startRendering()

void Ra::Gui::Viewer::startRendering ( const Scalar  dt)

Start rendering (potentially asynchronously in a separate thread)

Todo:
FIXME : move this outside of the rendering loop. must be done once per renderer ... if there is no light on the renderer, add the head light attached to the camera ...

Definition at line 217 of file Viewer.cpp.

+ Here is the call graph for this function:

◆ toDevice()

Core::Vector2 Ra::Gui::Viewer::toDevice ( const Core::Vector2 &  logicCoordinates)
inline

Computes device dependent (i.e. framebuffer) 2d coordinates from device independent (i.e. qt's main coordinate system) coordinates.

See https://doc.qt.io/qt-6/highdpi.html

Definition at line 165 of file Viewer.hpp.

◆ wheelEvent()

void Ra::Gui::Viewer::wheelEvent ( QWheelEvent *  event)
overrideprotected
Todo:
propagateToParent

Definition at line 613 of file Viewer.cpp.

Member Data Documentation

◆ m_customKeyActions

std::array<std::map<Core::Utils::Index, std::function<void( QKeyEvent* )> >, KeyEventTypeCount> Ra::Gui::Viewer::m_customKeyActions
protected

Array of custom key event handler Index is KeyEventType

Definition at line 323 of file Viewer.hpp.

◆ m_renderers

std::vector<std::shared_ptr<Engine::Rendering::Renderer> > Ra::Gui::Viewer::m_renderers
protected
Todo:
make the following private: Owning pointer to the renderers.

Definition at line 300 of file Viewer.hpp.


The documentation for this class was generated from the following files: