public override void SetTextureBlendMode( int stage, LayerBlendModeEx bm )
{
if ( stage >= _fixedFunctionTextureUnits )
{
//cant do this
return;
}
// Check to see if blending is supported
if ( !_rsCapabilities.HasCapability( Capabilities.TextureBlending ) )
return;
All src1op, src2op, cmd;
float[] cv1 = new float[ 4 ];
float[] cv2 = new float[ 4 ];
if ( bm.blendType == LayerBlendType.Color )
{
cv1[ 0 ] = bm.colorArg1.r;
cv1[ 1 ] = bm.colorArg1.g;
cv1[ 2 ] = bm.colorArg1.b;
cv1[ 3 ] = bm.colorArg1.a;
manualBlendColors[ stage, 0 ] = bm.colorArg1;
cv2[ 0 ] = bm.colorArg2.r;
cv2[ 1 ] = bm.colorArg2.g;
cv2[ 2 ] = bm.colorArg2.b;
cv2[ 3 ] = bm.colorArg2.a;
manualBlendColors[ stage, 1 ] = bm.colorArg2;
}
if ( bm.blendType == LayerBlendType.Alpha )
{
cv1[ 0 ] = manualBlendColors[ stage, 0 ].r;
cv1[ 1 ] = manualBlendColors[ stage, 0 ].g;
cv1[ 2 ] = manualBlendColors[ stage, 0 ].b;
cv1[ 3 ] = bm.alphaArg1;
cv2[ 0 ] = manualBlendColors[ stage, 1 ].r;
cv2[ 1 ] = manualBlendColors[ stage, 1 ].g;
cv2[ 2 ] = manualBlendColors[ stage, 1 ].b;
cv2[ 3 ] = bm.alphaArg2;
}
switch ( bm.source1 )
{
case LayerBlendSource.Current:
src1op = All.Previous;
break;
case LayerBlendSource.Texture:
src1op = All.Texture;
break;
case LayerBlendSource.Manual:
src1op = All.Constant;
break;
case LayerBlendSource.Diffuse:
src1op = All.PrimaryColor;
break;
case LayerBlendSource.Specular:
src1op = All.PrimaryColor;
break;
default:
src1op = 0;
break;
}
switch ( bm.source2 )
{
case LayerBlendSource.Current:
src2op = All.Previous;
break;
case LayerBlendSource.Texture:
src2op = All.Texture;
break;
case LayerBlendSource.Manual:
src2op = All.Constant;
break;
case LayerBlendSource.Diffuse:
src2op = All.PrimaryColor;
break;
case LayerBlendSource.Specular:
src2op = All.PrimaryColor;
break;
default:
src2op = 0;
break;
}
switch ( bm.operation )
{
case LayerBlendOperationEx.Source1:
cmd = All.Replace;
break;
case LayerBlendOperationEx.Source2:
cmd = All.Replace;
break;
case LayerBlendOperationEx.Modulate:
case LayerBlendOperationEx.ModulateX2:
case LayerBlendOperationEx.ModulateX4:
cmd = All.Modulate;
break;
case LayerBlendOperationEx.Add:
cmd = All.Add;
break;
case LayerBlendOperationEx.AddSigned:
cmd = All.AddSigned;
break;
case LayerBlendOperationEx.AddSmooth:
cmd = All.Interpolate;
break;
case LayerBlendOperationEx.Subtract:
cmd = All.Subtract;
break;
case LayerBlendOperationEx.BlendDiffuseAlpha:
case LayerBlendOperationEx.BlendCurrentAlpha:
case LayerBlendOperationEx.BlendManual:
case LayerBlendOperationEx.BlendTextureAlpha:
case LayerBlendOperationEx.BlendDiffuseColor:
cmd = All.Interpolate;
break;
case LayerBlendOperationEx.DotProduct:
bool cap = _rsCapabilities.HasCapability( Capabilities.Dot3 );
cmd = cap ? All.Dot3Rgb : All.Modulate;
break;
default:
cmd = 0;
break;
}
if ( !ActivateGLTextureUnit( 0 ) )
return;
OpenGL.TexEnv( All.TextureEnv, All.TextureEnvMode, (int)All.Combine );
GLESConfig.GlCheckError( this );
if ( bm.blendType == LayerBlendType.Color )
{
OpenGL.TexEnv( All.TextureEnv, All.CombineRgb, (int)cmd );
GLESConfig.GlCheckError( this );
OpenGL.TexEnv( All.TextureEnv, All.Src0Rgb, (int)src1op );
GLESConfig.GlCheckError( this );
OpenGL.TexEnv( All.TextureEnv, All.Src1Rgb, (int)src2op );
GLESConfig.GlCheckError( this );
OpenGL.TexEnv( All.TextureEnv, All.Src2Rgb, (int)All.Constant );
GLESConfig.GlCheckError( this );
}
else
{
OpenGL.TexEnv( All.TextureEnv, All.CombineAlpha, (int)cmd );
GLESConfig.GlCheckError( this );
OpenGL.TexEnv( All.TextureEnv, All.Src0Alpha, (int)src1op );
GLESConfig.GlCheckError( this );
OpenGL.TexEnv( All.TextureEnv, All.Src1Alpha, (int)src2op );
GLESConfig.GlCheckError( this );
OpenGL.TexEnv( All.TextureEnv, All.Src2Alpha, (int)All.Constant );
GLESConfig.GlCheckError( this );
}
float[] blendValue = new float[] { 0, 0, 0, bm.blendFactor };
switch ( bm.operation )
{
case LayerBlendOperationEx.BlendDiffuseColor:
case LayerBlendOperationEx.BlendDiffuseAlpha:
OpenGL.TexEnv( All.TextureEnv, All.Src2Rgb, (int)All.PrimaryColor );
GLESConfig.GlCheckError( this );
OpenGL.TexEnv( All.TextureEnv, All.Src2Alpha, (int)All.PrimaryColor );
GLESConfig.GlCheckError( this );
break;
case LayerBlendOperationEx.BlendTextureAlpha:
OpenGL.TexEnv( All.TextureEnv, All.Src2Rgb, (int)All.Texture );
GLESConfig.GlCheckError( this );
OpenGL.TexEnv( All.TextureEnv, All.Src2Alpha, (int)All.Texture );
GLESConfig.GlCheckError( this );
break;
case LayerBlendOperationEx.BlendCurrentAlpha:
OpenGL.TexEnv( All.TextureEnv, All.Src2Rgb, (int)All.Previous );
GLESConfig.GlCheckError( this );
OpenGL.TexEnv( All.TextureEnv, All.Src2Alpha, (int)All.Previous );
GLESConfig.GlCheckError( this );
break;
case LayerBlendOperationEx.BlendManual:
OpenGL.TexEnv( All.TextureEnv, All.TextureEnvColor, blendValue );
GLESConfig.GlCheckError( this );
break;
case LayerBlendOperationEx.ModulateX2:
OpenGL.TexEnv( All.TextureEnv, bm.blendType == LayerBlendType.Color ?
All.RgbScale : All.AlphaScale, 2 );
GLESConfig.GlCheckError( this );
break;
case LayerBlendOperationEx.ModulateX4:
OpenGL.TexEnv( All.TextureEnv, bm.blendType == LayerBlendType.Color ?
All.RgbScale : All.AlphaScale, 4 );
GLESConfig.GlCheckError( this );
break;
default:
break;
}
if ( bm.blendType == LayerBlendType.Color )
{
OpenGL.TexEnv( All.TextureEnv, All.Operand0Rgb, (int)All.SrcColor );
GLESConfig.GlCheckError( this );
OpenGL.TexEnv( All.TextureEnv, All.Operand1Rgb, (int)All.SrcColor );
if ( bm.operation == LayerBlendOperationEx.BlendDiffuseColor )
{
OpenGL.TexEnv( All.TextureEnv, All.Operand2Rgb, (int)All.SrcColor );
GLESConfig.GlCheckError( this );
}
else
{
OpenGL.TexEnv( All.TextureEnv, All.Operand2Rgb, (int)All.SrcAlpha );
GLESConfig.GlCheckError( this );
}
}
OpenGL.TexEnv( All.TextureEnv, All.Operand0Alpha, (int)All.SrcAlpha );
GLESConfig.GlCheckError( this );
OpenGL.TexEnv( All.TextureEnv, All.Operand1Alpha, (int)All.SrcAlpha );
GLESConfig.GlCheckError( this );
OpenGL.TexEnv( All.TextureEnv, All.Operand2Alpha, (int)All.SrcAlpha );
GLESConfig.GlCheckError( this );
if ( bm.source1 == LayerBlendSource.Manual )
OpenGL.TexEnv( All.TextureEnv, All.TextureEnvColor, cv1 );
if ( bm.source2 == LayerBlendSource.Manual )
OpenGL.TexEnv( All.TextureEnv, All.TextureEnvColor, cv2 );
GLESConfig.GlCheckError( this );
ActivateGLTextureUnit( 0 );
}
/// <summary>