Lots of code and warning cleanup. OGL/D3D: Moved to a shared config class in VideoCommon. This lets VideoCommon code read the config without ugly hacks. Fixed various config race conditions by keeping a copy (g_ActiveConfig) of the g_Config struct which is updated once per frame.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4256 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard
2009-09-13 08:21:35 +00:00
parent 52ea8a0fd1
commit 700f2ff694
44 changed files with 613 additions and 856 deletions

View File

@ -42,34 +42,43 @@
#include "debugger/debugger.h"
static float m_targetWidth;
static float m_targetHeight;
static int s_targetWidth;
static int s_targetHeight;
static int s_backbuffer_width;
static int s_backbuffer_height;
static float xScale;
static float yScale;
static int m_recordWidth;
static int m_recordHeight;
static int s_recordWidth;
static int s_recordHeight;
static bool m_LastFrameDumped;
static bool m_AVIDumping;
static bool s_LastFrameDumped;
static bool s_AVIDumping;
#define NUMWNDRES 6
extern int g_Res[NUMWNDRES][2];
bool Renderer::Init()
{
EmuWindow::SetSize(g_Res[g_Config.iWindowedRes][0], g_Res[g_Config.iWindowedRes][1]);
UpdateActiveConfig();
EmuWindow::SetSize(g_Res[g_ActiveConfig.iWindowedRes][0], g_Res[g_ActiveConfig.iWindowedRes][1]);
D3D::Create(g_Config.iAdapter, EmuWindow::GetWnd(), g_Config.bFullscreen, g_Config.iFSResolution, g_Config.iMultisampleMode);
D3D::Create(g_ActiveConfig.iAdapter, EmuWindow::GetWnd(), g_ActiveConfig.bFullscreen,
g_ActiveConfig.iFSResolution, g_ActiveConfig.iMultisampleMode);
m_targetWidth = (float)D3D::GetDisplayWidth();
m_targetHeight = (float)D3D::GetDisplayHeight();
s_targetWidth = D3D::GetDisplayWidth();
s_targetHeight = D3D::GetDisplayHeight();
xScale = m_targetWidth / (float)EFB_WIDTH;
yScale = m_targetHeight / (float)EFB_HEIGHT;
s_backbuffer_width = s_targetWidth;
s_backbuffer_height = s_targetHeight;
m_LastFrameDumped = false;
m_AVIDumping = false;
xScale = (float)s_targetWidth / (float)EFB_WIDTH;
yScale = (float)s_targetHeight / (float)EFB_HEIGHT;
s_LastFrameDumped = false;
s_AVIDumping = false;
// We're not using fixed function, except for some 2D.
// Let's just set the matrices to identity to be sure.
@ -82,7 +91,7 @@ bool Renderer::Init()
for (int i = 0; i < 8; i++)
D3D::dev->SetSamplerState(i, D3DSAMP_MAXANISOTROPY, 16);
D3D::BeginFrame(true, 0);
D3D::BeginFrame(true, 0, 1.0f);
VertexManager::BeginFrame();
return true;
}
@ -93,7 +102,7 @@ void Renderer::Shutdown()
D3D::EndFrame();
D3D::Close();
if (m_AVIDumping)
if (s_AVIDumping)
{
AVIDump::Stop();
}
@ -126,10 +135,10 @@ void dumpMatrix(D3DXMATRIX &mtx)
TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc)
{
TargetRectangle result;
result.left = (rc.left * m_targetWidth) / EFB_WIDTH;
result.top = (rc.top * m_targetHeight) / EFB_HEIGHT;
result.right = (rc.right * m_targetWidth) / EFB_WIDTH;
result.bottom = (rc.bottom * m_targetHeight) / EFB_HEIGHT;
result.left = (rc.left * s_targetWidth) / EFB_WIDTH;
result.top = (rc.top * s_targetHeight) / EFB_HEIGHT;
result.right = (rc.right * s_targetWidth) / EFB_WIDTH;
result.bottom = (rc.bottom * s_targetHeight) / EFB_HEIGHT;
return result;
}
@ -165,63 +174,63 @@ void Renderer::SwapBuffers()
}
// Frame dumping routine
if (g_Config.bDumpFrames) {
if (g_ActiveConfig.bDumpFrames) {
D3DDISPLAYMODE DisplayMode;
if (SUCCEEDED(D3D::dev->GetDisplayMode(0, &DisplayMode))) {
LPDIRECT3DSURFACE9 surf;
if (SUCCEEDED(D3D::dev->CreateOffscreenPlainSurface(DisplayMode.Width, DisplayMode.Height, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &surf, NULL))) {
if (!m_LastFrameDumped) {
if (!s_LastFrameDumped) {
RECT windowRect;
GetWindowRect(EmuWindow::GetWnd(), &windowRect);
m_recordWidth = windowRect.right - windowRect.left;
m_recordHeight = windowRect.bottom - windowRect.top;
m_AVIDumping = AVIDump::Start(EmuWindow::GetParentWnd(), m_recordWidth, m_recordHeight);
if (!m_AVIDumping) {
GetClientRect(EmuWindow::GetWnd(), &windowRect);
s_recordWidth = windowRect.right - windowRect.left;
s_recordHeight = windowRect.bottom - windowRect.top;
s_AVIDumping = AVIDump::Start(EmuWindow::GetParentWnd(), s_recordWidth, s_recordHeight);
if (!s_AVIDumping) {
PanicAlert("Error dumping frames to AVI.");
} else {
char msg [255];
sprintf(msg, "Dumping Frames to \"%s/framedump0.avi\" (%dx%d RGB24)", FULL_FRAMES_DIR, m_recordWidth, m_recordHeight);
sprintf(msg, "Dumping Frames to \"%s/framedump0.avi\" (%dx%d RGB24)", FULL_FRAMES_DIR, s_recordWidth, s_recordHeight);
OSD::AddMessage(msg, 2000);
}
}
if (m_AVIDumping) {
if (s_AVIDumping) {
if (SUCCEEDED(D3D::dev->GetFrontBufferData(0, surf))) {
RECT windowRect;
GetWindowRect(EmuWindow::GetWnd(), &windowRect);
D3DLOCKED_RECT rect;
if (SUCCEEDED(surf->LockRect(&rect, &windowRect, D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_NOSYSLOCK | D3DLOCK_READONLY))) {
char *data = (char *)malloc(3 * m_recordWidth * m_recordHeight);
formatBufferDump((const char *)rect.pBits, data, m_recordWidth, m_recordHeight, rect.Pitch);
char *data = (char *)malloc(3 * s_recordWidth * s_recordHeight);
formatBufferDump((const char *)rect.pBits, data, s_recordWidth, s_recordHeight, rect.Pitch);
AVIDump::AddFrame(data);
free(data);
surf->UnlockRect();
}
}
}
m_LastFrameDumped = true;
s_LastFrameDumped = true;
surf->Release();
}
}
}
else
{
if(m_LastFrameDumped && m_AVIDumping) {
if(s_LastFrameDumped && s_AVIDumping) {
AVIDump::Stop();
m_AVIDumping = false;
s_AVIDumping = false;
}
m_LastFrameDumped = false;
s_LastFrameDumped = false;
}
char st[8192];
// Finish up the current frame, print some stats
if (g_Config.bOverlayStats)
if (g_ActiveConfig.bOverlayStats)
{
Statistics::ToString(st);
D3D::font.DrawTextScaled(0,30,20,20,0.0f,0xFF00FFFF,st,false);
}
if (g_Config.bOverlayProjStats)
if (g_ActiveConfig.bOverlayProjStats)
{
Statistics::ToStringProj(st);
D3D::font.DrawTextScaled(0,30,20,20,0.0f,0xFF00FFFF,st,false);
@ -253,27 +262,44 @@ void Renderer::SwapBuffers()
VertexShaderCache::Cleanup();
TextureCache::Cleanup();
// Make any new configuration settings active.
UpdateActiveConfig();
/*
TODO: Resize backbuffer if window size has changed. This code crashes, debug it.
RECT rcWindow;
GetClientRect(EmuWindow::GetWnd(), &rcWindow);
if (rcWindow.right - rcWindow.left != s_backbuffer_width ||
rcWindow.bottom - rcWindow.top != s_backbuffer_height)
{
D3D::Reset();
s_backbuffer_width = D3D::GetDisplayWidth();
s_backbuffer_height = D3D::GetDisplayHeight();
}
*/
//Begin new frame
//Set default viewport and scissor, for the clear to work correctly
stats.ResetFrame();
D3DVIEWPORT9 vp;
vp.X = 0;
vp.Y = 0;
vp.Width = (DWORD)m_targetWidth;
vp.Height = (DWORD)m_targetHeight;
vp.Width = (DWORD)s_targetWidth;
vp.Height = (DWORD)s_targetHeight;
vp.MinZ = 0;
vp.MaxZ = 1.0f;
D3D::dev->SetViewport(&vp);
RECT rc;
rc.left = 0;
rc.top = 0;
rc.right = (LONG)m_targetWidth;
rc.bottom = (LONG)m_targetHeight;
rc.right = (LONG)s_targetWidth;
rc.bottom = (LONG)s_targetHeight;
D3D::dev->SetScissorRect(&rc);
D3D::dev->SetRenderState(D3DRS_SCISSORTESTENABLE, false);
// We probably shouldn't clear here.
D3D::dev->Clear(0, 0, D3DCLEAR_TARGET, 0x00000000, 0, 0);
// D3D::dev->Clear(0, 0, D3DCLEAR_TARGET, 0x00000000, 0, 0);
u32 clearColor = (bpmem.clearcolorAR << 16) | bpmem.clearcolorGB;
D3D::BeginFrame(false, clearColor, 1.0f);
@ -284,7 +310,7 @@ void Renderer::SwapBuffers()
VertexManager::BeginFrame();
if (g_Config.bOldCard)
if (g_ActiveConfig.bOldCard)
D3D::font.SetRenderStates(); //compatibility with low end cards
}
@ -302,26 +328,26 @@ bool Renderer::SetScissorRect()
rc.top = (int)(rc.top * yScale);
rc.right = (int)(rc.right * xScale);
rc.bottom = (int)(rc.bottom * yScale);
if (rc.right >= rc.left && rc.bottom >= rc.top) {
if (rc.right >= rc.left && rc.bottom >= rc.top)
{
D3D::dev->SetScissorRect(&rc);
return true;
}
else
{
WARN_LOG(VIDEO, "SCISSOR ERROR");
WARN_LOG(VIDEO, "Bad scissor rectangle: %i %i %i %i", rc.left, rc.top, rc.right, rc.bottom);
return false;
}
}
void Renderer::SetColorMask()
{
DWORD write = 0;
DWORD color_mask = 0;
if (bpmem.blendmode.alphaupdate)
write = D3DCOLORWRITEENABLE_ALPHA;
color_mask = D3DCOLORWRITEENABLE_ALPHA;
if (bpmem.blendmode.colorupdate)
write |= D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE;
D3D::SetRenderState(D3DRS_COLORWRITEENABLE, write);
color_mask |= D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE;
D3D::SetRenderState(D3DRS_COLORWRITEENABLE, color_mask);
}
u32 Renderer::AccessEFB(EFBAccessType type, int x, int y)
@ -338,7 +364,6 @@ u32 Renderer::AccessEFB(EFBAccessType type, int x, int y)
// TODO (FIX) : currently, AA path is broken/offset and doesn't return the correct pixel
switch (type)
{
case PEEK_Z:
{
// if (s_MSAASamples > 1)
@ -395,7 +420,7 @@ u32 Renderer::AccessEFB(EFBAccessType type, int x, int y)
// TODO: Implement. One way is to draw a tiny pixel-sized rectangle at
// the exact location. Note: EFB pokes are susceptible to Z-buffering
// and perhaps blending.
//WARN_LOG(VIDEOINTERFACE, "This is probably some kind of software rendering");
// WARN_LOG(VIDEOINTERFACE, "This is probably some kind of software rendering");
break;
}
@ -403,16 +428,14 @@ u32 Renderer::AccessEFB(EFBAccessType type, int x, int y)
return 0;
}
// mtx.m[0][3] = pMatrix[1]; // -0.5f/m_targetWidth; <-- fix d3d pixel center?
// mtx.m[1][3] = pMatrix[3]; // +0.5f/m_targetHeight; <-- fix d3d pixel center?
// mtx.m[0][3] = pMatrix[1]; // -0.5f/s_targetWidth; <-- fix d3d pixel center?
// mtx.m[1][3] = pMatrix[3]; // +0.5f/s_targetHeight; <-- fix d3d pixel center?
// Called from VertexShaderManager
void UpdateViewport()
{
int scissorXOff = bpmem.scissorOffset.x * 2;
int scissorYOff = bpmem.scissorOffset.y * 2;
// -------------------------------------
float MValueX = Renderer::GetTargetScaleX();
float MValueY = Renderer::GetTargetScaleY();