fixed blending in dx9 and dx11

fixed fps counter in all the plugins
enjoy

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5778 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Rodolfo Osvaldo Bogado 2010-06-24 15:58:06 +00:00
parent 10b5d2371c
commit 3435c0f647
3 changed files with 41 additions and 87 deletions

View File

@ -766,60 +766,40 @@ void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaE
u32 rgbaColor = (color & 0xFF00FF00) | ((color >> 16) & 0xFF) | ((color << 16) & 0xFF0000);
D3D::stateman->PushDepthState(cleardepthstates[zEnable]);
D3D::stateman->PushRasterizerState(clearraststate);
D3D::stateman->PushBlendState(resetblendstate);
//D3D::stateman->PushBlendState(resetblendstate); temporarily comented till i found the cause of th blending error in mkwii
D3D::stateman->Apply();
D3D::drawClearQuad(rgbaColor, (z & 0xFFFFFF) / float(0xFFFFFF), PixelShaderCache::GetClearProgram(), VertexShaderCache::GetClearVertexShader(), VertexShaderCache::GetClearInputLayout());
D3D::stateman->PopDepthState();
D3D::stateman->PopRasterizerState();
D3D::stateman->PopBlendState();
//D3D::stateman->PopBlendState();
UpdateViewport();
SetScissorRect();
}
void Renderer::SetBlendMode(bool forceUpdate)
{
#define BLEND_ENABLE_MASK 1
#define BLENDOP_SHIFT 2
#define BLENDOP_MASK 4
#define SRCFACTOR_SHIFT 3
#define DESTFACTOR_SHIFT 6
#define FACTOR_MASK 7
// blend mode bit mask
// 0 - blend enable
// 2 - reverse subtract enable (else add)
// 3-5 - srcRGB function
// 6-8 - dstRGB function
if (bpmem.blendmode.logicopenable && bpmem.blendmode.logicmode != 3)
if (bpmem.blendmode.logicopenable)
return;
u32 newval = bpmem.blendmode.subtract << BLENDOP_SHIFT;
if (bpmem.blendmode.subtract) // enable blending src 1 dst 1
{
newval |= BLEND_ENABLE_MASK | (1 << SRCFACTOR_SHIFT) | (1 << DESTFACTOR_SHIFT);
D3D::gfxstate->SetAlphaBlendEnable(true);
D3D::gfxstate->SetBlendOp(D3D11_BLEND_OP_REV_SUBTRACT);
D3D::gfxstate->SetSrcBlend(d3dSrcFactors[1]);
D3D::gfxstate->SetDestBlend(d3dDestFactors[1]);
}
else if (bpmem.blendmode.blendenable)
else
{
newval |= BLEND_ENABLE_MASK; // enable blending
newval |= bpmem.blendmode.srcfactor << SRCFACTOR_SHIFT;
newval |= bpmem.blendmode.dstfactor << DESTFACTOR_SHIFT;
D3D::gfxstate->SetAlphaBlendEnable(bpmem.blendmode.blendenable && (!( bpmem.blendmode.srcfactor == 1 && bpmem.blendmode.dstfactor == 0)));
if (bpmem.blendmode.blendenable && (!( bpmem.blendmode.srcfactor == 1 && bpmem.blendmode.dstfactor == 0)))
{
D3D::gfxstate->SetBlendOp(D3D11_BLEND_OP_ADD);
D3D::gfxstate->SetSrcBlend(d3dSrcFactors[bpmem.blendmode.srcfactor]);
D3D::gfxstate->SetDestBlend(d3dDestFactors[bpmem.blendmode.dstfactor]);
}
}
u32 changes = forceUpdate ? 0xFFFFFFFF : newval ^ s_blendMode;
if (changes & BLEND_ENABLE_MASK) // blend enable change
D3D::gfxstate->SetAlphaBlendEnable(newval & BLEND_ENABLE_MASK);
if (changes & BLENDOP_MASK) // subtract enable change
D3D::gfxstate->SetBlendOp((newval & BLENDOP_MASK) ? D3D11_BLEND_OP_REV_SUBTRACT : D3D11_BLEND_OP_ADD);
if (changes & 0x1F8) // blend RGB change
{
D3D::gfxstate->SetSrcBlend(d3dSrcFactors[(newval >> SRCFACTOR_SHIFT) & FACTOR_MASK]);
D3D::gfxstate->SetDestBlend(d3dDestFactors[(newval >> DESTFACTOR_SHIFT) & FACTOR_MASK]);
}
s_blendMode = newval;
}
void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
@ -1011,7 +991,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
D3D::context->OMSetRenderTargets(1, &FBManager.GetEFBColorTexture()->GetRTV(), FBManager.GetEFBDepthTexture()->GetDSV());
UpdateViewport();
VertexShaderManager::SetViewportChanged();
g_VideoInitialize.pCopiedToXFB(XFBWrited);
g_VideoInitialize.pCopiedToXFB(XFBWrited || g_ActiveConfig.bUseRealXFB);
XFBWrited = false;
}

View File

