hopefully solved all the pixel align problems when drawing full screen quads.

this not solve the remaining projection problem in some games like mario kart wii
will work that problem later.
please test and let me know the results.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5473 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Rodolfo Osvaldo Bogado 2010-05-24 14:20:19 +00:00
parent b73b77014f
commit 4b1909ea98
6 changed files with 42 additions and 23 deletions

View File

@ -380,27 +380,31 @@ void drawShadedTexQuad(IDirect3DTexture9 *texture,
const RECT *rSource, const RECT *rSource,
int SourceWidth, int SourceWidth,
int SourceHeight, int SourceHeight,
int DestWidth,
int DestHeight,
IDirect3DPixelShader9 *PShader, IDirect3DPixelShader9 *PShader,
IDirect3DVertexShader9 *Vshader) IDirect3DVertexShader9 *Vshader)
{ {
float sw = 1.0f /(float) SourceWidth; float sw = 1.0f /(float) SourceWidth;
float sh = 1.0f /(float) SourceHeight; float sh = 1.0f /(float) SourceHeight;
float u1=((float)rSource->left + 0.5f) * sw; float dw = 1.0f /(float) DestWidth;
float u2=((float)rSource->right + 0.5f) * sw; float dh = 1.0f /(float) DestHeight;
float v1=((float)rSource->top + 0.5f) * sh; float u1=((float)rSource->left) * sw;
float v2=((float)rSource->bottom + 0.5f) * sh; float u2=((float)rSource->right) * sw;
float v1=((float)rSource->top) * sh;
float v2=((float)rSource->bottom) * sh;
struct Q2DVertex { float x,y,z,rhw,u,v,w,h,L,T,R,B; } coords[4] = { struct Q2DVertex { float x,y,z,rhw,u,v,w,h,L,T,R,B; } coords[4] = {
{-1.0f, 1.0f, 0.0f,1.0f, u1, v1, sw, sh,u1,v1,u2,v2}, {-1.0f - dw,-1.0f + dh, 0.0f,1.0f, u1, v2, sw, sh,u1,v1,u2,v2},
{ 1.0f, 1.0f, 0.0f,1.0f, u2, v1, sw, sh,u1,v1,u2,v2}, {-1.0f - dw, 1.0f + dh, 0.0f,1.0f, u1, v1, sw, sh,u1,v1,u2,v2},
{ 1.0f,-1.0f, 0.0f,1.0f, u2, v2, sw, sh,u1,v1,u2,v2}, { 1.0f - dw,-1.0f + dh, 0.0f,1.0f, u2, v2, sw, sh,u1,v1,u2,v2},
{-1.0f,-1.0f, 0.0f,1.0f, u1, v2, sw, sh,u1,v1,u2,v2} { 1.0f - dw, 1.0f + dh, 0.0f,1.0f, u2, v1, sw, sh,u1,v1,u2,v2}
}; };
dev->SetVertexShader(Vshader); dev->SetVertexShader(Vshader);
dev->SetPixelShader(PShader); dev->SetPixelShader(PShader);
D3D::SetTexture(0, texture); D3D::SetTexture(0, texture);
dev->SetFVF(D3DFVF_XYZW | D3DFVF_TEX3 | D3DFVF_TEXCOORDSIZE4(2)); dev->SetFVF(D3DFVF_XYZW | D3DFVF_TEX3 | D3DFVF_TEXCOORDSIZE4(2));
dev->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, coords, sizeof(Q2DVertex)); dev->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, coords, sizeof(Q2DVertex));
RestoreShaders(); RestoreShaders();
} }
@ -409,27 +413,31 @@ void drawShadedTexSubQuad(IDirect3DTexture9 *texture,
int SourceWidth, int SourceWidth,
int SourceHeight, int SourceHeight,
const MathUtil::Rectangle<float> *rDest, const MathUtil::Rectangle<float> *rDest,
int DestWidth,
int DestHeight,
IDirect3DPixelShader9 *PShader, IDirect3DPixelShader9 *PShader,
IDirect3DVertexShader9 *Vshader) IDirect3DVertexShader9 *Vshader)
{ {
float sw = 1.0f /(float) SourceWidth; float sw = 1.0f /(float) SourceWidth;
float sh = 1.0f /(float) SourceHeight; float sh = 1.0f /(float) SourceHeight;
float u1= (rSource->left + 0.5f) * sw; float dw = 1.0f /(float) DestWidth;
float u2= (rSource->right + 0.5f) * sw; float dh = 1.0f /(float) DestHeight;
float v1= (rSource->top + 0.5f) * sh; float u1= rSource->left * sw;
float v2= (rSource->bottom + 0.5f) * sh; float u2= rSource->right * sw;
float v1= rSource->top * sh;
float v2= rSource->bottom * sh;
struct Q2DVertex { float x,y,z,rhw,u,v,w,h,L,T,R,B; } coords[4] = { struct Q2DVertex { float x,y,z,rhw,u,v,w,h,L,T,R,B; } coords[4] = {
{ rDest->left , rDest->bottom, 0.0f,1.0f, u1, v1, sw, sh,u1,v1,u2,v2}, { rDest->left - dw , rDest->top + dh, 1.0f,1.0f, u1, v2, sw, sh,u1,v1,u2,v2},
{ rDest->right, rDest->bottom, 0.0f,1.0f, u2, v1, sw, sh,u1,v1,u2,v2}, { rDest->left - dw , rDest->bottom + dh, 1.0f,1.0f, u1, v1, sw, sh,u1,v1,u2,v2},
{ rDest->right, rDest->top , 0.0f,1.0f, u2, v2, sw, sh,u1,v1,u2,v2}, { rDest->right - dw , rDest->top + dh, 1.0f,1.0f, u2, v2, sw, sh,u1,v1,u2,v2},
{ rDest->left , rDest->top , 0.0f,1.0f, u1, v2, sw, sh,u1,v1,u2,v2} { rDest->right - dw , rDest->bottom + dh, 1.0f,1.0f, u2, v1, sw, sh,u1,v1,u2,v2}
}; };
dev->SetVertexShader(Vshader); dev->SetVertexShader(Vshader);
dev->SetPixelShader(PShader); dev->SetPixelShader(PShader);
D3D::SetTexture(0, texture); D3D::SetTexture(0, texture);
dev->SetFVF(D3DFVF_XYZW | D3DFVF_TEX3 | D3DFVF_TEXCOORDSIZE4(2)); dev->SetFVF(D3DFVF_XYZW | D3DFVF_TEX3 | D3DFVF_TEXCOORDSIZE4(2));
dev->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, coords, sizeof(Q2DVertex)); dev->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, coords, sizeof(Q2DVertex));
RestoreShaders(); RestoreShaders();
} }

