I cannot say I really understood how all this Source/Dest Blending stuff really works (all these values confuse me) but I was able to McGyver a solution that works in OpenGL, DX9 and DX11.
I added another Blendingeffect to Aspyhre.Canvas called beEraser.
In OpenGL.Canvas i added :
Code:
beEraser:
glBlendFuncSeparate(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
In DirectX9.canvas :
Code:
beEraser:
with D3D9Device do
begin
SetRenderState(D3DRS_SRCBLENDALPHA, D3DBLEND_ZERO);
SetRenderState(D3DRS_DESTBLENDALPHA, D3DBLEND_INVSRCALPHA);
SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ZERO);
SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
end;
In DirectX11.Types i had to duplicate the function DX11CreateBasicBlendState so that alpha blend values can be changed :
Code:
function DX11CreateBasicBlendStateAlpha(SrcBlend, DestBlend,SrcAlpha,DestAlpha: D3D11_BLEND;
out BlendState: ID3D11BlendState): Boolean;
var
Desc: D3D11_BLEND_DESC;
begin
if (not Assigned(D3D11Device)) then
begin
BlendState:= nil;
Result:= False;
Exit;
end;
FillChar(Desc, SizeOf(D3D11_BLEND_DESC), 0);
Desc.RenderTarget[0].BlendEnable:= True;
Desc.RenderTarget[0].SrcBlend := SrcBlend;
Desc.RenderTarget[0].DestBlend:= DestBlend;
Desc.RenderTarget[0].BlendOp := D3D11_BLEND_OP_ADD;
Desc.RenderTarget[0].SrcBlendAlpha := SrcAlpha; //These 2 were predefined and could not be changed in the original function
Desc.RenderTarget[0].DestBlendAlpha:= DestAlpha;
Desc.RenderTarget[0].BlendOpAlpha := D3D11_BLEND_OP_ADD;
Desc.RenderTarget[0].RenderTargetWriteMask:= Ord(D3D11_COLOR_WRITE_ENABLE_ALL);
PushClearFPUState();
try
Result:= Succeeded(D3D11Device.CreateBlendState(Desc, BlendState));
finally
PopFPUState();
end;
if (not Result) then BlendState:= nil;
end;
and finally in directx11.canvas :
Code:
// "Eraser"
DX11CreateBasicBlendStateAlpha(D3D11_BLEND_ZERO, D3D11_BLEND_INV_SRC_ALPHA,D3D11_BLEND_ZERO,D3D11_BLEND_INV_SRC_ALPHA,
BlendingStates[beEraser]);
And now i can rip holes into my rendertargets again ^^
Bookmarks