Cogs.Rendering
Loading...
Searching...
No Matches
IEffects.h
Go to the documentation of this file.
1#pragma once
2
3#include "VertexFormat.h"
4
5#include "Foundation/StringView.h"
6
7namespace Cogs
8{
10 typedef std::pair<std::string, std::string> PreprocessorDefinition;
11
13 typedef std::vector<PreprocessorDefinition> PreprocessorDefinitions;
14
17 {
20 {
22 None = 0,
24 HLSL = 0x1,
26 GLSL = 0x2,
30 Pinned = 0x8,
36 WGSL = 0x40,
37 };
38 };
39
44 {
46 File,
48 Source,
49 };
50
55 {
57 StringView vertexShader;
58
60 StringView hullShader;
61
63 StringView domainShader;
64
66 StringView geometryShader;
67
69 StringView pixelShader;
70
72 StringView effect;
73
75 StringView vsEntryPoint;
76
78 StringView hsEntryPoint;
79
81 StringView dsEntryPoint;
82
84 StringView gsEntryPoint;
85
87 StringView psEntryPoint;
88
90 StringView name;
91
94
97
100 };
101
106 {
107 virtual ~IIOHandler() {}
108
115 virtual bool openFile(const StringView & fileName, std::string & content) = 0;
116
125 virtual bool resolveFile(const StringView & source, const StringView & fileName, std::string & content) = 0;
126
127 enum class FileType
128 {
129 ShaderDump = 0,
132 };
133
134 virtual bool exists(FileType type, const StringView & fileName) = 0;
135
136 virtual bool writeBinaryFile(FileType type, const StringView & fileName, const void * content, size_t contentSize) = 0;
137 virtual bool openBinaryFile(FileType type, const StringView & fileName, std::vector<uint8_t> & content) = 0;
138
139 virtual void pushSearchPaths() = 0;
140 virtual void addSearchPath(const StringView & path) = 0;
141 virtual void popSearchPaths() = 0;
142 };
143
147 struct IEffects
148 {
156 virtual EffectHandle loadEffect(const EffectDescription & description) = 0;
157
164 virtual EffectHandle loadEffect(const StringView & fileName, EffectFlags::EEffectFlags effectFlags = EffectFlags::None) = 0;
165
172 virtual EffectHandle loadComputeEffect(const StringView & fileName, EffectFlags::EEffectFlags effectFlags = EffectFlags::None) = 0;
173
181 virtual EffectHandle loadComputeEffect(const StringView & fileName, const PreprocessorDefinitions & definitions, EffectFlags::EEffectFlags effectFlags = EffectFlags::None) = 0;
182
190 virtual EffectHandle loadEffect(const StringView & vsFileName, const StringView & psFileName, EffectFlags::EEffectFlags effectFlags = EffectFlags::None) = 0;
191
200 virtual EffectHandle loadEffect(const StringView & vsFileName, const StringView & psFileName, const PreprocessorDefinitions & definitions, EffectFlags::EEffectFlags effectFlags = EffectFlags::None) = 0;
201
210 virtual EffectHandle loadEffectSource(const StringView & vsSource, const StringView & psSource, EffectFlags::EEffectFlags effectFlags = EffectFlags::None) = 0;
211
221 virtual EffectHandle loadEffectSource(const StringView & vsSource, const StringView & gsSource, const StringView & psSource, EffectFlags::EEffectFlags effectFlags = EffectFlags::None) = 0;
222
232 virtual EffectHandle loadEffectSource(const StringView & vsSource, const StringView & psSource, const PreprocessorDefinitions & definitions, EffectFlags::EEffectFlags effectFlags = EffectFlags::None) = 0;
233
244 virtual EffectHandle loadEffectSource(const StringView & vsSource, const StringView & gsSource, const StringView & psSource, const PreprocessorDefinitions & definitions, EffectFlags::EEffectFlags effectFlags = EffectFlags::None) = 0;
245
251 virtual void releaseEffect(EffectHandle effectHandle) = 0;
252
260 virtual EffectVariableHandle getEffectVariable(EffectHandle effectHandle, const StringView & name) = 0;
261
271 virtual ConstantBufferBindingHandle getConstantBufferBinding(EffectHandle effectHandle, const StringView & name) = 0;
272
284 virtual TextureBindingHandle getTextureBinding(EffectHandle effectHandle, const StringView & name, const unsigned int slot) = 0;
285
289 virtual BufferBindingHandle getBufferBinding(EffectHandle effectHandle, const StringView & name) = 0;
290
294 virtual void releaseBufferBinding(BufferBindingHandle bufferBindingHandle) = 0;
295
310 virtual SamplerStateBindingHandle getSamplerStateBinding(EffectHandle effectHandle, const StringView & name, const unsigned int slot) = 0;
311
315 virtual void releaseResources() = 0;
316
320 virtual void annotate(EffectHandle handle, const StringView & name) { (void)handle; (void)name; }
321
325 virtual void annotateVS(EffectHandle handle, const StringView & name) { (void)handle; (void)name; }
326
330 virtual void annotateGS(EffectHandle handle, const StringView & name) { (void)handle; (void)name; }
331
335 virtual void annotatePS(EffectHandle handle, const StringView & name) { (void)handle; (void)name; }
336
340 virtual void annotateCS(EffectHandle handle, const StringView & name) { (void)handle; (void)name; }
341
347 virtual void setIOHandler(IIOHandler * handler) = 0;
348
352 virtual IIOHandler * getIOHandler() { return nullptr; }
353 };
354}
Definition: Base.h:24
std::pair< std::string, std::string > PreprocessorDefinition
Preprocessor definition.
Definition: IEffects.h:10
EffectDescriptionType
Type of contents in effect description.
Definition: IEffects.h:44
std::vector< PreprocessorDefinition > PreprocessorDefinitions
A set of preprocessor definitions.
Definition: IEffects.h:13
Contains an effect description used to load a single effect.
Definition: IEffects.h:55
StringView hsEntryPoint
Entry point of the hull shader.
Definition: IEffects.h:78
StringView gsEntryPoint
Entry point of the geometry shader.
Definition: IEffects.h:84
EffectFlags::EEffectFlags flags
Effect loading flags.
Definition: IEffects.h:96
StringView geometryShader
Geometry shader file name or source.
Definition: IEffects.h:66
StringView vsEntryPoint
Entry point of the vertex shader.
Definition: IEffects.h:75
StringView effect
Effect file name or source.
Definition: IEffects.h:72
StringView domainShader
Domain shader file name or source.
Definition: IEffects.h:63
StringView dsEntryPoint
Entry point of the domain shader.
Definition: IEffects.h:81
PreprocessorDefinitions definitions
Definitions.
Definition: IEffects.h:93
StringView vertexShader
Vertex shader file name or source.
Definition: IEffects.h:57
StringView name
Name of the effect. Used for tracking purposes, like naming shader dumps.
Definition: IEffects.h:90
StringView psEntryPoint
Entry point of the pixel shader.
Definition: IEffects.h:87
EffectDescriptionType type
Type of effect description. Defaults to file names.
Definition: IEffects.h:99
StringView pixelShader
Pixel shader file name or source.
Definition: IEffects.h:69
StringView hullShader
Hull shader file name or source.
Definition: IEffects.h:60
Flags used to describe effect source.
Definition: IEffects.h:17
EEffectFlags
Effect source flags.
Definition: IEffects.h:20
@ LogShaderSource
Log the contents of the shader on error.
Definition: IEffects.h:34
@ HLSL
Effect source is HLSL.
Definition: IEffects.h:24
@ WGSL
Effect source is WGSL.
Definition: IEffects.h:36
@ None
None.
Definition: IEffects.h:22
@ LogShaderInfo
Log detailed info about shaders.
Definition: IEffects.h:32
@ GeometryShader
Effect source contains geometry shader.
Definition: IEffects.h:28
@ GLSL
Effect source is GLSL.
Definition: IEffects.h:26
@ Pinned
Effect can only be released explicitly, not using releaseResources().
Definition: IEffects.h:30
Handle template class used to provide opaque, non-converting handles.
Definition: Common.h:22
Provides effects and shader management functionality.
Definition: IEffects.h:148
virtual SamplerStateBindingHandle getSamplerStateBinding(EffectHandle effectHandle, const StringView &name, const unsigned int slot)=0
Get a handle to a sampler state object binding, mapping how to bind the sampler state to the given ef...
virtual void annotatePS(EffectHandle handle, const StringView &name)
Associate a name with an object for use in graphics debugging.
Definition: IEffects.h:335
virtual EffectHandle loadEffectSource(const StringView &vsSource, const StringView &psSource, const PreprocessorDefinitions &definitions, EffectFlags::EEffectFlags effectFlags=EffectFlags::None)=0
Load an effect created from the vertex and pixel shader sources given, applying the given preprocesso...
virtual ConstantBufferBindingHandle getConstantBufferBinding(EffectHandle effectHandle, const StringView &name)=0
Get a handle to a constant buffer binding, mapping how to bind a constant buffer to the given effect.
virtual EffectHandle loadComputeEffect(const StringView &fileName, EffectFlags::EEffectFlags effectFlags=EffectFlags::None)=0
Load the compute shader with the given file name and create an effect.
virtual EffectHandle loadEffectSource(const StringView &vsSource, const StringView &gsSource, const StringView &psSource, EffectFlags::EEffectFlags effectFlags=EffectFlags::None)=0
Load an effect created from the vertex, geometry, and pixel shader sources given.
virtual TextureBindingHandle getTextureBinding(EffectHandle effectHandle, const StringView &name, const unsigned int slot)=0
Get a handle to a texture object binding, mapping how to bind textures to the given effect.
virtual EffectHandle loadEffect(const StringView &fileName, EffectFlags::EEffectFlags effectFlags=EffectFlags::None)=0
Load the given single file effect.
virtual BufferBindingHandle getBufferBinding(EffectHandle effectHandle, const StringView &name)=0
Get a handle to a buffer binding.
virtual void releaseResources()=0
Release all allocated effect resources.
virtual EffectHandle loadEffectSource(const StringView &vsSource, const StringView &gsSource, const StringView &psSource, const PreprocessorDefinitions &definitions, EffectFlags::EEffectFlags effectFlags=EffectFlags::None)=0
Load an effect created from the vertex, geometry, and pixel shader sources given, applying the given ...
virtual void releaseEffect(EffectHandle effectHandle)=0
Release the effect with the given handle, freeing all resources generated during program loading.
virtual EffectHandle loadEffectSource(const StringView &vsSource, const StringView &psSource, EffectFlags::EEffectFlags effectFlags=EffectFlags::None)=0
Load an effect created from the vertex and pixel shader sources given.
virtual void annotateCS(EffectHandle handle, const StringView &name)
Associate a name with an object for use in graphics debugging.
Definition: IEffects.h:340
virtual EffectHandle loadEffect(const StringView &vsFileName, const StringView &psFileName, const PreprocessorDefinitions &definitions, EffectFlags::EEffectFlags effectFlags=EffectFlags::None)=0
Load an effect created from the vertex and pixel shader files given, applying the given preprocessor ...
virtual EffectHandle loadEffect(const StringView &vsFileName, const StringView &psFileName, EffectFlags::EEffectFlags effectFlags=EffectFlags::None)=0
Load an effect created from the vertex and pixel shader files given.
virtual IIOHandler * getIOHandler()
Gets the external I/O handler.
Definition: IEffects.h:352
virtual void annotateVS(EffectHandle handle, const StringView &name)
Associate a name with an object for use in graphics debugging.
Definition: IEffects.h:325
virtual void releaseBufferBinding(BufferBindingHandle bufferBindingHandle)=0
Release a handle to a buffer binding.
virtual EffectVariableHandle getEffectVariable(EffectHandle effectHandle, const StringView &name)=0
Get a handle to the variable with the given name in the effect with the given effectHandle.
virtual EffectHandle loadEffect(const EffectDescription &description)=0
Load an effect from the given description.
virtual void annotateGS(EffectHandle handle, const StringView &name)
Associate a name with an object for use in graphics debugging.
Definition: IEffects.h:330
virtual EffectHandle loadComputeEffect(const StringView &fileName, const PreprocessorDefinitions &definitions, EffectFlags::EEffectFlags effectFlags=EffectFlags::None)=0
Load the compute shader with the given file name and create an effect.
virtual void annotate(EffectHandle handle, const StringView &name)
Associate a name with an object for use in graphics debugging.
Definition: IEffects.h:320
virtual void setIOHandler(IIOHandler *handler)=0
Sets an external I/O handler to use for I/O operations.
I/O handler.
Definition: IEffects.h:106
virtual void addSearchPath(const StringView &path)=0
virtual ~IIOHandler()
Definition: IEffects.h:107
virtual bool resolveFile(const StringView &source, const StringView &fileName, std::string &content)=0
Callback method used to resolve include statements in shader code and get the contents to include.
virtual void pushSearchPaths()=0
FileType
Definition: IEffects.h:128
virtual void popSearchPaths()=0
virtual bool writeBinaryFile(FileType type, const StringView &fileName, const void *content, size_t contentSize)=0
virtual bool openFile(const StringView &fileName, std::string &content)=0
Callback method used to open files.
virtual bool exists(FileType type, const StringView &fileName)=0
virtual bool openBinaryFile(FileType type, const StringView &fileName, std::vector< uint8_t > &content)=0