ImFusion SDK 4.3
GlExpr Class Referencefinal

#include <ImFusion/ImageMath/OpenGL/GlExpr.h>

Wrapper for using a ExprBase as GlAbstractInclude. More...

+ Inheritance diagram for GlExpr:

Detailed Description

Wrapper for using a ExprBase as GlAbstractInclude.

GlExpr provides GlAbstractInclude which can be used in a GlProgram. The GlAbstractInclude defines "EXPR" and a method with the following signature (see SharedImageSetArithmetic.glh)

vec4 exprVal(vec3 tc, vec4 varval, int index);

The index can be used in case of SharedImageSets in order to index the image you are evaluating. This class also provides setIndices() in order to choose which SharedImages of a SharedImageSet are supposed to be bound.

Example: SharedImageSetArithmetic.frag:

#version 400
in vec3 in_texCoord;
#ifdef EXPR_NUM_IMG
layout(location = 0) out vec4 out_color[EXPR_NUM_IMG];
#else
layout(location = 0) out vec4 out_color;
#endif
#pragma abstract_include "EXPR"
#ifndef EXPR
// default implementation if no definition was set
vec4 exprVal(vec3 tc, vec4 val, int index)
{
return vec4(0.0);
}
#endif
void main()
{
vec4 varVal = vec4(0.0);
#ifdef EXPR_NUM_IMG
#ifdef EXPR
for(int i = 0; i < EXPR_NUM_IMG; ++i)
out_color[i] = exprVal(in_texCoord, varVal, i);
#endif
#else
out_color = exprVal(in_texCoord, varVal, 0);
#endif
}

Now in c++ any expression can be used in this shader by:

SharedImage img(...);
auto expr2 = ...;
GlExpr wrapper(expr2);
auto program = std::make_unique<GL::ImageProgram>("ImFusionLib/ImageMath/SharedImageSetArithmetic.frag");
program->addAbstractIncludeDefinition(&wrapper);
program->enable();
wrapper.setIncludeArguments(*program);
program->compute(*img.gl());
program->unbindImages();
program->disable();
GLCHECK;
img.setDirtyGl();
Image shared on multiple devices.
Definition SharedImage.h:86
T make_unique(T... args)

Public Member Functions

 GlExpr (const internal::GlExprInterface &expr)
 
std::function< std::string(const std::string &)> includeCodeSubstitution () const override
 Replaces any occurrence of UNIFORMS_IMPL with the uniform definition and any occurrence of EXPR_IMPL with the actual expression.
 
int setIncludeArguments (GL::Program &p, const std::string &prefix="expr") const override
 
Fingerprint fingerprint () const override
 Provides a finger print of the include.
 
void setIndices (std::vector< int > indices)
 Set the indices which shall be considered in case of a SharedImageSet ()
 
int numRequiredSamplersPerIndex ()
 Returns how many samplers are required per index.
 
const internal::GlExprInterfaceexpr () const
 Get wrapped expression.
 
- 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::stringdefineName () const
 Returns the name of define used by this include.
 
const std::stringincludePath () const
 Returns the path to the included shader file.
 
virtual std::vector< AbstractInclude * > dependentIncludes () const
 Returns a list of dependent abstract includes that need to be included as well.
 
- Public Member Functions inherited from MultiIncludable< GlExpr >
std::shared_ptr< MultiIncludeTypecreateMultiInclude (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 "EXPR".
 
static std::string defineSuffix ()
 Returns "EXPR".
 

Additional Inherited Members

- Public Types inherited from MultiIncludable< GlExpr >
using MultiIncludeType
 Alias for type of a multi-include instance of the original include.
 
- Protected Member Functions inherited from MultiIncludable< GlExpr >
 MultiIncludable (GlExpr *crtpInstance, const std::string &baseToken, Flags< ShaderTextReplacement > replacementScheme)
 Instantiate and configure the MultiIncludable interface.
 

Member Function Documentation

◆ includeCodeSubstitution()

std::function< std::string(const std::string &)> includeCodeSubstitution ( ) const
overridevirtual

Replaces any occurrence of UNIFORMS_IMPL with the uniform definition and any occurrence of EXPR_IMPL with the actual expression.

Reimplemented from AbstractInclude.

◆ fingerprint()

Fingerprint fingerprint ( ) const
overridevirtual

Provides a finger print of the include.

If two finger prints are equal this means that the two includes provide the very same code substitution. It does NOT mean that the two includes are equal. In particular the result of setArguments can be different.

Reimplemented from AbstractInclude.


The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close