1#include "RenderEffect.h"
3#include "Rendering/IGraphicsDevice.h"
4#include "Rendering/IEffects.h"
5#include "Rendering/IBuffers.h"
7#include "Foundation/Logging/Logger.h"
11#include "Services/Variables.h"
12#include "Services/TaskManager.h"
14#include "Resources/Material.h"
17#include "RenderResources.h"
29 LOG_ERROR(logger,
"Error loading effect %s, definition:", effect->
getName().
data());
34 LOG_WARNING(logger,
"Could not create input layout for %.*s, definition:", StringViewFormat(effect->
getName()));
41 LOG_DEBUG(logger,
"+- #define %s %s", d.first.c_str(), d.second.c_str());
44 LOG_DEBUG(logger,
"+- No #define's");
48 LOG_DEBUG(logger,
" +- Vertex shader input semantic %.*s", StringViewFormat(ShaderInterfaceMemberDefinition::semanticNameString(i.semantic.name)));
50 if (effect->definition.vertexShader.shaderInterface.members.empty()) {
51 LOG_DEBUG(logger,
"+- No vertex shader input semantics");
69 Context* context = resources->getContext();
70 Renderer* renderer = resources->getRenderer();
72 const bool updateAsync = context->
variables->get(
"resources.effects.updateAsync",
false);
78 effectHandle = queuedEffectHandle;
81 inputHandle = queuedInputHandle;
87 if (!checkAndLogEffectLoad(effect, effectHandle, inputHandle)) {
102 incrementGeneration();
112 description.
vertexShader = effect->definition.vertexShader.loadPath;
113 description.
hullShader = effect->definition.hullShader.loadPath;
114 description.
domainShader = effect->definition.domainShader.loadPath;
115 description.
geometryShader = effect->definition.geometryShader.loadPath;
116 description.
pixelShader = effect->definition.pixelShader.loadPath;
121 queuedEffectHandle = effects->
loadEffect(description);
122 queuedInputHandle = queuedEffectHandle
144 description.
vertexShader = effect->definition.vertexShader.loadPath;
145 description.
hullShader = effect->definition.hullShader.loadPath;
146 description.
domainShader = effect->definition.domainShader.loadPath;
147 description.
geometryShader = effect->definition.geometryShader.loadPath;
148 description.
pixelShader = effect->definition.pixelShader.loadPath;
156 effectHandle = effects->
loadEffect(description);
159 LOG_ERROR(logger,
"Error loading effect %s.", effect->
getName().
data());
179 LOG_ERROR(logger,
"Error loading effect %s.", effect->
getName().
data());
199 if (!checkAndLogEffectLoad(effect, effectHandle, inputHandle)) {
200 LOG_ERROR(logger,
"Error loading effect %s.", effect->
getName().
data());
224void Cogs::Core::RenderEffect::release(
Renderer * renderer)
242void Cogs::Core::RenderEffect::requestLoad()
244 getResource()->delayLoad =
false;
245 getResource()->setChanged();
A Context instance contains all the services, systems and runtime components needed to use Cogs.
std::unique_ptr< class TaskManager > taskManager
TaskManager service instance.
std::unique_ptr< class Variables > variables
Variables service instance.
Contains render resources used by the renderer.
IGraphicsDevice * getDevice() override
Get the graphics device used by the renderer.
EffectFlags::EEffectFlags getEffectFlags() const override
Get the EffectFlags.
static constexpr TaskQueueId ResourceQueue
Resource task queue.
Represents a graphics device used to manage graphics resources and issue drawing commands.
virtual IEffects * getEffects()=0
Get a pointer to the effect management interface.
virtual IBuffers * getBuffers()=0
Get a pointer to the buffer management interface.
Log implementation class.
constexpr const char * data() const noexcept
Get the sequence of characters referenced by the string view.
static constexpr size_t NoPosition
No position.
size_t find(const StringView &other, size_t offset=0) const noexcept
Find the given string segment inside the string.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
ActivationResult
Defines results for resource activation.
@ Success
Resource activated successfully.
@ Delayed
Delayed activation.
@ Postponed
Resource activation postponed, retry later.
@ Failure
Resource activation failed.
bool HandleIsValid(const ResourceHandle_t< T > &handle)
Check if the given resource is valid, that is not equal to NoHandle or InvalidHandle.
constexpr Log getLogger(const char(&name)[LEN]) noexcept
@ Pending
The resource is still loading.
@ Error
The resource failed to load.
@ Ready
The resource has loaded successfully and is ready for use.
std::pair< std::string, std::string > PreprocessorDefinition
Preprocessor definition.
MeshStreamsLayout streamsLayout
The vertex layout this effect expects.
PreprocessorDefinitions definitions
Preprocessor definitions.
BindGroupSetDescription bindGroupLayouts
Optional backend-neutral bind-group layout metadata, typically emitted by shader builders.
Effect resources contain data to control the shader stages of the GPU pipeline.
bool delayLoad
If the effect should be loaded or delayed.
struct Material * material
Owning material resource.
VertexFormatHandle vertexFormats[maxStreams]
void logLayout(Cogs::Logging::Log &logger) const
StringView getName() const
Get the name of the resource.
bool isValid() const
Check if the task id is valid.
Contains an effect description used to load a single effect.
EffectFlags::EEffectFlags flags
Effect loading flags.
StringView geometryShader
Geometry shader file name or source.
BindGroupSetDescription bindGroupLayoutDesc
Optional bind-group layout metadata. Backends may use this instead of source introspection.
StringView domainShader
Domain shader file name or source.
PreprocessorDefinitions definitions
Definitions.
StringView vertexShader
Vertex shader file name or source.
StringView name
Name of the effect. Used for tracking purposes, like naming shader dumps.
StringView pixelShader
Pixel shader file name or source.
StringView hullShader
Hull shader file name or source.
EEffectFlags
Effect source flags.
@ GLSL
Effect source is GLSL.
static const Handle_t NoHandle
Represents a handle to nothing.
Provides buffer management functionality.
virtual InputLayoutHandle loadInputLayout(const VertexFormatHandle *vertexFormats, const size_t count, EffectHandle effectHandle)=0
Loads a new input layout to map vertex flow between vertex buffers with the given vertexFormats to ef...
virtual void releaseInputLayout(InputLayoutHandle inputLayoutHandle)=0
Releases the input layout with the given inputLayoutHandle.
Provides effects and shader management functionality.
virtual void releaseEffect(EffectHandle effectHandle)=0
Release the effect with the given handle, freeing all resources generated during program loading.
virtual EffectHandle loadEffect(const EffectDescription &description)=0
Load an effect from the given description.
virtual ResourceStatus checkEffect(EffectHandle effectHandle)=0
Check the load status of the effect with the given effectHandle.