@ -909,8 +909,6 @@ void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaE
vp.MaxZ = 1.0;
D3D::dev->SetViewport(&vp);
// Always set the scissor in case it was set by the game and has not been reset
RECT sirc;
sirc.left = targetRc.left;
@ -931,50 +929,26 @@ void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaE
void Renderer::SetBlendMode(bool forceUpdate)
{
// blend mode bit mask
// 0 - blend enable
// 2 - reverse subtract enable (else add)
// 3-5 - srcRGB function
// 6-8 - dstRGB function
#define BLEND_ENABLE_MASK 1
#define BLENDOP_SHIFT 2
#define BLENDOP_MASK 4
#define SRCFACTOR_SHIFT 3
#define DESTFACTOR_SHIFT 6
#define FACTOR_MASK 7
if (bpmem.blendmode.logicopenable && bpmem.blendmode.logicmode != 3)
if (bpmem.blendmode.logicopenable)
return;
u32 newval = bpmem.blendmode.subtract << BLENDOP_SHIFT;
if (bpmem.blendmode.subtract) {
newval |= BLEND_ENABLE_MASK | (1 << SRCFACTOR_SHIFT) | (1 << DESTFACTOR_SHIFT);
} else if (bpmem.blendmode.blendenable) {
newval |= BLEND_ENABLE_MASK; // enable blending
newval |= bpmem.blendmode.srcfactor << SRCFACTOR_SHIFT;
newval |= bpmem.blendmode.dstfactor << DESTFACTOR_SHIFT;
if (bpmem.blendmode.subtract && bpmem.blendmode.blendenable)
{
D3D::SetRenderState(D3DRS_ALPHABLENDENABLE, true);
D3D::SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_REVSUBTRACT);
D3D::SetRenderState(D3DRS_SRCBLEND, d3dSrcFactors[1]);
D3D::SetRenderState(D3DRS_DESTBLEND, d3dDestFactors[1]);
}
u32 changes = forceUpdate ? 0xFFFFFFFF : newval ^ s_blendMode;
if (changes & BLEND_ENABLE_MASK) {
// blend enable change
D3D::SetRenderState(D3DRS_ALPHABLENDENABLE, (newval & BLEND_ENABLE_MASK));
else
{
D3D::SetRenderState(D3DRS_ALPHABLENDENABLE, bpmem.blendmode.blendenable && (!( bpmem.blendmode.srcfactor == 1 && bpmem.blendmode.dstfactor == 0)));
if (bpmem.blendmode.blendenable && (!( bpmem.blendmode.srcfactor == 1 && bpmem.blendmode.dstfactor == 0)))
{
D3D::SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
D3D::SetRenderState(D3DRS_SRCBLEND, d3dSrcFactors[bpmem.blendmode.srcfactor]);
D3D::SetRenderState(D3DRS_DESTBLEND, d3dDestFactors[bpmem.blendmode.dstfactor]);
}
}
if (changes & BLENDOP_MASK) {
// subtract enable change
D3D::SetRenderState(D3DRS_BLENDOP, newval & BLENDOP_MASK ? D3DBLENDOP_REVSUBTRACT : D3DBLENDOP_ADD);
}
if (changes & 0x1F8) {
// blend RGB change
D3D::SetRenderState(D3DRS_SRCBLEND, d3dSrcFactors[(newval >> SRCFACTOR_SHIFT) & FACTOR_MASK]);
D3D::SetRenderState(D3DRS_DESTBLEND, d3dDestFactors[(newval >> DESTFACTOR_SHIFT) & FACTOR_MASK]);
}
s_blendMode = newval;
}
@ -1292,7 +1266,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
D3D::dev->SetDepthStencilSurface(FBManager.GetEFBDepthRTSurface());
UpdateViewport();
VertexShaderManager::SetViewportChanged();
g_VideoInitialize.pCopiedToXFB(XFBWrited);
g_VideoInitialize.pCopiedToXFB(XFBWrited || g_ActiveConfig.bUseRealXFB);
XFBWrited = false;
}
@ -1343,8 +1317,7 @@ void Renderer::SetLogicOpMode()
{
if (bpmem.blendmode.logicopenable && bpmem.blendmode.logicmode != 3)
{
s_blendMode = 0;
D3D::SetRenderState(D3DRS_ALPHABLENDENABLE, 1);
D3D::SetRenderState(D3DRS_ALPHABLENDENABLE, true);
D3D::SetRenderState(D3DRS_BLENDOP, d3dLogicOpop[bpmem.blendmode.logicmode]);
D3D::SetRenderState(D3DRS_SRCBLEND, d3dLogicOpSrcFactors[bpmem.blendmode.logicmode]);
D3D::SetRenderState(D3DRS_DESTBLEND, d3dLogicOpDestFactors[bpmem.blendmode.logicmode]);

View File

@ -1243,8 +1243,9 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
// For testing zbuffer targets.
// Renderer::SetZBufferRender();
// SaveTexture("tex.tga", GL_TEXTURE_RECTANGLE_ARB, s_FakeZTarget, GetTargetWidth(), GetTargetHeight());
g_VideoInitialize.pCopiedToXFB(XFBWrited || g_ActiveConfig.bUseRealXFB);
XFBWrited = false;
g_VideoInitialize.pCopiedToXFB(XFBWrited);
}
// Create On-Screen-Messages