![]() |
ImFusion SDK 4.3
|
#include <ImFusion/Core/GL/MultiAbstractInclude.h>
Multi-AbstractIncludes allow for using multiple instances of the same AbstractInclude type in one shader. More...
Multi-AbstractIncludes allow for using multiple instances of the same AbstractInclude type in one shader.
Inherit from this class to enable multiple instances of your AbstractIncludes in one shader. To avoid symbol conflicts this interface will perform a simple text replacement in the corresponding shader code: all occurrences of a baseToken will be replaced with a token specified by the user when instantiating the Multi-Include.
Since using multiple instances of the same include type in one shader requires having unique uniform names per multi-include and these uniform names need to be referenced from the C++ side, this interface provides the virtual setIncludeArguments() function: Its function arguments are defined by second variadic template argument IncludeArgumentsTypes
of this class. Its final argument token
references the unique per-multi-include token and will automatically be computed by the Multi-Include logic, so that you can use it to define uniform names:
A user can request a Multi-Include instance by calling createMultiInclude() and add those to the Program instead of the base include instance. This is the place where the user has to define a unique replacement token so that defines, uniforms, and functions of the multi-shader include instances are unique and the final shader does compile.
Given this original shader code:
adding the two multi-includes will expand it to:
BaseIncludeType | Type of the concrete AbstractInclude that implements this interface (CRTP pattern), must also implement the AbstractInclude interface. |
IncludeArgumentsTypes | Optional Template pack describing the arguments that the user needs to pass to setIncludeArguments() in order to configure the include/corresponding shader. |
Public Types | |
using | MultiIncludeType = MultiAbstractInclude<BaseIncludeType, IncludeArgumentsTypes...> |
Alias for type of a multi-include instance of the original include. | |
Public Member Functions | |
std::shared_ptr< MultiIncludeType > | createMultiInclude (const std::string &replacementToken) |
Instantiates a new AbstractInclude instance where all occurrences of baseToken provided during construction are replaces with replacementToken according to the specified replacementScheme. | |
virtual int | setIncludeArguments (Program &prog, IncludeArgumentsTypes... includeArgs, const std::string &token) const =0 |
Interface that multi includes should use to configure the shader include (such as setting uniforms, binding textures, etc). | |
Protected Member Functions | |
MultiIncludable (BaseIncludeType *crtpInstance, const std::string &baseToken, Flags< ShaderTextReplacement > replacementScheme) | |
Instantiate and configure the MultiIncludable interface. | |
|
inlineprotected |
Instantiate and configure the MultiIncludable interface.
crtpInstance | Pointer to the concrete instance implementing this interface (usually this ) |
baseToken | Text fragment that will be replaced with the token specified in createMultiInclude() in order to generate unique shader code/variables. Make sure that the token is part of the base include's define name and to choose a sufficiently unique token to avoid replacing unwanted code. |
replacementScheme | Bitfield enumeration describing how to perform the text replacement in the include shader code. Text replacement of the include's define name is always performed using AllUppercase only. |
|
pure virtual |
Interface that multi includes should use to configure the shader include (such as setting uniforms, binding textures, etc).
The return value shall indicate the number of textures bound to the program.
prog | Shader instance to configure |
includeArgs | List of custom arguments the user needs to provide in order to configure the include |
token | Text fragment to distinguish multiple include instances: The MultiIncludable framework will ensure that this contains the replacement token of a concrete multi include instance. |