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

Library containing shader objects, allowing shader instances to be stored with identifiers. More...

#include <Rendering/SceneComponents/Shaders/shaderlibrary.h>

Public Member Functions

 ShaderLibrary ()
 
 ShaderLibrary (const ShaderLibrary &)
 
virtual ~ShaderLibrary ()
 
bool add (const QString &id, Shader &shader)
 
bool add (ShaderLibrary &library)
 
void clearShaders ()
 
void clearSubLibraries ()
 
ShadergetShader (const QString &id)
 
ShaderLibraryoperator= (const ShaderLibrary &lib)
 
bool remove (const QString &id)
 
bool remove (Shader &shader)
 
bool remove (ShaderLibrary &library)
 

Detailed Description

The main purpose of this class is to provide a single place from which clients can retrieve a Shader with a given id. A ShaderLibrary can hold other ShaderLibrary instances, searching recursively (depth first) for a requested shader id.

Constructor & Destructor Documentation

◆ ShaderLibrary() [1/2]

Creates an empty library.

◆ ShaderLibrary() [2/2]

ShaderLibrary ( const ShaderLibrary lib)
Parameters
libThe library to make a copy of.

When lib is copied, the items it contains are not copied. Instead, the new ShaderLibrary instance will hold references to the same things as lib. Therefore, the client needs to ensure that these contents remain valid for as long as the copy is in use. In particular, if lib is rebuilt as a result of a workspace operation's inputs being updated, the original copy of it should also be updated to prevent that copy from trying to use objects which might no longer exist.

◆ ~ShaderLibrary()

~ShaderLibrary ( )
virtual

The destructor destroys the library, but not the things it contains.

Member Function Documentation

◆ add() [1/2]

bool add ( const QString &  id,
Shader shader 
)
Parameters
idThe id to assign to this shader in the library.
shaderThe shader to add to the library.

If a shader with the same id as shader is already present in the library, this function will not add shader. Instead, the old shader is retained and the function returns false. Note that this test is only performed for shaders held directly by this library, not for any of the sub-libraries it also might hold. This allows a library to provide shaders which override those specified in any sub-libraries.

Returns
True if shader could be added.

◆ add() [2/2]

bool add ( ShaderLibrary library)
Parameters
libraryThe sub-library to add to this library.
Returns
True if library could be added or false if it is already a direct sub-library of this one.

◆ clearShaders()

void clearShaders ( )

Clears all shaders from the library. Note that the shaders are not deleted. This function merely clears the list of shaders the library keeps internally.

◆ clearSubLibraries()

void clearSubLibraries ( )

Clears all sub-libraries from this library. Note that the sub-libraries are not deleted. This function merely clears the list of sub-libraries this library keeps internally.

◆ getShader()

Shader * getShader ( const QString &  id)
Parameters
idThe id of the shader to retrieve.
Returns
The shader corresponding to the specified id, or a null pointer if no such shader could be found. Searches sub-libraries in a depth-first manner. The first shader matching id is always returned whether or not the shader is able to be used successfully.

◆ operator=()

ShaderLibrary & operator= ( const ShaderLibrary lib)
Parameters
libThe library to assign to this one.

See the comments for ShaderLibrary(const ShaderLibrary&), since they also apply here.

Returns
A reference to this object.

◆ remove() [1/3]

bool remove ( const QString &  id)
Parameters
idThe id of the shader to remove from the library.
Returns
True if a shader exists in the library with the specified id and it could be removed.

◆ remove() [2/3]

bool remove ( Shader shader)
Parameters
shaderThe shader to remove from the library.

Note that this function is slower than the remove(const String&) version due to how the data is stored internally. Access is optimized for lookups based on the id string, so searching for a particular shader object is O(n) where n is the number of shader this library holds directly (but is not affected by any sub-libraries).

Returns
True if shader exists in the library and could be removed.

◆ remove() [3/3]

bool remove ( ShaderLibrary library)
Parameters
libraryThe sub-library to remove from this library.
Returns
True if library is a sub-library directly held by this library and it could be removed. It will not be removed if it is not an immediate sub-library but is held more deeply in the sub-library hierachy.