mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
VideoCommon: Use integer arithmetic instead of floating point arithmetic when dealing with EFB scales.
Should fix problems caused by EFB scales other than Native (excluding fractional!). Test whether this fixes games which work fine with native EFB resolution but show glitches with higher internal resolutions. Also fixed numerous warnings. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6549 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@ -593,12 +593,10 @@ void Renderer::RenderText(const char *text, int left, int top, u32 color)
|
||||
TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc)
|
||||
{
|
||||
TargetRectangle result;
|
||||
int Xstride = (s_Fulltarget_width - s_target_width) / 2;
|
||||
int Ystride = (s_Fulltarget_height - s_target_height) / 2;
|
||||
result.left = (int)(rc.left * EFBxScale) + Xstride;
|
||||
result.top = (int)((EFB_HEIGHT - rc.top) * EFByScale) + Ystride;
|
||||
result.right = (int)(rc.right * EFBxScale) - (Xstride * 2);
|
||||
result.bottom = (int)((EFB_HEIGHT - rc.bottom) * EFByScale) - (Ystride * 2);
|
||||
result.left = EFBToScaledX(rc.left) + TargetStrideX();
|
||||
result.top = EFBToScaledY(EFB_HEIGHT - rc.top) + TargetStrideY();
|
||||
result.right = EFBToScaledX(rc.right) - (TargetStrideX() * 2);
|
||||
result.bottom = EFBToScaledY(EFB_HEIGHT - rc.bottom) - (TargetStrideY() * 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -618,11 +616,8 @@ bool Renderer::SetScissorRect()
|
||||
GetScissorRect(rc);
|
||||
|
||||
if (rc.left < 0) rc.left = 0;
|
||||
|
||||
if (rc.right > EFB_WIDTH) rc.right = EFB_WIDTH;
|
||||
|
||||
if (rc.top < 0) rc.top = 0;
|
||||
|
||||
if (rc.right > EFB_WIDTH) rc.right = EFB_WIDTH;
|
||||
if (rc.bottom > EFB_HEIGHT) rc.bottom = EFB_HEIGHT;
|
||||
|
||||
if (rc.left > rc.right)
|
||||
@ -642,11 +637,10 @@ bool Renderer::SetScissorRect()
|
||||
if (rc.right != rc.left && rc.bottom != rc.top)
|
||||
{
|
||||
glScissor(
|
||||
(int)(rc.left * EFBxScale), // x = 0 for example
|
||||
(int)((EFB_HEIGHT - rc.bottom) * EFByScale), // y = 0 for example
|
||||
(int)((rc.right - rc.left)* EFBxScale), // width = 640 for example
|
||||
(int)((rc.bottom - rc.top) * EFByScale) // height = 480 for example
|
||||
);
|
||||
EFBToScaledX(rc.left), // x = 0 for example
|
||||
EFBToScaledY(EFB_HEIGHT - rc.bottom), // y = 0 for example
|
||||
EFBToScaledX(rc.right - rc.left), // width = 640 for example
|
||||
EFBToScaledY(rc.bottom - rc.top)); // height = 480 for example
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -784,23 +778,23 @@ void Renderer::UpdateViewport()
|
||||
// [4] = yorig + height/2 + 342
|
||||
// [5] = 16777215 * farz
|
||||
|
||||
int scissorXOff = bpmem.scissorOffset.x * 2;
|
||||
int scissorYOff = bpmem.scissorOffset.y * 2;
|
||||
int scissorXOff = bpmem.scissorOffset.x << 1;
|
||||
int scissorYOff = bpmem.scissorOffset.y << 1;
|
||||
|
||||
// int Xstride = (s_Fulltarget_width - s_target_width) / 2;
|
||||
// int Ystride = (s_Fulltarget_height - s_target_height) / 2;
|
||||
|
||||
// Stretch picture with increased internal resolution
|
||||
int X = (int)ceil((xfregs.rawViewport[3] - xfregs.rawViewport[0] - float(scissorXOff)) * Renderer::GetTargetScaleX());
|
||||
int Y = (int)ceil((float(EFB_HEIGHT) - xfregs.rawViewport[4] + xfregs.rawViewport[1] + float(scissorYOff)) * Renderer::GetTargetScaleY());
|
||||
int Width = (int)ceil(2.0f * xfregs.rawViewport[0] * Renderer::GetTargetScaleX());
|
||||
int Height = (int)ceil(-2.0f * xfregs.rawViewport[1] * Renderer::GetTargetScaleY());
|
||||
// TODO: ceil, floor or just cast to int?
|
||||
int X = EFBToScaledX((int)ceil(xfregs.rawViewport[3] - xfregs.rawViewport[0] - (float)scissorXOff));
|
||||
int Y = EFBToScaledY((int)ceil((float)EFB_HEIGHT - xfregs.rawViewport[4] + xfregs.rawViewport[1] + (float)scissorYOff));
|
||||
int Width = EFBToScaledX((int)ceil(2.0f * xfregs.rawViewport[0]));
|
||||
int Height = EFBToScaledY((int)ceil(-2.0f * xfregs.rawViewport[1]));
|
||||
double GLNear = (xfregs.rawViewport[5] - xfregs.rawViewport[2]) / 16777216.0f;
|
||||
double GLFar = xfregs.rawViewport[5] / 16777216.0f;
|
||||
if (Width < 0)
|
||||
{
|
||||
X += Width;
|
||||
Width*=-1;
|
||||
Width *= -1;
|
||||
}
|
||||
if (Height < 0)
|
||||
{
|
||||
|
@ -276,10 +276,6 @@ void TextureCache::TCacheEntry::FromRenderTarget(bool bFromZBuffer, bool bScaleB
|
||||
FramebufferManager::ResolveAndGetDepthTarget(source_rect) :
|
||||
FramebufferManager::ResolveAndGetRenderTarget(source_rect);
|
||||
|
||||
// TODO: move
|
||||
const float xScale = Renderer::GetTargetScaleX();
|
||||
const float yScale = Renderer::GetTargetScaleY();
|
||||
|
||||
GL_REPORT_ERRORD();
|
||||
|
||||
if (false == isDynamic || g_ActiveConfig.bCopyEFBToTexture)
|
||||
@ -325,8 +321,6 @@ void TextureCache::TCacheEntry::FromRenderTarget(bool bFromZBuffer, bool bScaleB
|
||||
hash = TextureConverter::EncodeToRamFromTexture(
|
||||
addr,
|
||||
read_texture,
|
||||
xScale,
|
||||
yScale,
|
||||
bFromZBuffer,
|
||||
bIsIntensityFmt,
|
||||
copyfmt,
|
||||
|
@ -284,19 +284,14 @@ void EncodeToRam(u32 address, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyf
|
||||
s32 expandedWidth = (width + blkW) & (~blkW);
|
||||
s32 expandedHeight = (height + blkH) & (~blkH);
|
||||
|
||||
float MValueX = Renderer::GetTargetScaleX();
|
||||
float MValueY = Renderer::GetTargetScaleY();
|
||||
|
||||
float top = (EFB_HEIGHT - source.top - expandedHeight) * MValueY ;
|
||||
|
||||
float sampleStride = bScaleByHalf?2.0f:1.0f;
|
||||
|
||||
TextureConversionShader::SetShaderParameters((float)expandedWidth,
|
||||
expandedHeight * MValueY,
|
||||
source.left * MValueX,
|
||||
top,
|
||||
sampleStride * MValueX,
|
||||
sampleStride * MValueY);
|
||||
float sampleStride = bScaleByHalf ? 2.f : 1.f;
|
||||
// TODO: sampleStride scaling might be slightly off
|
||||
TextureConversionShader::SetShaderParameters((float)expandedWidth,
|
||||
(float)Renderer::EFBToScaledY(expandedHeight), // TODO: Why do we scale this?
|
||||
(float)Renderer::EFBToScaledX(source.left),
|
||||
(float)Renderer::EFBToScaledY(EFB_HEIGHT - source.top - expandedHeight),
|
||||
Renderer::EFBToScaledXf(sampleStride),
|
||||
Renderer::EFBToScaledYf(sampleStride));
|
||||
|
||||
TargetRectangle scaledSource;
|
||||
scaledSource.top = 0;
|
||||
@ -318,7 +313,7 @@ void EncodeToRam(u32 address, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyf
|
||||
GL_REPORT_ERRORD();
|
||||
}
|
||||
|
||||
u64 EncodeToRamFromTexture(u32 address,GLuint source_texture,float MValueX,float MValueY,bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source)
|
||||
u64 EncodeToRamFromTexture(u32 address,GLuint source_texture, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source)
|
||||
{
|
||||
u32 format = copyfmt;
|
||||
|
||||
@ -354,14 +349,14 @@ u64 EncodeToRamFromTexture(u32 address,GLuint source_texture,float MValueX,float
|
||||
s32 expandedWidth = (width + blkW) & (~blkW);
|
||||
s32 expandedHeight = (height + blkH) & (~blkH);
|
||||
|
||||
float sampleStride = bScaleByHalf?2.0f:1.0f;
|
||||
float top = (EFB_HEIGHT - source.top - expandedHeight) * MValueY ;
|
||||
TextureConversionShader::SetShaderParameters((float)expandedWidth,
|
||||
expandedHeight * MValueY,
|
||||
source.left * MValueX,
|
||||
top,
|
||||
sampleStride * MValueX,
|
||||
sampleStride * MValueY);
|
||||
float sampleStride = bScaleByHalf ? 2.f : 1.f;
|
||||
// TODO: sampleStride scaling might be slightly off
|
||||
TextureConversionShader::SetShaderParameters((float)expandedWidth,
|
||||
(float)Renderer::EFBToScaledY(expandedHeight), // TODO: Why do we scale this?
|
||||
(float)Renderer::EFBToScaledX(source.left),
|
||||
(float)Renderer::EFBToScaledY(EFB_HEIGHT - source.top - expandedHeight),
|
||||
Renderer::EFBToScaledXf(sampleStride),
|
||||
Renderer::EFBToScaledYf(sampleStride));
|
||||
|
||||
TargetRectangle scaledSource;
|
||||
scaledSource.top = 0;
|
||||
@ -447,8 +442,8 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur
|
||||
GL_REPORT_ERRORD();
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(srcFmtWidth, (float)srcHeight); glVertex2f(1,-1);
|
||||
glTexCoord2f(srcFmtWidth, 0); glVertex2f(1,1);
|
||||
glTexCoord2f((float)srcFmtWidth, (float)srcHeight); glVertex2f(1,-1);
|
||||
glTexCoord2f((float)srcFmtWidth, 0); glVertex2f(1,1);
|
||||
glTexCoord2f(0, 0); glVertex2f(-1,1);
|
||||
glTexCoord2f(0, (float)srcHeight); glVertex2f(-1,-1);
|
||||
glEnd();
|
||||
|
@ -37,7 +37,7 @@ void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc,
|
||||
|
||||
void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTexture);
|
||||
|
||||
u64 EncodeToRamFromTexture(u32 address,GLuint source_texture,float MValueX,float MValueY, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source);
|
||||
u64 EncodeToRamFromTexture(u32 address, GLuint source_texture, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source);
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user