View File

@ -64,6 +64,8 @@ namespace D3D
const RECT *rSource, const RECT *rSource,
int SourceWidth, int SourceWidth,
int SourceHeight, int SourceHeight,
int DestWidth,
int DestHeight,
IDirect3DPixelShader9 *PShader, IDirect3DPixelShader9 *PShader,
IDirect3DVertexShader9 *Vshader); IDirect3DVertexShader9 *Vshader);
void drawShadedTexSubQuad(IDirect3DTexture9 *texture, void drawShadedTexSubQuad(IDirect3DTexture9 *texture,
@ -71,6 +73,8 @@ namespace D3D
int SourceWidth, int SourceWidth,
int SourceHeight, int SourceHeight,
const MathUtil::Rectangle<float> *rDest, const MathUtil::Rectangle<float> *rDest,
int DestWidth,
int DestHeight,
IDirect3DPixelShader9 *PShader, IDirect3DPixelShader9 *PShader,
IDirect3DVertexShader9 *Vshader); IDirect3DVertexShader9 *Vshader);
void drawClearQuad(u32 Color,float z,IDirect3DPixelShader9 *PShader,IDirect3DVertexShader9 *Vshader); void drawClearQuad(u32 Color,float z,IDirect3DPixelShader9 *PShader,IDirect3DVertexShader9 *Vshader);

View File

@ -451,6 +451,8 @@ void FramebufferManager::copyToVirtualXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight
&sourcerect, &sourcerect,
Renderer::GetFullTargetWidth() , Renderer::GetFullTargetWidth() ,
Renderer::GetFullTargetHeight(), Renderer::GetFullTargetHeight(),
target_width,
target_height,
PixelShaderCache::GetColorCopyProgram(SSAAMode), PixelShaderCache::GetColorCopyProgram(SSAAMode),
(SSAAMode != 0)? VertexShaderCache::GetFSAAVertexShader() : VertexShaderCache::GetSimpleVertexShader()); (SSAAMode != 0)? VertexShaderCache::GetFSAAVertexShader() : VertexShaderCache::GetSimpleVertexShader());

View File

