Workspace 6.21.5
Public Member Functions | Protected Member Functions | List of all members
LightsProcessor Class Reference

Base class for all objects that can process the lights in a Scene. More...

#include <Rendering/SceneComponents/Lights/lightsprocessor.h>

Inheritance diagram for LightsProcessor:
[legend]

Public Member Functions

 ~LightsProcessor () override
 
bool process (const QList< Light * > &lights)
 
bool process (Scene &scene)
 
bool visit (AmbientLight &light)
 
bool visit (DirectionalLight &light)
 
bool visit (PointLight &light)
 
bool visit (SpotLight &light)
 
- Public Member Functions inherited from Observable
virtual ~Observable ()
 
void attachObserver (Observer &observer)
 
void destroy ()
 
void detachObserver (Observer &observer)
 
void notifyEvent (const ObservableEvent &event)
 

Protected Member Functions

 LightsProcessor ()
 
 LightsProcessor (const LightsProcessor &p)
 
void logText (const QString &msg)
 
LightsProcessoroperator= (const LightsProcessor &p)
 
virtual bool postVisits (const QList< Light * > &lights)
 
virtual bool postVisits (Scene &scene)
 
virtual bool preVisits (const QList< Light * > &lights)
 
virtual bool preVisits (Scene &scene)
 
virtual bool visitImpl (AmbientLight &light)
 
virtual bool visitImpl (DirectionalLight &light)
 
virtual bool visitImpl (PointLight &light)
 
virtual bool visitImpl (SpotLight &light)
 
- Protected Member Functions inherited from Observable
 Observable ()
 
 Observable (const Observable &)
 

Detailed Description

There is a degree of similarity between LightsProcessor and SceneProcessor. The main difference is that a LightsProcessor is only intended to act on a scene's lights. As such, there are different visit() function overloads for Light subclasses instead of for SceneItem subclasses. The implementation of the process() function calls preVisits() before processing the lights and postVisits() after processing the lights, but in between these two calls only the Light's present in the Scene are visited. For the SceneProcessor class, all scene items are visited via the transform hierarchy.

The most common usage of a lights processor is as an internal implementation detail of a SceneProcessor.

See process() for more details about how the lights processor is intended to be implemented and used.

Constructor & Destructor Documentation

◆ LightsProcessor() [1/2]

LightsProcessor ( )
protected

Subclasses should only perform initialization in their constructor which does not depend on the scene being processed. Such processing can only be performed in preVisits().

◆ LightsProcessor() [2/2]

LightsProcessor ( const LightsProcessor p)
protected

◆ ~LightsProcessor()

~LightsProcessor ( )
override

Member Function Documentation

◆ logText()

void logText ( const QString &  msg)
protected
Parameters
msgThe text to send to the log.

◆ operator=()

LightsProcessor & operator= ( const LightsProcessor p)
protected

◆ postVisits() [1/2]

bool postVisits ( const QList< Light * > &  lights)
protectedvirtual
Parameters
lightsThe list of lights which are being processed.

Alternative postVisits function for processing a list of lights, rather than the entire scene.

Returns
True if successful, false if an error was encountered.
See also
postVists(Scene&)

Reimplemented in WSGLLightsProcessor.

◆ postVisits() [2/2]

bool postVisits ( Scene scene)
protectedvirtual
Parameters
sceneThe scene whose lights are being processed.

Sub-classes might re-implement this function to perform various clean up tasks or anything which should take place after all lights have been visited.

Returns
True if successful, or false if an error was encountered and the processing of the scene's lights should be aborted. The default implementation performs no action and simply returns true if the processor is currently processing the scene (which should always be the case if this function is called).
See also
process(), preVisits()

◆ preVisits() [1/2]

bool preVisits ( const QList< Light * > &  lights)
protectedvirtual
Parameters
lightsThe list of lights which are being processed.

Alternative preVisits function for processing a list of lights, rather than the entire scene.

Returns
True if successful, false if an error was encountered.
See also
preVists(Scene&)

Reimplemented in WSGLLightsProcessor.

◆ preVisits() [2/2]

bool preVisits ( Scene scene)
protectedvirtual
Parameters
sceneThe scene whose lights are being processed.

A common usage of this function might be to count the number of enabled lights in the scene and check this against some limit imposed on the renderer. For example, OpenGL mandates that a minimum of 6 lights must be supported, and implementations often only support this minimum number (or close to it). The processor may choose to only emit a warning that lights will be skipped or it may choose to generate a hard error by returning false.

Returns
True if successful, or false if an error was encountered and the processing of the scene's lights should be aborted. The default implementation performs no action and simply returns true if the processor is currently processing the scene (which should always be the case if this function is called).
See also
process(), postVisits()

◆ process() [1/2]

bool process ( const QList< Light * > &  lights)
Parameters
lightsThe list of lights to process.

An alternative process function that allows callers to provide a list of lights that they want to process, rather than processing every light in the scene.

Returns
true if successful, false otherwise.

◆ process() [2/2]

bool process ( Scene scene)
Parameters
sceneThe scene whose lights are to be processed.

This function will first call preVisits() to allow the processor to perform any setup or preparation needed. If that returns true, then each of the lights in scene will be visited in the order in which they were added to the scene (so essentially in an arbitrary order) by calling the light's visit() function and passing the processor itself as a parameter. The light's visit() function is expected to then call the processor's appropriate visit() overloaded function. This visitor pattern allows co-operation between a processor and the lights in a way that is extensible and requires no casting of types.

Once all items have been visited, the process() function calls postVisits() before returning.

Returns
True if all stages encountered no error, or false if any of preVisits(), postVisits() or any of the lights' visit() functions return false. As soon as any of these return a false result, the rest of the process() function is skipped and process() returns immediately.

◆ visit() [1/4]

bool visit ( AmbientLight light)
Parameters
lightThe light being visited.

This function should only ever be called by Light subclasses in their visit() function, which in turn should only ever be called by process().

◆ visit() [2/4]

bool visit ( DirectionalLight light)

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

◆ visit() [3/4]

bool visit ( PointLight light)

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

◆ visit() [4/4]

bool visit ( SpotLight light)

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

◆ visitImpl() [1/4]

bool visitImpl ( AmbientLight light)
protectedvirtual

See visit() for details.

Returns
True if the light was successfully processed, or false if the function failed and processing should be aborted. The default implementation performs no action and simply returns true.

Reimplemented in WSGLLightsProcessor.

◆ visitImpl() [2/4]

bool visitImpl ( DirectionalLight light)
protectedvirtual

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

Reimplemented in WSGLLightsProcessor.

◆ visitImpl() [3/4]

bool visitImpl ( PointLight light)
protectedvirtual

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

Reimplemented in WSGLLightsProcessor.

◆ visitImpl() [4/4]

bool visitImpl ( SpotLight light)
protectedvirtual

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

Reimplemented in WSGLLightsProcessor.