Code: Select all
Plugin::~Plugin()
{
for( Param* param : params )
{
if(param != nullptr)
delete param;
}
}
Code: Select all
unsigned int uniformLocation;
Code: Select all
// FFGL.h
typedef FFUInt32 FFResult;
enum FFSuccessFail : FFResult
{
FF_SUCCESS = 0,
FF_FAIL = 0xFFFFFFFF
};
// Parameter usages
enum class FFParameterUsage : FFUInt32
{
FF_USAGE_STANDARD = 0,
FF_USAGE_FFT = 1,
FF_FAIL = FFSuccessFail::FF_FAIL
};
typedef union FFMixed
{
FFUInt32 UIntValue;
void* PointerValue;
float FloatValue;
double* pDouble;
const char* StrValue;
FFInputStatus InputStatus;
FFParameterType ParameterType;
FFParameterUsage ParameterUsage;
//...
} FFMixed;
// FFGLPluginManager.cpp
FFParameterUsage CFFGLPluginManager::GetParamUsage( unsigned int dwIndex ) const
{
const ParamInfo* paramInfo = GetParamInfo( dwIndex );
if( paramInfo == nullptr )
return FFParameterUsage::FF_FAIL;
return paramInfo->usage; // definition in FFGLPluginManager.h: FFParameterUsage usage;
}
// FFGL.cpp
FFParameterUsage getParameterUsage( unsigned int index )
{
if( s_pPrototype == NULL )
{
FFResult dwRet = initialise();
if( dwRet == FF_FAIL )
return FFParameterUsage::FF_FAIL;
}
return s_pPrototype->GetParamUsage( index );
}
FFMixed __stdcall plugMain( FFUInt32 functionCode, FFMixed inputValue, FFInstanceID instanceID )
{
//...
switch( (FFFunctionCode) functionCode )
{
//...
case FFFunctionCode::FF_GETPARAMETERUSAGE:
retval.ParameterUsage = getParameterUsage( inputValue.UIntValue );
break;
//...
}
return retval;
}
Code: Select all
result.UIntValue == FF_FAIL
Code: Select all
protected:
std::string uniformName;
GLint uniformLocation;
Code: Select all
AddRGBRangeParam( "Brightness", "adjustment", 0.0f, { -1.0f, 1.0f } );
Code: Select all
color.rgb += adjustment * mult;
Code: Select all
// ffgl/PluginManager.h
namespace ffgl
{
class PluginManager
{
public:
/// This function allows you to add a new parameter to the plugin. There is differents kind of
/// parameters available, Adding a parameter allows the plugin to be
/// aware of them, make them available to the host and take of all the communication with it.
/// It can also allow the plugin to automatically pass the current value of each parameter to the
/// shader before drawing (see ffglqs::Plugin::SendParams()).
/// \param param The parameter to add
void AddParam( ParamBase* param );
protected:
// Plugin parameters. ParamBase is used for polymorphism.
std::vector< ParamBase* > params;
Code: Select all
#pragma once
#include "ffgl/ParamOption.h"
#include "ffglquickstart/Effect.h"
#include "ffglquickstart/ParamHSBAStruct.h"
#include "ffglquickstart/ParamRGBStruct.h"
namespace spxl
{
namespace ffgl
{
namespace effect
{
class SubAdd : public ffglqs::Effect
{
public:
SubAdd();
~SubAdd();
void Update() override;
protected:
ffglqs::ParamRGBStruct adjustment;
ffglqs::ParamHSBAStruct col1;
ffglqs::ParamHSBAStruct col2;
::ffgl::ParamOption* testOption;
};
}// namespace effect
}// namespace ffgl
}// namespace spxl
Code: Select all
// spxlSubAdd Effect Plugin
// More or less the same result as the AddSubtract sample plugin, with extra parameters for testing purposes.
// The "multiplier" parameter is used to scale the R,G,B addition/subtraction.
// 2019-08-12 ffgl@subpixels.com
// - Created, based on AddSubbtract sample code
#include "spxlSubAdd.h"
#include "ffgl/ParamBool.h"
#include "ffgl/ParamBuffer.h"
#include "ffgl/ParamFloat.h"
#include "ffgl/ParamInteger.h"
#include "ffgl/ParamOption.h"
#include "ffgl/ParamRange.h"
#include "ffgl/ParamText.h"
#include "ffglquickstart/ParamEvent.h"
#include "ffglquickstart/ParamFFT.h"
#include "ffglquickstart/ParamTrigger.h"
using namespace ffgl;
using namespace ffglex;
using namespace ffglqs;
namespace spxl
{
namespace ffgl
{
namespace effect
{
static ::ffgl::PluginInfo pluginInfo(
PluginFactory< SubAdd >,// Create method
#ifdef _DEBUG
"?e01", // Plugin unique ID of maximum length 4.
"?SubAdd",// Plugin name
#else
"_e01", // Plugin unique ID of maximum length 4.
"_SubAdd",// Plugin name
#endif
2, // API major version number
1, // API minor version number
1, // Plugin major version number
0, // Plugin minor version number
PluginType::FF_EFFECT,// Plugin type
"Subtract and Add colours", // Plugin description
"Resolume FFGL Example (mod by ffgl@subpixels.com)"// About
);
static const char _fragmentShaderCode[] = R"(
void main()
{
vec4 color = texture( inputTexture, i_uv );
//The InputTexture contains premultiplied colors, so we need to unpremultiply first to apply our effect on straight colors.
if( color.a > 0.0 )
color.rgb /= color.a;
color.rgb += adjustment * mult;
if (TestBool) color.rgb += col1.rgb * factor1;
if (b2) color.rgb -= col2.rgb * factor2;
//The plugin has to output premultiplied colors, this is how we're premultiplying our straight color while also
//ensuring we aren't going out of the LDR the video engine is working in.
color.rgb = clamp( color.rgb * color.a, vec3( 0.0 ), vec3( color.a ) );
fragColor = color;
}
)";
SubAdd::SubAdd()
{
//We declare that this plugin has a Brightness parameter which is a RGB param.
//The name here must match the one you declared in your fragment shader.
adjustment = AddRGBRangeParam( "Brightness", "adjustment", 0.0f, { -1.0f, 1.0f } );
// Test Parameters
AddParam( new ParamFloat( "Col Mult", "mult", 1.0f ) );
col1 = AddHueColorParam( "MyColor1", "col1", { 0.0f, 1.0f, 0.75f, 1.0f } );
col2 = AddHueColorParam( "MyColor2", "col2", { 0.666667f, 0.9f, 1.0f, 0.5f } );
AddParam( new ParamFloat( "Scale 1", "factor1" ) );
AddParam( new ParamFloat( "Scale 2", "factor2", 0.25f ) );
AddParam( new ParamFloat( "NameTypeValue", ParameterType::FF_TYPE_BRIGHTNESS, 0.9f ) );
AddParam( new ParamBool( "TestBool" ) );
AddParam( new ParamBool( "TestBool2", "b2", true ) );
AddParam( new ParamEvent( "TestEvent" ) );
AddAudioParam( new ParamFFT( "TestFFT", 8 ) );
testOption = new ParamOption( "TestOption", 2U );
testOption->AddOption( { "Test1", 11.1f } );
testOption->AddOption( { "Test2", 22.2f } );
testOption->AddOption( { "Test3", 33.3f } );
AddParam( testOption );
AddParam( new ParamRange( "TestRange", "temperature", 27.5f, { 0.0f, 100.0f } ) );
AddParam( new ParamInteger( "TestInteger", "xscale", 64, { -1920.0f, 1920.0f } ) );
AddParam( new ParamText( "TestText", "Lorem ipsum blah blah amet" ) );
AddParam( new ParamTrigger( "TestTrigger" ) );
SetFragmentShader( _fragmentShaderCode );
SetTimeSupported( true );
}
SubAdd::~SubAdd()
{
}
void SubAdd::Update()
{
// Try out accessing parameter values
float r = adjustment.red->GetFloatValue();
float g = adjustment.green->GetFloatValue();
float b = adjustment.blue->GetFloatValue();
float average = ( r + g + b ) / 3.0f;
HSBAColor color1 = col1.GetColor();
HSBAColor color2 = col2.GetColor();
float hue1 = color1.hue;
std::string uniformName = col1.hue->GetUniformName();
FFUInt32 selectedOption = testOption->GetIndex();
std::string selectedName = testOption->GetOptionName( selectedOption );
float selectedValue;
FFResult res = testOption->GetOptionValue( selectedOption, selectedValue );
float selectedValueDirect = testOption->GetFloatValue();
}
}// namespace effect
}// namespace ffgl
}// namespace spxl