![]() |
ImFusion SDK 4.3
|
#include <ImFusion/GL/GlMask.h>
Base interface for implementing polymorphic image masks using OpenGL. More...
Inheritance diagram for GlMask:Base interface for implementing polymorphic image masks using OpenGL.
Each subclass of a GlMask should directly correspond to a subclass of Mask and the GlMask instance should therefore only be exposed through the corresponding Mask object. Usually, concrete implementations inherit from both the Mask and the GlMask interfaces.
A GlMask should mirror the functionality of the Mask using the GL::AbstractInclude interface. The defineName is IMAGE_MASK and the include is expected to define a function with the following signature:
Which correlates to Mask::maskValue. For a complete example how to use such an include see Image Masks.
In order to use several different mask includes in the same shader, GlMask also implements the GL::MultiIncludable interface so that you can use the createMultiInclude() helper function to create variants with individual and unique prefixes.
Because of the way GL::MultiIncludable works (prefix text replacement) there are some additional requirements when subclassing GlMask: All uniform names have to start with "mask", such as
In setIncludeArguments() use the given prefix to access these uniform, i.e. in the previous example use
instead of
When creating a multi-include this prefix will be replaced by a given unique alternative (e.g mask1). Thus, all occurrences of mask in the shader code will be replaced by the alternative, e.g. maskOutsideValue will become mask1OutsideValue.
Public Member Functions | |
| GlMask (const std::string &includePath) | |
Instantiates a new GL::AbstractInclude using IMAGE_MASK as defineName and the given path the to retrieve the GLSL source code from. | |
| int | setIncludeArguments (GL::Program &p, const std::string &prefix="mask") const override=0 |
| Called by users of GlMask in order to correctly setup the mask shader. | |
| virtual std::unique_ptr< GlImage > | createExplicitMaskGl (const GlImage &inputImage, bool normalized=false) |
| Creates an explicit mask representation of this mask when applied to the given image. | |
Public Member Functions inherited from AbstractInclude | |
| AbstractInclude (const std::string &defineName, const std::string &includePath) | |
| Creates a AbstractInclude for the given define and with the corresponding GLSL file at includePath. | |
| const std::string & | defineName () const |
| Returns the name of define used by this include. | |
| const std::string & | includePath () const |
| Returns the path to the included shader file. | |
| virtual std::function< std::string(const std::string &)> | includeCodeSubstitution () const |
| Optionally the abstract include can provide a function to change the shader code. | |
| virtual std::vector< AbstractInclude * > | dependentIncludes () const |
| Returns a list of dependent abstract includes that need to be included as well. | |
| virtual Fingerprint | fingerprint () const |
| Provides a finger print of the include. | |
Public Member Functions inherited from MultiIncludable< GlMask > | |
| 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). | |
Static Public Member Functions | |
| static std::string | defineName () |
| Returns "IMAGE_MASK". | |
| static std::string | defineSuffix () |
| Returns "MASK". | |
| static std::string | multiIncludeDefine (const std::string &replacementToken) |
Returns "IMAGE_" + toUpper(replacementToken) | |
Additional Inherited Members | |
Public Types inherited from MultiIncludable< GlMask > | |
| using | MultiIncludeType |
| Alias for type of a multi-include instance of the original include. | |
Protected Member Functions inherited from MultiIncludable< GlMask > | |
| MultiIncludable (GlMask *crtpInstance, const std::string &baseToken, Flags< ShaderTextReplacement > replacementScheme) | |
| Instantiate and configure the MultiIncludable interface. | |
|
overridepure virtual |
Called by users of GlMask in order to correctly setup the mask shader.
Subclasses should implement this function so that it correctly sets all needed uniforms and input textures to be used by the OpenGL shader instance. Make sure to use the given prefix argument instead of a hardcoded "mask" when defining uniform names to support multi-includes where the prefixes have been replaced with unique alternatives. Example:
Implemented in CroppingMask, ExplicitIntensityMask, ExplicitMask, OperandMask< T >, IntensityMask, SkippingMask, and FanMask.
|
virtual |
Creates an explicit mask representation of this mask when applied to the given image.
| inputImage | Image to which the mask should be applied for each pixel in order to generate the explicit mask image. Must be compatible with the mask. |
| normalized | If the this parameter is true the resulting binary mask value will be created as CPU uint8_t values 0 and 255 (corresponding to 0 and 1 on the GPU), instead of 0 and 1 (0 and 1/255 on the GPU). |
Reimplemented in ExplicitIntensityMask, and ExplicitMask.