Don't resize render target to handle out-of-bounds viewports. Instead, adjust the projection matrix.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7538 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Nolan Check
2011-05-12 02:14:45 +00:00
parent 8cb2443c2f
commit 8024783502
16 changed files with 229 additions and 261 deletions

View File

@ -62,10 +62,6 @@ volatile bool Renderer::s_bScreenshot;
int Renderer::s_target_width;
int Renderer::s_target_height;
// The custom resolution
int Renderer::s_Fulltarget_width;
int Renderer::s_Fulltarget_height;
// TODO: Add functionality to reinit all the render targets when the window is resized.
int Renderer::s_backbuffer_width;
int Renderer::s_backbuffer_height;
@ -180,8 +176,8 @@ bool Renderer::CalculateTargetSize(int multiplier)
if (newEFBWidth != s_target_width || newEFBHeight != s_target_height)
{
s_Fulltarget_width = s_target_width = newEFBWidth;
s_Fulltarget_height = s_target_height = newEFBHeight;
s_target_width = newEFBWidth;
s_target_height = newEFBHeight;
return true;
}
return false;
@ -375,7 +371,7 @@ void Renderer::RecordVideoMemory()
FifoRecorder::GetInstance().SetVideoMemory(bpMem, cpMem, xfMem, xfRegs, sizeof(XFRegisters) / 4);
}
void UpdateViewport()
void UpdateViewport(Matrix44& vpCorrection)
{
g_renderer->UpdateViewport();
g_renderer->UpdateViewport(vpCorrection);
}

View File

@ -66,12 +66,6 @@ public:
virtual void ApplyState(bool bUseDstAlpha) = 0;
virtual void RestoreState() = 0;
// Real internal resolution:
// D3D doesn't support viewports larger than the target size, so we need to resize the target to the viewport size for those.
// OpenGL supports this, so GetFullTargetWidth returns the same as GetTargetWidth there.
static int GetFullTargetWidth() { return s_Fulltarget_width; }
static int GetFullTargetHeight() { return s_Fulltarget_height; }
// Ideal internal resolution - determined by display resolution (automatic scaling) and/or a multiple of the native EFB resolution
static int GetTargetWidth() { return s_target_width; }
static int GetTargetHeight() { return s_target_height; }
@ -99,12 +93,6 @@ public:
static float EFBToScaledXf(float x) { return x * ((float)GetTargetWidth() / (float)EFB_WIDTH); }
static float EFBToScaledYf(float y) { return y * ((float)GetTargetHeight() / (float)EFB_HEIGHT); }
// Returns the offset at which the EFB will be drawn onto the backbuffer
// NOTE: Never calculate this manually (e.g. to "increase accuracy"), since you might end up getting off-by-one errors.
// This is a per-frame constant, so it won't cause any issues.
static int TargetStrideX() { return (s_Fulltarget_width - s_target_width) / 2; }
static int TargetStrideY() { return (s_Fulltarget_height - s_target_height) / 2; }
// Random utilities
static void SetScreenshot(const char *filename);
static void DrawDebugText();
@ -124,7 +112,7 @@ public:
// Finish up the current frame, print some stats
virtual void Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight, const EFBRectangle& rc,float Gamma = 1.0f) = 0;
virtual void UpdateViewport() = 0;
virtual void UpdateViewport(Matrix44& vpCorrection) = 0;
virtual bool SaveScreenshot(const std::string &filename, const TargetRectangle &rc) = 0;
@ -160,10 +148,6 @@ protected:
static int s_target_width;
static int s_target_height;
// The custom resolution
static int s_Fulltarget_width;
static int s_Fulltarget_height;
// TODO: Add functionality to reinit all the render targets when the window is resized.
static int s_backbuffer_width;
static int s_backbuffer_height;
@ -189,7 +173,7 @@ private:
extern Renderer *g_renderer;
void UpdateViewport();
void UpdateViewport(Matrix44& vpCorrection);
template <typename R>
void GetScissorRect(MathUtil::Rectangle<R> &rect)

View File

@ -43,12 +43,13 @@ static int nNormalMatricesChanged[2]; // min,max
static int nPostTransformMatricesChanged[2]; // min,max
static int nLightsChanged[2]; // min,max
static Matrix44 s_viewportCorrection;
static Matrix33 s_viewRotationMatrix;
static Matrix33 s_viewInvRotationMatrix;
static float s_fViewTranslationVector[3];
static float s_fViewRotation[2];
void UpdateViewport();
void UpdateViewport(Matrix44& vpCorrection);
inline void SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{
@ -301,7 +302,8 @@ void VertexShaderManager::SetConstants()
bViewportChanged = false;
SetVSConstant4f(C_DEPTHPARAMS,xfregs.viewport.farZ / 16777216.0f,xfregs.viewport.zRange / 16777216.0f,0.0f,0.0f);
// This is so implementation-dependent that we can't have it here.
UpdateViewport();
UpdateViewport(s_viewportCorrection);
bProjectionChanged = true;
}
if (bProjectionChanged)
@ -421,12 +423,18 @@ void VertexShaderManager::SetConstants()
Matrix44::Multiply(mtxB, mtxA, viewMtx); // view = rotation x translation
Matrix44::Set(mtxB, g_fProjectionMatrix);
Matrix44::Multiply(mtxB, viewMtx, mtxA); // mtxA = projection x view
Matrix44::Multiply(s_viewportCorrection, mtxA, mtxB); // mtxB = viewportCorrection x mtxA
SetMultiVSConstant4fv(C_PROJECTION, 4, &mtxA.data[0]);
SetMultiVSConstant4fv(C_PROJECTION, 4, mtxB.data);
}
else
{
SetMultiVSConstant4fv(C_PROJECTION, 4, &g_fProjectionMatrix[0]);
Matrix44 projMtx;
Matrix44::Set(projMtx, g_fProjectionMatrix);
Matrix44 correctedMtx;
Matrix44::Multiply(s_viewportCorrection, projMtx, correctedMtx);
SetMultiVSConstant4fv(C_PROJECTION, 4, correctedMtx.data);
}
}
}