Workspace 6.21.5
Signals | Public Member Functions | List of all members
WSGLRenderer Class Reference

Renders a scene using OpenGL.

#include <Rendering/OpenGL/wsglrenderer.h>

Inheritance diagram for WSGLRenderer:
[legend]

Signals

void glSettingsUpdateRequested ()
 
void renderSceneSuccess ()
 

Public Member Functions

 WSGLRenderer (int width, int height, const Shader &defaultShader=LambertShader())
 
 ~WSGLRenderer () override
 
void addManipulator (TransformManipulator *manip)
 
void clearManipulators ()
 
TransformManipulatorgetActiveManipulator () const
 
bool getAllowRenderWhileModelsQueuedForProcessing () const
 
CameragetCamera ()
 
const CameragetCamera () const
 
const SceneRendererContextgetContext () const override
 
QVector2D getCurrentDepthRange () const
 
const QList< Light * > & getCurrentLights () const
 
const Mesh::TransformMatrixgetCurrentProjectionMatrix () const
 
WSGLRenderItemgetCurrentRenderItem () const
 
const Mesh::TransformMatrixgetCurrentViewMatrix () const
 
const Mesh::TransformMatrixgetCurrentViewMatrixInverse () const
 
const PickedItemgetFirstPickedItem () const
 
bool getForceDefaultShader () const
 
QOpenGLFunctions_2_1 & getGLFunctions ()
 
int getHeight () const
 
unsigned getMaxSupportedDepthLayers () const
 
const PickedItemMapgetPickedItems () const
 
const PickFiltergetPickFilter () const
 
const RenderFiltergetRenderFilter () const
 
bool getRenderingWithSsao () const
 
const RenderSettingsgetRenderSettings () const
 
const Mesh::BoundingBoxMinimalgetSceneBoundingBox () const
 
WSGLScreenSpaceLayersgetScreenSpaceLayers ()
 
const WSGLScreenSpaceLayersgetScreenSpaceLayers () const
 
int getWidth () const
 
WSGLContextgetWSGLContext ()
 
const WSGLContextgetWSGLContext () const
 
bool hasManipulators ()
 
bool initialize (WSGLContext &context)
 
bool isBlendingEnabled () const
 
bool isInitialized ()
 
bool modelSourceUpdateRequested () const
 
bool modelsQueuedForProcessing () const
 
bool pick (const QPoint &point, bool accumulate=false) const
 
bool pick (const QRect &rect, bool accumulate=false) const
 
bool pick (const QString &opIdPath, bool accumulate=false) const
 
bool pick (Mesh::ItemHandle::size_type elementId) const
 
bool pickNone ()
 
void popBlendState ()
 
void pushBlendState (bool enabled, GLuint srcRgb, GLuint dstRgb, GLuint srcAlpha, GLuint dstAlpha, GLuint depthMask=GL_FALSE, GLuint depthFunc=GL_LESS, QColor blendColor=QColor())
 
bool renderLoadScreen ()
 
bool renderPlaceholderImage ()
 
bool renderProcessingOverlay ()
 
bool renderScene (Scene &scene, GLuint fboHandle=0)
 
bool resize (int width, int height)
 
void setAllowRenderWhileModelsQueuedForProcessing (bool b)
 
void setCamera (Camera *camera)
 
void setDefaultShader (const Shader &defaultShader)
 
void setForceDefaultShader (bool b)
 
void setPickFilter (const PickFilter &filter)
 
void setRenderFilter (const RenderFilter &filter)
 
void setRenderSettings (const RenderSettings &settings)
 
bool shouldRenderType (const Mesh::ElementType::Type &type) const
 
- Public Member Functions inherited from TypedSceneRenderer< WSGLRenderer >
const SceneRendererTypeIdgetTypeId () const override
 
virtual const SceneRendererContextgetContext () const =0
 
virtual const SceneRendererTypeIdgetTypeId () const =0
 
- Public Member Functions inherited from Observable
virtual ~Observable ()
 
void attachObserver (Observer &observer)
 
void destroy ()
 
void detachObserver (Observer &observer)
 
void notifyEvent (const ObservableEvent &event)
 

Additional Inherited Members

- Static Public Member Functions inherited from TypedSceneRenderer< WSGLRenderer >
static SceneRendererTypeIdtypeId ()
 
- Static Public Member Functions inherited from SceneRenderer
static void renderOverlays (QPainter &painter, Scene &scene, const Camera &camera)
 
static bool renderOverlaysUnthreaded (QPainter &painter, Scene &scene, const Camera &camera)
 
- Protected Member Functions inherited from Observable
 Observable ()
 
 Observable (const Observable &)
 

