From 5ac7105b66eb0dc8c7193ebc7716aa4267f8e424 Mon Sep 17 00:00:00 2001 From: omegadox Date: Sat, 15 Aug 2009 07:20:37 +0000 Subject: [PATCH] GFX: New GlobalControl system - cleaner way to control hacks and for possible control over other parts of the video code (video debugger control). git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3982 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/VideoCommon/Src/GlobalControl.cpp | 136 ++++++++++++++++++ Source/Core/VideoCommon/Src/GlobalControl.h | 102 +++++++++++++ Source/Core/VideoCommon/Src/SConscript | 1 + .../VideoCommon/Src/VertexShaderManager.cpp | 14 +- .../VideoCommon/Src/VertexShaderManager.h | 2 +- Source/Core/VideoCommon/VideoCommon.vcproj | 8 ++ .../Plugin_VideoDX9/Src/VertexManager.cpp | 2 +- .../Plugin_VideoOGL/Src/GUI/ConfigDlg.cpp | 7 + .../Plugin_VideoOGL/Src/VertexManager.cpp | 2 +- 9 files changed, 267 insertions(+), 7 deletions(-) create mode 100644 Source/Core/VideoCommon/Src/GlobalControl.cpp create mode 100644 Source/Core/VideoCommon/Src/GlobalControl.h diff --git a/Source/Core/VideoCommon/Src/GlobalControl.cpp b/Source/Core/VideoCommon/Src/GlobalControl.cpp new file mode 100644 index 0000000000..83559dd468 --- /dev/null +++ b/Source/Core/VideoCommon/Src/GlobalControl.cpp @@ -0,0 +1,136 @@ +// Copyright (C) 2003 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + +#include "GlobalControl.h" + +namespace +{ +// Control Variables +static bool g_ProjHack0; +static ProjectionHack g_ProjHack1; +static ProjectionHack g_ProjHack2; +static bool g_FreeLook; +} // Namespace + + +void Projection_SetHack0(bool value) +{ + g_ProjHack0 = value; +} + +void Projection_SetHack1(ProjectionHack value) +{ + g_ProjHack1 = value; +} + +void Projection_SetHack2(ProjectionHack value) +{ + g_ProjHack2 = value; +} + +void Projection_SetFreeLook(bool enabled) +{ + g_FreeLook = enabled; +} + +bool Projection_GetHack0() +{ + return g_ProjHack0; +} + +ProjectionHack Projection_GetHack1() +{ + return g_ProjHack1; +} + +ProjectionHack Projection_GetHack2() +{ + return g_ProjHack2; +} + +bool Projection_GetFreeLook() +{ + return g_FreeLook; +} +// Copyright (C) 2003 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + +#include "GlobalControl.h" + +namespace +{ +// Control Variables +static bool g_ProjHack0; +static ProjectionHack g_ProjHack1; +static ProjectionHack g_ProjHack2; +static bool g_FreeLook; +} // Namespace + + +void Projection_SetHack0(bool value) +{ + g_ProjHack0 = value; +} + +void Projection_SetHack1(ProjectionHack value) +{ + g_ProjHack1 = value; +} + +void Projection_SetHack2(ProjectionHack value) +{ + g_ProjHack2 = value; +} + +void Projection_SetFreeLook(bool enabled) +{ + g_FreeLook = enabled; +} + +bool Projection_GetHack0() +{ + return g_ProjHack0; +} + +ProjectionHack Projection_GetHack1() +{ + return g_ProjHack1; +} + +ProjectionHack Projection_GetHack2() +{ + return g_ProjHack2; +} + +bool Projection_GetFreeLook() +{ + return g_FreeLook; +} \ No newline at end of file diff --git a/Source/Core/VideoCommon/Src/GlobalControl.h b/Source/Core/VideoCommon/Src/GlobalControl.h new file mode 100644 index 0000000000..43a992f459 --- /dev/null +++ b/Source/Core/VideoCommon/Src/GlobalControl.h @@ -0,0 +1,102 @@ +// Copyright (C) 2003 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + +/* ----------------------------------------------------------------------- + Purpose: This is used to control parts of the video code such as hacks + ----------------------------------------------------------------------- */ + +#include "Common.h" + +struct ProjectionHack +{ + bool enabled; + float value; + + ProjectionHack() + { + } + + ProjectionHack(bool enabled, float value) + { + ProjectionHack::enabled = enabled; + ProjectionHack::value = value; + } +}; + +/* ------------------- + Projection Control + ------------------- */ +void Projection_SetHack0(bool value); +void Projection_SetHack1(ProjectionHack value); +void Projection_SetHack2(ProjectionHack value); +void Projection_SetFreeLook(bool enabled); + +bool Projection_GetHack0(); +ProjectionHack Projection_GetHack1(); +ProjectionHack Projection_GetHack2(); +bool Projection_GetFreeLook(); +// Copyright (C) 2003 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + +/* ----------------------------------------------------------------------- + Purpose: This is used to control parts of the video code such as hacks + ----------------------------------------------------------------------- */ + +#include "Common.h" + +struct ProjectionHack +{ + bool enabled; + float value; + + ProjectionHack() + { + } + + ProjectionHack(bool enabled, float value) + { + ProjectionHack::enabled = enabled; + ProjectionHack::value = value; + } +}; + +/* ------------------- + Projection Control + ------------------- */ +void Projection_SetHack0(bool value); +void Projection_SetHack1(ProjectionHack value); +void Projection_SetHack2(ProjectionHack value); +void Projection_SetFreeLook(bool enabled); + +bool Projection_GetHack0(); +ProjectionHack Projection_GetHack1(); +ProjectionHack Projection_GetHack2(); +bool Projection_GetFreeLook(); diff --git a/Source/Core/VideoCommon/Src/SConscript b/Source/Core/VideoCommon/Src/SConscript index 882dd8d629..e1e79adfa3 100644 --- a/Source/Core/VideoCommon/Src/SConscript +++ b/Source/Core/VideoCommon/Src/SConscript @@ -3,6 +3,7 @@ Import('env') files = [ + 'GlobalControl.cpp', 'BPMemory.cpp', 'CPMemory.cpp', 'XFMemory.cpp', diff --git a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp index 56ce20782e..a742ec0a84 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp @@ -29,6 +29,7 @@ #include "CPMemory.h" #include "XFMemory.h" #include "VideoCommon.h" +#include "GlobalControl.h" // Temporary ugly declaration. namespace VertexManager @@ -75,7 +76,7 @@ void VertexShaderManager::Shutdown() } // Syncs the shader constant buffers with xfmem // TODO: A cleaner way to control the matricies without making a mess in the parameters field -void VertexShaderManager::SetConstants(bool proj_hax_1,bool Hack_hack1 ,float Hack_value1 ,bool Hack_hack2 ,float Hack_value2 ,bool freeLook) +void VertexShaderManager::SetConstants() { // TODO: Is this still needed? @@ -268,6 +269,11 @@ void VertexShaderManager::SetConstants(bool proj_hax_1,bool Hack_hack1 ,float Ha } else { + // Get the hacks + ProjectionHack hack1 = Projection_GetHack1(); + ProjectionHack hack2 = Projection_GetHack2(); + bool hack0 = Projection_GetHack0(); + // Orthographic Projection g_fProjectionMatrix[0] = xfregs.rawProjection[0]; g_fProjectionMatrix[1] = 0.0f; @@ -281,8 +287,8 @@ void VertexShaderManager::SetConstants(bool proj_hax_1,bool Hack_hack1 ,float Ha g_fProjectionMatrix[8] = 0.0f; g_fProjectionMatrix[9] = 0.0f; - g_fProjectionMatrix[10] = (Hack_hack1 ? -(Hack_value1 + xfregs.rawProjection[4]) : xfregs.rawProjection[4]); - g_fProjectionMatrix[11] = (Hack_hack2 ? -(Hack_value2 + xfregs.rawProjection[5]) : xfregs.rawProjection[5]) + (proj_hax_1 ? 0.1f : 0.0f); + g_fProjectionMatrix[10] = (hack1.enabled ? -(hack1.value + xfregs.rawProjection[4]) : xfregs.rawProjection[4]); + g_fProjectionMatrix[11] = (hack2.enabled ? -(hack2.value + xfregs.rawProjection[5]) : xfregs.rawProjection[5]) + (hack0 ? 0.1f : 0.0f); g_fProjectionMatrix[12] = 0.0f; g_fProjectionMatrix[13] = 0.0f; @@ -316,7 +322,7 @@ void VertexShaderManager::SetConstants(bool proj_hax_1,bool Hack_hack1 ,float Ha PRIM_LOG("Projection: %f %f %f %f %f %f\n", xfregs.rawProjection[0], xfregs.rawProjection[1], xfregs.rawProjection[2], xfregs.rawProjection[3], xfregs.rawProjection[4], xfregs.rawProjection[5]); - if (freeLook) + if (Projection_GetFreeLook()) { Matrix44 mtxA; Matrix44 mtxB; diff --git a/Source/Core/VideoCommon/Src/VertexShaderManager.h b/Source/Core/VideoCommon/Src/VertexShaderManager.h index b88d40415e..a88934a5a4 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderManager.h +++ b/Source/Core/VideoCommon/Src/VertexShaderManager.h @@ -28,7 +28,7 @@ public: static void Shutdown(); // constant management - static void SetConstants(bool proj_hax_1,bool Hack_hack1, float Hack_value1, bool Hack_hack2, float Hack_value2, bool freeLook); + static void SetConstants(); static void SetViewport(float* _Viewport); static void SetViewportChanged(); diff --git a/Source/Core/VideoCommon/VideoCommon.vcproj b/Source/Core/VideoCommon/VideoCommon.vcproj index 1335ab1ea8..9599c9a7f7 100644 --- a/Source/Core/VideoCommon/VideoCommon.vcproj +++ b/Source/Core/VideoCommon/VideoCommon.vcproj @@ -673,6 +673,14 @@ > + + + + diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp b/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp index 5de52184cd..46e8d97b12 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp @@ -235,7 +235,7 @@ void Flush() if (numVertices) { // set global constants - VertexShaderManager::SetConstants(false, false, 0, false, 0, false); + VertexShaderManager::SetConstants(); PixelShaderManager::SetConstants(); PixelShaderCache::SetShader(); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/GUI/ConfigDlg.cpp b/Source/Plugins/Plugin_VideoOGL/Src/GUI/ConfigDlg.cpp index b4d8d2bfd9..c1bc0d9e28 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/GUI/ConfigDlg.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/GUI/ConfigDlg.cpp @@ -30,6 +30,7 @@ #include "../TextureMngr.h" #include "VertexShaderManager.h" #include "../PostProcessing.h" +#include "GlobalControl.h" BEGIN_EVENT_TABLE(GFXConfigDialogOGL,wxDialog) EVT_CLOSE(GFXConfigDialogOGL::OnClose) @@ -700,6 +701,7 @@ void GFXConfigDialogOGL::AdvancedSettingsChanged(wxCommandEvent& event) break; case ID_FREELOOK: g_Config.bFreeLook = m_FreeLook->IsChecked(); + Projection_SetFreeLook(g_Config.bFreeLook); break; case ID_TEXTUREPATH: break; @@ -835,5 +837,10 @@ void Config::UpdateProjectionHack() g_Config.bProjHack1 = 0; break; } + + // Set the projections hacks + Projection_SetHack0(g_Config.bProjHack1); + Projection_SetHack1(ProjectionHack(g_Config.bPhackvalue1 == 0 ? false : true, g_Config.fhackvalue1)); + Projection_SetHack2(ProjectionHack(g_Config.bPhackvalue2 == 0 ? false : true, g_Config.fhackvalue2)); } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp index 0038a715d3..882fc2a598 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp @@ -261,7 +261,7 @@ void Flush() VERTEXSHADER* vs = VertexShaderCache::GetShader(g_nativeVertexFmt->m_components); // set global constants - VertexShaderManager::SetConstants(g_Config.bProjHack1,g_Config.bPhackvalue1, g_Config.fhackvalue1, g_Config.bPhackvalue2, g_Config.fhackvalue2, g_Config.bFreeLook); + VertexShaderManager::SetConstants(); PixelShaderManager::SetConstants(); // finally bind