1#include "EffectManager.h"
3#include "Rendering/IGraphicsDevice.h"
4#include "Rendering/IEffects.h"
6#include "Foundation/Logging/Logger.h"
8#include "Renderer/IRenderer.h"
10#include "Services/Variables.h"
12#include "ResourceStore.h"
16#include "ShaderBuilder.h"
25 reportLeaks(
"Effect");
30 auto & dataDir = context->resourceStore->getDataDir();
32 context->resourceStore->addSearchPath(dataDir +
"Shaders/");
33 context->resourceStore->addSearchPath(
"Shaders/");
34 context->resourceStore->addSearchPath(
"shaders/");
39 bool preLoad = context->variables->get(
"resources.effects.preLoad",
false);
42 if (!context->resourceStore->hasResources(loadInfo->
dependencies)) {
44 context->resourceStore->preloadResources(loadInfo->
dependencies);
49 queueResource(loadInfo);
55 auto effect = get(loadInfo->
handle);
56 effect->definition = std::move(loadInfo->
definition);
58 auto & definition = effect->definition;
60 if(definition.vertexShader.loadPath.find(extension) == std::string::npos) {
62 if (definition.vertexShader.loadPath.size()) {
63 definition.vertexShader.loadPath += extension;
66 if (definition.hullShader.loadPath.size()) {
67 definition.hullShader.loadPath += extension;
70 if (definition.domainShader.loadPath.size()) {
71 definition.domainShader.loadPath += extension;
74 if (definition.geometryShader.loadPath.size()) {
75 definition.geometryShader.loadPath += extension;
78 if (definition.pixelShader.loadPath.size()) {
79 definition.pixelShader.loadPath += extension;
83 setProcessed(loadInfo);
90 auto & loadInfo = *createLoadInfo();
91 loadInfo.resourceId = effect->getId();
92 loadInfo.resourcePath = effect->getSource().to_string();
93 loadInfo.resourceName = effect->getName().to_string();
95 loadInfo.handle = handle;
96 loadInfo.definition = effect->definition;
98 loadResource(&loadInfo);
103 return context->renderer->getResources()->updateResource(handle);
108 switch (context->renderer->getDevice()->getType()) {
110 extension =
".es30.glsl";
124 loadInfo.
dependencies.emplace_back(
"Shaders/" + d + extension);
127 if (definition.vertexShader.loadPath.size()) {
128 loadInfo.
dependencies.emplace_back(
"Shaders/" + definition.vertexShader.loadPath + extension);
131 if (definition.pixelShader.loadPath.size()) {
132 loadInfo.
dependencies.emplace_back(
"Shaders/" + definition.pixelShader.loadPath + extension);
135 return loadResource(&loadInfo);
140 context->renderer->getResources()->releaseResource(resource);
void handleLoad(EffectLoadInfo *loadInfo) override
Overridden to handle effect loading.
ActivationResult handleActivation(EffectHandle handle, Effect *effect) override
Overridden to handle effect activation, updating the effect in the renderer.
void initialize() override
Initialize the effect manager.
EffectHandle loadEffect(const EffectDefinition &definition)
Load the effect described by the given definition.
~EffectManager()
Destructs the EffectManager.
void handleDeletion(Effect *resource) override
Overridden to handle deletion, removing the effect resource from the renderer.
Log implementation class.
ActivationResult
Defines results for resource activation.
constexpr Log getLogger(const char(&name)[LEN]) noexcept
@ OpenGLES30
Graphics device using the OpenGLES 3.0 API.
@ WebGPU
Graphics device using the WebGPU API Backend.
Defines a loadable effect.
std::string name
Name of the effect.
std::vector< std::string > dependencies
Load information for Effect resources.
std::vector< std::string > dependencies
Paths to all dependencies that need to be resident before activating the effect.
EffectDefinition definition
Definition of the effect and its dependencies.
bool preloading
If the effect is currently in the preloading phase, still resolving dependencies.
Effect resources contain data to control the shader stages of the GPU pipeline.
Resource handle base class handling reference counting of resources derived from ResourceBase.
std::string resourceName
Desired resource name. If no name is given, a default name will be chosen.
ResourceHandleBase handle
Handle to resource structure for holding actual resource data.