Constructor & Destructor Documentation

◆ WSGLRenderer()

WSGLRenderer ( int  width,
int  height,
const Shader defaultShader = LambertShader() 
)
Parameters
widthWidth of the viewport in pixels
heightHeight of the viewport in pixels
defaultShaderThe default shader to use when no shader has been applied to an object, or when an invalid shader has been applied to an object.

Creates a new WSGLRenderer, used for drawing a Scene using OpenGL.

Note
While creating a WSGLRenderer does not require a current OpenGL context, deleting one does, as any dedicated resources used by the renderer will potentially be cleaned up at the time it is deleted.

◆ ~WSGLRenderer()

~WSGLRenderer ( )
override

Member Function Documentation

◆ addManipulator()

void addManipulator ( TransformManipulator manip)
Parameters
manipThe activeManipulator we wish to use to modify picked objects.
Note
The renderer will take ownership of the manipulator.

◆ clearManipulators()

void clearManipulators ( )

◆ getActiveManipulator()

TransformManipulator * getActiveManipulator ( ) const
Returns
The activeManipulator the renderer is using to modify picked objects.

◆ getAllowRenderWhileModelsQueuedForProcessing()

bool getAllowRenderWhileModelsQueuedForProcessing ( ) const
Returns
True if the renderer should continue to render if any models are queued for processing.

◆ getCamera() [1/2]

Camera * getCamera ( )
Returns
The current camera the renderer will use, or a null pointer if not set.

If the camera is not currently set when the renderer tries to render a scene, it will attempt to find a camera in the scene itself and set the camera to whatever it finds. It first looks for a camera with the name "Default" (case-sensitive). If no such camera exists, then it will simply use the first camera it finds. If no cameras exist in the scene, rendering will fail.

Because the renderer will attempt to find a camera if one is not supplied, then if the value returned from this function is a null pointer before rendering is attempted, after an attempt to render is made the value returned by this function could be something other than a null pointer.

◆ getCamera() [2/2]

const Camera * getCamera ( ) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ getContext()

const SceneRendererContext * getContext ( ) const
overridevirtual
Returns
The context associated with the renderer.
Note
This is different from the regular QOpenGLWidgets
See also
context

Implements SceneRenderer.

◆ getCurrentDepthRange()

QVector2D getCurrentDepthRange ( ) const
Returns
The current near / far depth values used by OpenGL for the current depth layer.

◆ getCurrentLights()

const LightList & getCurrentLights ( ) const

Retrieves the set of lights currently active in the scene during rendering. Can only be called by objects that interact with the renderer while it is in the process of rendering.

NOTE: This function will fail if it is called when the renderer is not processing a scene.

Returns
the LightList containing the lights being used for rendering.

◆ getCurrentProjectionMatrix()

const Mesh::TransformMatrix & getCurrentProjectionMatrix ( ) const

Returns the current projection matrix being used for rendering. Can only be called by objects that interact with the renderer while it is in the process of rendering.

NOTE: This function will fail if it is called when the renderer is not processing a scene.

Returns
the TransformMatrix containing the projection matrix used for rendering.

◆ getCurrentRenderItem()

WSGLRenderItem & getCurrentRenderItem ( ) const

Retrieves the item which is currently in the process of being rendered. Can only be called by objects that interact with the renderer while it is in the process of rendering.

NOTE: This function will fail if it is called when the renderer is not processing a scene.

Returns
the RenderItem currently being rendered.

◆ getCurrentViewMatrix()

const Mesh::TransformMatrix & getCurrentViewMatrix ( ) const

Retrieves the view matrix currently being used to render the scene. Can only be called by objects that interact with the renderer while it is in the process of rendering.

NOTE: This function will fail if it is called when the renderer is not processing a scene.

Returns
the TransformMatrix being used as the view matrix for rendering.

◆ getCurrentViewMatrixInverse()

const Mesh::TransformMatrix & getCurrentViewMatrixInverse ( ) const

Returns the inverse of the view matrix currently being used. This function has been made available for efficiency reasons.

Can only be called by objects that interact with the renderer while it is in the process of rendering.

NOTE: This function will fail if it is called when the renderer is not processing a scene.

Returns
the TransformMatrix being used as the inverse of the view matrix for rendering.

◆ getFirstPickedItem()

const PickedItem * getFirstPickedItem ( ) const
Returns
The first picked item, if one exists, zero otherwise.

◆ getForceDefaultShader()

bool getForceDefaultShader ( ) const
Returns
True if the renderer is forced to always use the default shader, false otherwise.

Use this option if you have a single shader that you wish to render the entire scene with.