@ -759,6 +759,7 @@ u32 Renderer::AccessEFB(EFBAccessType type, int x, int y)
&RectToLock, &RectToLock,
Renderer::GetFullTargetWidth() , Renderer::GetFullTargetWidth() ,
Renderer::GetFullTargetHeight(), Renderer::GetFullTargetHeight(),
4,4,
(BufferFormat == FOURCC_RAWZ)?PixelShaderCache::GetColorMatrixProgram(0):PixelShaderCache::GetDepthMatrixProgram(0), (BufferFormat == FOURCC_RAWZ)?PixelShaderCache::GetColorMatrixProgram(0):PixelShaderCache::GetDepthMatrixProgram(0),
VertexShaderCache::GetSimpleVertexShader()); VertexShaderCache::GetSimpleVertexShader());
@ -1095,7 +1096,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
drawRc.top = 1.0f - 2.0f * ((hOffset + xfbHeight) / (float)fbHeight); drawRc.top = 1.0f - 2.0f * ((hOffset + xfbHeight) / (float)fbHeight);
drawRc.left = -(xfbWidth / (float)fbWidth); drawRc.left = -(xfbWidth / (float)fbWidth);
drawRc.right = (xfbWidth / (float)fbWidth); drawRc.right = (xfbWidth / (float)fbWidth);
if (!g_ActiveConfig.bAutoScale) if (!g_ActiveConfig.bAutoScale)
{ {
@ -1117,7 +1118,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
drawRc.right = 1; drawRc.right = 1;
} }
D3D::drawShadedTexSubQuad(xfbSource->texture,&sourceRc,xfbSource->texWidth,xfbSource->texHeight,&drawRc,PixelShaderCache::GetColorCopyProgram(0),VertexShaderCache::GetSimpleVertexShader()); D3D::drawShadedTexSubQuad(xfbSource->texture,&sourceRc,xfbSource->texWidth,xfbSource->texHeight,&drawRc,Width,Height,PixelShaderCache::GetColorCopyProgram(0),VertexShaderCache::GetSimpleVertexShader());
} }
D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER); D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER);

View File

@ -582,6 +582,8 @@ void TextureCache::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, boo
&sourcerect, &sourcerect,
Renderer::GetFullTargetWidth() , Renderer::GetFullTargetWidth() ,
Renderer::GetFullTargetHeight(), Renderer::GetFullTargetHeight(),
Scaledtex_w,
Scaledtex_h,
((bformat != FOURCC_RAWZ && bformat != D3DFMT_D24X8) && bFromZBuffer)? PixelShaderCache::GetDepthMatrixProgram(SSAAMode): PixelShaderCache::GetColorMatrixProgram(SSAAMode), ((bformat != FOURCC_RAWZ && bformat != D3DFMT_D24X8) && bFromZBuffer)? PixelShaderCache::GetDepthMatrixProgram(SSAAMode): PixelShaderCache::GetColorMatrixProgram(SSAAMode),
(SSAAMode != 0)? VertexShaderCache::GetFSAAVertexShader() : VertexShaderCache::GetSimpleVertexShader()); (SSAAMode != 0)? VertexShaderCache::GetFSAAVertexShader() : VertexShaderCache::GetSimpleVertexShader());

View File

@ -271,7 +271,7 @@ void EncodeToRamUsingShader(LPDIRECT3DPIXELSHADER9 shader, LPDIRECT3DTEXTURE9 sr
// Draw... // Draw...
D3D::drawShadedTexQuad(srcTexture,&SrcRect,1,1,shader,VertexShaderCache::GetSimpleVertexShader()); D3D::drawShadedTexQuad(srcTexture,&SrcRect,1,1,dstWidth,dstHeight,shader,VertexShaderCache::GetSimpleVertexShader());
hr = D3D::dev->SetRenderTarget(0, FBManager.GetEFBColorRTSurface()); hr = D3D::dev->SetRenderTarget(0, FBManager.GetEFBColorRTSurface());
hr = D3D::dev->SetDepthStencilSurface(FBManager.GetEFBDepthRTSurface()); hr = D3D::dev->SetDepthStencilSurface(FBManager.GetEFBDepthRTSurface());
Renderer::RestoreAPIState(); Renderer::RestoreAPIState();
@ -442,9 +442,9 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, LPDIRECT3DTEXTURE
RECT sourcerect; RECT sourcerect;
sourcerect.bottom = srcHeight; sourcerect.bottom = srcHeight;
sourcerect.left = -1; sourcerect.left = 0;
sourcerect.right = srcFmtWidth; sourcerect.right = srcFmtWidth;
sourcerect.top = -1; sourcerect.top = 0;
D3D::ChangeSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT); D3D::ChangeSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
D3D::ChangeSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); D3D::ChangeSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
@ -463,6 +463,8 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, LPDIRECT3DTEXTURE
&sourcerect, &sourcerect,
1 , 1 ,
1, 1,
srcWidth,
srcHeight,
s_yuyvToRgbProgram, s_yuyvToRgbProgram,
VertexShaderCache::GetSimpleVertexShader()); VertexShaderCache::GetSimpleVertexShader());