Using the ffgl library, if i try to activate more than sampler 0 and 1, it crashes.
Here is the code :
Code: Select all
static const char _fragmentShaderCode[] = R"(#version 410 core
uniform sampler2D inputTexture;
uniform sampler2D inputTexture2;
uniform sampler2D inputTexture3;
in vec2 uv;
in vec2 norm_uv;
out vec4 fragColor;
void main()
{
vec4 color = texture(inputTexture, uv);
vec4 mask = texture(inputTexture2, vec2(norm_uv.x, 1.0 - norm_uv.y));
fragColor = color * vec4(mask.r,mask.r,mask.r,mask.r);
}
)";
The2dMaskV2::The2dMaskV2()
{
SetMinInputs( 1 );
SetMaxInputs( 1 );
}
The2dMaskV2::~The2dMaskV2()
{
}
FFResult The2dMaskV2::InitGL( const FFGLViewportStruct* vp )
{
glGenTextures( 1, &maskTextureID1 );
if( maskTextureID1 == 0 )
return false;
glGenTextures( 1, &maskTextureID2 );
if( maskTextureID2 == 0 )
return false;
////////////////////////
if( !shader.Compile( _vertexShaderCode, _fragmentShaderCode ) )
{
DeInitGL();
return FF_FAIL;
}
if( !quad.Initialise() )
{
DeInitGL();
return FF_FAIL;
}
//Use base-class init as success result so that it retains the viewport.
return CFFGLPlugin::InitGL( vp );
}
FFResult The2dMaskV2::ProcessOpenGL( ProcessOpenGLStruct* pGL )
{
if( pGL->numInputTextures < 1 )
return FF_FAIL;
if( pGL->inputTextures[ 0 ] == NULL )
return FF_FAIL;
ScopedShaderBinding shaderBinding( shader.GetGLID() );
ScopedSamplerActivation activateSampler1( 0 );
Scoped2DTextureBinding textureBinding1( pGL->inputTextures[ 0 ]->Handle );
ScopedSamplerActivation activateSampler2( 1 );
Scoped2DTextureBinding textureBinding2( maskTextureID1 );
ScopedSamplerActivation activateSampler3( 2 );
Scoped2DTextureBinding textureBinding3( maskTextureID2 );
shader.Set( "inputTexture", 0 );
shader.Set( "inputTexture2", 1 );
shader.Set( "inputTexture3", 2 );
FFGLTexCoords maxCoords = GetMaxGLTexCoords( *pGL->inputTextures[ 0 ] );
shader.Set( "MaxUV", maxCoords.s, maxCoords.t );
SendParams( shader );
quad.Draw();
return FF_SUCCESS;
}