◆ getGLFunctions()

QOpenGLFunctions_2_1 & getGLFunctions ( )
Returns
A QOpenGLFunctions_2_1 object that has been initialized. Allows shaders to invoke OpenGL functions without needing to instantiate their own QOpenGLFunctions_2_1 objects.

◆ getHeight()

int getHeight ( ) const

◆ getMaxSupportedDepthLayers()

unsigned getMaxSupportedDepthLayers ( ) const

◆ getPickedItems()

const PickedItemMap & getPickedItems ( ) const
Returns
The entire set of picked items in an associative map.

◆ getPickFilter()

const PickFilter & getPickFilter ( ) const
Returns
The pick filter currently being used by the renderer.

◆ getRenderFilter()

const CSIRO::Rendering::RenderFilter & getRenderFilter ( ) const
Returns
The render filter currently being used by the renderer.

◆ getRenderingWithSsao()

bool getRenderingWithSsao ( ) const
Returns
Returns true if SSAO is enabled for this renderer.

◆ getRenderSettings()

const RenderSettings & getRenderSettings ( ) const

◆ getSceneBoundingBox()

const Mesh::BoundingBoxMinimal & getSceneBoundingBox ( ) const
Returns
The bounding box of the currently rendered scene's contents - including only visible items. This operates on cached elements, so no mesh data should need to be read as part of invoking this data provided that a recent render has been performed.

◆ getScreenSpaceLayers() [1/2]

WSGLScreenSpaceLayers & getScreenSpaceLayers ( )
Returns
A copy of the WSGLScreenSpaceLayers object that this renderer contains. It can be used by shaders to access screen-space functionality if required.

◆ getScreenSpaceLayers() [2/2]

const WSGLScreenSpaceLayers & getScreenSpaceLayers ( ) const
Returns
A copy of the WSGLScreenSpaceLayers object that this renderer contains. It can be used by shaders to access screen-space functionality if required.

◆ getWidth()

int getWidth ( ) const

◆ getWSGLContext() [1/2]

WSGLContext * getWSGLContext ( )
Returns
the context associated with the renderer.

◆ getWSGLContext() [2/2]

const WSGLContext * getWSGLContext ( ) const
Returns
the context associated with the renderer.

◆ glSettingsUpdateRequested

void glSettingsUpdateRequested ( )
signal

◆ hasManipulators()

bool hasManipulators ( )
Returns
true if manipulators are applied to the renderer, false otherwise.

◆ initialize()

bool initialize ( WSGLContext context)
Precondition
The context must have been made current prior to invoking this function.
Parameters
contextThe context in which the renderer is being initialized.
Returns
True if the initialization of the renderer was successful.

This function should be called once only after the creation of the renderer, as it requires that a GL context exists. It will generally be invoked by the initialize event triggered by the GLWidget parent of the renderer. If the parent of the renderer does not have such an initialization event, this function will need to be invoked manually.

No renderering will occur if initialize has not yet been called on the renderer.

◆ isBlendingEnabled()

bool isBlendingEnabled ( ) const

◆ isInitialized()

bool isInitialized ( )
Warning
If the renderer has not been initialised, it is unsafe to invoke any render functions.
Returns
true if the renderer has been initialized and is ready for rendering.

◆ modelSourceUpdateRequested()

bool modelSourceUpdateRequested ( ) const
Returns
true if one or more MeshModelSources were requested to update during the render pass. If this is the case, another render pass will be required after the updates are complete in order to render the full scene.

◆ modelsQueuedForProcessing()

bool modelsQueuedForProcessing ( ) const
Returns
true if one or more MeshModelSource objects are queued for asynchronous processing by the renderer. If this returns true, at least another render pass will be required in order to render the full scene.

◆ pick() [1/4]

bool pick ( const QPoint &  point,
bool  accumulate = false 
) const
Parameters
pointThe point (in window coordinates) under which the closest visible object in the current scene will be selected.
accumulateIf true, the picked items will be added to our existing selection.
Returns
true if successful, false otherwise

Picks all of the items in the scene that lie underneath the specified rect (in window coordinates). This is useful for drag-selecting a set of items.

Note
No actual selection occurs with this function. The actual pick will occur during the next call to render.

◆ pick() [2/4]

bool pick ( const QRect &  rect,
bool  accumulate = false 
) const
Parameters
rectThe rectangle (in window coordinates) under which the closest visible objects in the current scene will be selected.
accumulateIf true, the picked items will be added to our existing selection.
Returns
true if successful, false otherwise

Picks all of the items in the scene that lie underneath the specified rect (in window coordinates). This is useful for drag-selecting a set of items.

