Library containing shader objects, allowing shader instances to be stored with identifiers.
More...
#include <Rendering/SceneComponents/Shaders/shaderlibrary.h>
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.
◆ ShaderLibrary() [1/2]
Creates an empty library.
◆ ShaderLibrary() [2/2]
- Parameters
-
lib | The 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()
The destructor destroys the library, but not the things it contains.
◆ add() [1/2]
bool add |
( |
const QString & |
id, |
|
|
Shader & |
shader |
|
) |
| |
- Parameters
-
id | The id to assign to this shader in the library. |
shader | The 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]
- Parameters
-
library | The 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()
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
-
id | The 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=()
◆ remove() [1/3]
bool remove |
( |
const QString & |
id | ) |
|
- Parameters
-
id | The 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
-
shader | The 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]
- Parameters
-
library | The 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.