Note
No actual selection occurs with this function. The actual pick will occur during the next call to render.

◆ pick() [3/4]

bool pick ( const QString &  opIdPath,
bool  accumulate = false 
) const
Parameters
opIdPathThe opIdPath of the model we wish to mark as picked
accumulateWhether or not to add this model to our existing selection
Returns
true if successful, false otherwise

Marks the scene item with the specified opIdPath as picked. This is useful for navigating through the scene in an external widget, and having the renderer highlight the selected item.

Note
No actual selection occurs with this function. The actual pick will occur during the next call to render.

◆ pick() [4/4]

bool pick ( Mesh::ItemHandle::size_type  elementId) const
Parameters
elementIdThe elementId of the element we want to highlight as picked.
Returns
true if an item was picked, false if nothing was picked.

Picks a specific element in the currently picked model. This is useful for navigating through a mesh-model structure using an external widget, and having the renderer synchronise with it.

Note
No actual selection occurs with this function. The actual pick will occur during the next call to render.

◆ pickNone()

bool pickNone ( )
Returns
true if successful, false otherwise.

Ensures that no items in the renderer are picked.

◆ popBlendState()

void popBlendState ( )

◆ pushBlendState()

void pushBlendState ( bool  enabled,
GLuint  srcRgb,
GLuint  dstRgb,
GLuint  srcAlpha,
GLuint  dstAlpha,
GLuint  depthMask = GL_FALSE,
GLuint  depthFunc = GL_LESS,
QColor  blendColor = QColor() 
)

◆ renderLoadScreen()

bool renderLoadScreen ( )
Precondition
The context must have been made current prior to invoking this function.

◆ renderPlaceholderImage()

bool renderPlaceholderImage ( )
Returns
true if the placeholder image was rendered successfully, false otherwise.

◆ renderProcessingOverlay()

bool renderProcessingOverlay ( )
Precondition
The context must have been made current prior to invoking this function.

◆ renderScene()

bool renderScene ( Scene scene,
GLuint  fboHandle = 0 
)
Precondition
An OpenGL context must have been made current prior to invoking this function.
Parameters
sceneThe scene to render using OpenGL
fboHandleThe target framebuffer to render the output to. 0 is the default screen framebuffer.

Renders the scene to the target fboHandle.

Returns
True if the scene was rendered to the output target (fboHandle), producing valid results. This does not mean the complete scene was necessarily rendered - it is possible that some elements of the scene are being processed asychronously. To check this, use the function modelsQueuedForProcessing(). Returns false whenever it is not able to render valid content, such as when a MeshModelSource is in the process of being updated.

◆ renderSceneSuccess

void renderSceneSuccess ( )
signal

◆ resize()

bool resize ( int  width,
int  height 
)
Precondition
The context must have been made current prior to invoking this function.
Parameters
widthThe desired width of the renderer.
heightThe desired height of the renderer.
Returns
true if the resize was successful. The resize may fail for a number of reasons, but usually only if an invalid size is specified, or it is unable to set up the required off-screen buffers.

◆ setAllowRenderWhileModelsQueuedForProcessing()

void setAllowRenderWhileModelsQueuedForProcessing ( bool  b)
Parameters
bWhether or not the renderer should continue to render if any models are queued for processing.

◆ setCamera()

void setCamera ( Camera camera)
Parameters
cameraThe camera the renderer should use. It is allowable for this to be a null pointer, in which case the renderer will attempt to find a camera the next time a render is attempted. See getCamera() for more information.

◆ setDefaultShader()

void setDefaultShader ( const Shader defaultShader)
Parameters
defaultShaderThe shader to use as the default if an item does not have a shader applied. Alternatively, if setForceDefaultShader() is enabled, the shader will be used for all items in the scene.

◆ setForceDefaultShader()

void setForceDefaultShader ( bool  b)
Parameters
bWhether or not to force the renderer to always use the default shader.

Use this option if you have a single shader that you wish to render the entire scene with.

◆ setPickFilter()

void setPickFilter ( const PickFilter filter)
Parameters
filterThe filter to assign to the renderer.

Setting the renderer's pick filter will control what type of object/element is targeted for interactive selection. This will have no effect when using an off-screen renderer.

◆ setRenderFilter()

void setRenderFilter ( const RenderFilter filter)
Parameters
filterThe filter to assign to the renderer.

Setting the renderer's render filter will control what type of object/element is rendered. Affects off-screen render too.

◆ setRenderSettings()

void setRenderSettings ( const RenderSettings settings)

◆ shouldRenderType()

bool shouldRenderType ( const Mesh::ElementType::Type type) const
Returns
True if the current render filter matches the request