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

@ -1291,14 +1291,6 @@
>
</File>
</Filter>
<File
RelativePath=".\Src\Config.cpp"
>
</File>
<File
RelativePath=".\Src\Config.h"
>
</File>
<File
RelativePath=".\Src\Globals.h"
>

View File

@ -207,9 +207,9 @@ void SetColorMask(const BPCmd &bp)
void CopyEFB(const BPCmd &bp, const EFBRectangle &rc, const u32 &address, const bool &fromZBuffer, const bool &isIntensityFmt, const u32 &copyfmt, const int &scaleByHalf)
{
if (!g_Config.bEFBCopyDisable)
if (!g_ActiveConfig.bEFBCopyDisable)
{
//if (g_Config.bCopyEFBToRAM)
//if (g_ActiveConfig.bCopyEFBToRAM)
// To RAM, not implemented yet
//TextureConverter::EncodeToRam(address, fromZBuffer, isIntensityFmt, copyfmt, scaleByHalf, rc);
//else // To D3D Texture
@ -286,12 +286,12 @@ u8 *GetPointer(const u32 &address)
void SetSamplerState(const BPCmd &bp)
{
FourTexUnits &tex = bpmem.tex[(bp.address & 0xE0) == 0xA0];
const FourTexUnits &tex = bpmem.tex[(bp.address & 0xE0) == 0xA0];
int stage = (bp.address & 3);//(addr>>4)&2;
TexMode0 &tm0 = tex.texMode0[stage];
const TexMode0 &tm0 = tex.texMode0[stage];
D3DTEXTUREFILTERTYPE min, mag, mip;
if (g_Config.bForceFiltering)
if (g_ActiveConfig.bForceFiltering)
{
min = mag = mip = D3DTEXF_LINEAR;
}
@ -304,7 +304,7 @@ void SetSamplerState(const BPCmd &bp)
if ((bp.address & 0xE0) == 0xA0)
stage += 4;
if (g_Config.bForceMaxAniso)
if (g_ActiveConfig.iMaxAnisotropy > 1)
{
mag = D3DTEXF_ANISOTROPIC;
min = D3DTEXF_ANISOTROPIC;
@ -314,7 +314,7 @@ void SetSamplerState(const BPCmd &bp)
dev->SetSamplerState(stage, D3DSAMP_MAGFILTER, mag);
dev->SetSamplerState(stage, D3DSAMP_MIPFILTER, mip);
dev->SetSamplerState(stage, D3DSAMP_MAXANISOTROPY, 16);
dev->SetSamplerState(stage, D3DSAMP_MAXANISOTROPY, g_ActiveConfig.iMaxAnisotropy);
dev->SetSamplerState(stage, D3DSAMP_ADDRESSU, d3dClamps[tm0.wrap_s]);
dev->SetSamplerState(stage, D3DSAMP_ADDRESSV, d3dClamps[tm0.wrap_t]);
//wip
@ -323,8 +323,10 @@ void SetSamplerState(const BPCmd &bp)
//sprintf(temp,"lod %f",tm0.lod_bias/4.0f);
//g_VideoInitialize.pLog(temp);
}
void SetInterlacingMode(const BPCmd &bp)
{
// TODO
}
};

View File

@ -1,123 +0,0 @@
// 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 "Config.h"
#include "IniFile.h"
#include "globals.h"
#include "../../../Core/Core/Src/ConfigManager.h" // FIXME
Config g_Config;
Config::Config()
{
}
void Config::Load()
{
IniFile iniFile;
iniFile.Load(FULL_CONFIG_DIR "gfx_dx9.ini");
iniFile.Get("Hardware", "Adapter", &iAdapter, 0);
iniFile.Get("Hardware", "WindowedRes", &iWindowedRes, 0);
iniFile.Get("Hardware", "FullscreenRes", &iFSResolution, 0);
iniFile.Get("Hardware", "Fullscreen", &bFullscreen, 0);
iniFile.Get("Hardware", "RenderInMainframe", &renderToMainframe, false);
iniFile.Get("Hardware", "VSync", &bVsync, 0);
if (iAdapter == -1)
iAdapter = 0;
iniFile.Get("Settings", "OverlayStats", &bOverlayStats, false);
iniFile.Get("Settings", "OverlayProjection", &bOverlayProjStats, false);
iniFile.Get("Settings", "Postprocess", &iPostprocessEffect, 0);
iniFile.Get("Settings", "DumpTextures", &bDumpTextures, 0);
iniFile.Get("Settings", "DumpFrames", &bDumpFrames, 0);
iniFile.Get("Settings", "ShowShaderErrors", &bShowShaderErrors, 0);
iniFile.Get("Settings", "Multisample", &iMultisampleMode, 0);
iniFile.Get("Settings", "TexDumpPath", &texDumpPath, 0);
iniFile.Get("Settings", "TexFmtOverlayEnable", &bTexFmtOverlayEnable, 0);
iniFile.Get("Settings", "TexFmtOverlayCenter", &bTexFmtOverlayCenter, 0);
iniFile.Get("Enhancements", "ForceFiltering", &bForceFiltering, 0);
iniFile.Get("Enhancements", "ForceMaxAniso", &bForceMaxAniso, 0);
}
void Config::Save()
{
IniFile iniFile;
iniFile.Load(FULL_CONFIG_DIR "gfx_dx9.ini");
iniFile.Set("Hardware", "Adapter", iAdapter);
iniFile.Set("Hardware", "WindowedRes", iWindowedRes);
iniFile.Set("Hardware", "FullscreenRes", iFSResolution);
iniFile.Set("Hardware", "Fullscreen", bFullscreen);
iniFile.Set("Hardware", "VSync", bVsync);
iniFile.Set("Hardware", "RenderInMainframe", renderToMainframe);
iniFile.Set("Settings", "OverlayStats", bOverlayStats);
iniFile.Set("Settings", "OverlayProjection", bOverlayProjStats);
iniFile.Set("Settings", "Postprocess", iPostprocessEffect);
iniFile.Set("Settings", "DumpTextures", bDumpTextures);
iniFile.Set("Settings", "DumpFrames", bDumpFrames);
iniFile.Set("Settings", "ShowShaderErrors", bShowShaderErrors);
iniFile.Set("Settings", "Multisample", iMultisampleMode);
iniFile.Set("Settings", "TexDumpPath", texDumpPath);
iniFile.Set("Settings", "TexFmtOverlayEnable", bTexFmtOverlayEnable);
iniFile.Set("Settings", "TexFmtOverlayCenter", bTexFmtOverlayCenter);
iniFile.Set("Enhancements", "ForceFiltering", bForceFiltering);
iniFile.Set("Enhancements", "ForceMaxAniso", bForceMaxAniso);
iniFile.Save(FULL_CONFIG_DIR "gfx_dx9.ini");
}
void Config::GameIniLoad()
{
// This function is copied from OGL plugin, slightly modified.
IniFile *iniFile = ((struct SConfig *)globals->config)->m_LocalCoreStartupParameter.gameIni;
if (! iniFile)
return;
if (iniFile->Exists("Video", "ForceFiltering"))
iniFile->Get("Video", "ForceFiltering", &bForceFiltering, 0);
//if (iniFile->Exists("Video", "MaxAnisotropy"))
// iniFile->Get("Video", "MaxAnisotropy", &iMaxAnisotropy, 3); // NOTE - this is x in (1 << x)
if (iniFile->Exists("Video", "EFBCopyDisable"))
iniFile->Get("Video", "EFBCopyDisable", &bEFBCopyDisable, 0);
//if (iniFile->Exists("Video", "EFBCopyDisableHotKey"))
// iniFile->Get("Video", "EFBCopyDisableHotKey", &bEFBCopyDisableHotKey, 0);
if (iniFile->Exists("Video", "EFBToRAMEnable"))
iniFile->Get("Video", "EFBToRAMEnable", &bCopyEFBToRAM, 0);
if (iniFile->Exists("Video", "SafeTextureCache"))
iniFile->Get("Video", "SafeTextureCache", &bSafeTextureCache, bSafeTextureCache);
//if (iniFile->Exists("Video", "MSAA"))
// iniFile->Get("Video", "MSAA", &iMultisampleMode, 0);
if (iniFile->Exists("Video", "DstAlphaPass"))
iniFile->Get("Video", "DstAlphaPass", &bDstAlphaPass, bDstAlphaPass);
if (iniFile->Exists("Video", "UseXFB"))
iniFile->Get("Video", "UseXFB", &bUseXFB, 0);
if (iniFile->Exists("Video", "ProjectionHack"))
iniFile->Get("Video", "ProjectionHack", &iPhackvalue, 0);
}

View File

@ -1,77 +0,0 @@
// 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/
#ifndef _GLOBALS_H
#define _GLOBALS_H
#include <string>
struct Config
{
Config();
void Load();
void Save();
void GameIniLoad();
int iAdapter;
int iFSResolution;
int iMultisampleMode;
int iPostprocessEffect;
bool renderToMainframe;
bool bFullscreen;
bool bVsync;
bool bWireFrame;
bool bOverlayStats;
bool bOverlayProjStats;
bool bDumpTextures;
bool bDumpFrames;
bool bOldCard;
bool bShowShaderErrors;
//enhancements
bool bForceFiltering;
bool bForceMaxAniso;
bool bPreUpscale;
int iPreUpscaleFilter;
bool bTruform;
int iTruformLevel;
int iWindowedRes;
char psProfile[16];
char vsProfile[16];
bool bTexFmtOverlayEnable;
bool bTexFmtOverlayCenter;
// from game INI file, import from OGL plugin
bool bSafeTextureCache;
bool bEFBCopyDisable;
bool bCopyEFBToRAM;
bool bDstAlphaPass;
bool bUseXFB;
int iPhackvalue;
std::string texDumpPath;
};
extern Config g_Config;
#endif

View File

@ -19,81 +19,74 @@
#include "Render.h"
#include "XFStructs.h"
namespace D3D
{
bool fullScreen = false;
bool nextFullScreen = false;
LPDIRECT3D9 D3D = NULL; // Used to create the D3DDevice
LPDIRECT3DDEVICE9 dev = NULL; // Our rendering device
LPDIRECT3DSURFACE9 backBuffer;
D3DCAPS9 caps;
int multisample;
int resolution;
const int MaxTextureStages = 9;
const int MaxRenderStates = 210;
const DWORD MaxTextureTypes = 33;
const DWORD MaxSamplerSize = 13;
const DWORD MaxSamplerTypes = 15;
static DWORD m_RenderStates[MaxRenderStates+46];
static DWORD m_TextureStageStates[MaxTextureStages][MaxTextureTypes];
static DWORD m_SamplerStates[MaxSamplerSize][MaxSamplerTypes];
LPDIRECT3DBASETEXTURE9 m_Textures[16];
LPDIRECT3D9 D3D = NULL; // Used to create the D3DDevice
LPDIRECT3DDEVICE9 dev = NULL; // Our rendering device
LPDIRECT3DSURFACE9 backBuffer;
D3DCAPS9 caps;
HWND hWnd;
static bool fullScreen = false;
static bool nextFullScreen = false;
static int multisample;
static int resolution;
static int xres, yres;
#define VENDOR_NVIDIA 4318
#define VENDOR_ATI 4098
RECT client;
HWND hWnd;
int xres, yres;
int cur_adapter;
Shader Ps;
Shader Vs;
static bool bFrameInProgress = false;
bool bFrameInProgress = false;
#define MAX_ADAPTERS 4
static Adapter adapters[MAX_ADAPTERS];
static int numAdapters;
static int cur_adapter;
//enum shit
Adapter adapters[4];
int numAdapters;
// Value caches for state filtering
const int MaxTextureStages = 9;
const int MaxRenderStates = 210;
const DWORD MaxTextureTypes = 33;
const DWORD MaxSamplerSize = 13;
const DWORD MaxSamplerTypes = 15;
static DWORD m_RenderStates[MaxRenderStates+46];
static DWORD m_TextureStageStates[MaxTextureStages][MaxTextureTypes];
static DWORD m_SamplerStates[MaxSamplerSize][MaxSamplerTypes];
LPDIRECT3DBASETEXTURE9 m_Textures[16];
void Enumerate();
void Enumerate();
int GetNumAdapters()
{
return numAdapters;
}
int GetNumAdapters() { return numAdapters; }
const Adapter &GetAdapter(int i) { return adapters[i]; }
const Adapter &GetCurAdapter() { return adapters[cur_adapter]; }
const Adapter &GetAdapter(int i)
{
return adapters[i];
}
HRESULT Init()
{
// Create the D3D object, which is needed to create the D3DDevice.
D3D = Direct3DCreate9(D3D_SDK_VERSION);
if (!D3D)
return E_FAIL;
Enumerate();
return S_OK;
}
const Adapter &GetCurAdapter()
{
return adapters[cur_adapter];
}
void Shutdown()
{
D3D->Release();
D3D = 0;
}
HRESULT Init()
{
// Create the D3D object, which is needed to create the D3DDevice.
if( NULL == ( D3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
return E_FAIL;
void EnableAlphaToCoverage()
{
// Each vendor has their own specific little hack.
if (GetCurAdapter().ident.VendorId == VENDOR_ATI)
D3D::SetRenderState(D3DRS_POINTSIZE, (D3DFORMAT)MAKEFOURCC('A', '2', 'M', '1'));
else
D3D::SetRenderState(D3DRS_ADAPTIVETESS_Y, (D3DFORMAT)MAKEFOURCC('A', 'T', 'O', 'C'));
}
Enumerate();
return S_OK;
}
void EnableAlphaToCoverage()
{
if (GetCurAdapter().ident.VendorId == VENDOR_ATI)
D3D::SetRenderState(D3DRS_POINTSIZE, (D3DFORMAT)MAKEFOURCC('A', '2', 'M', '1'));
else
D3D::SetRenderState(D3DRS_ADAPTIVETESS_Y, (D3DFORMAT)MAKEFOURCC('A', 'T', 'O', 'C'));
}
void InitPP(int adapter, int resolution, int aa_mode, D3DPRESENT_PARAMETERS *pp)
void InitPP(int adapter, int f, int aa_mode, D3DPRESENT_PARAMETERS *pp)
{
int FSResX = adapters[adapter].resolutions[resolution].xres;
int FSResY = adapters[adapter].resolutions[resolution].yres;
@ -119,6 +112,7 @@ namespace D3D
}
else
{
RECT client;
GetClientRect(hWnd, &client);
xres = pp->BackBufferWidth = client.right - client.left;
yres = pp->BackBufferHeight = client.bottom - client.top;
@ -131,12 +125,10 @@ namespace D3D
void Enumerate()
{
numAdapters = D3D::D3D->GetAdapterCount();
for (int i=0; i<numAdapters; i++)
for (int i = 0; i < std::min(MAX_ADAPTERS, numAdapters); i++)
{
Adapter &a = adapters[i];
D3D::D3D->GetAdapterIdentifier(i, 0, &a.ident);
bool isNvidia = a.ident.VendorId == VENDOR_NVIDIA;
// Add multisample modes
@ -184,14 +176,11 @@ namespace D3D
}
}
}
if (a.aa_levels.size() == 1)
{
strcpy(a.aa_levels[0].name, "(Not supported on this device)");
}
int numModes = D3D::D3D->GetAdapterModeCount(i, D3DFMT_X8R8G8B8);
for (int m = 0; m < numModes; m++)
{
D3DDISPLAYMODE mode;
@ -234,26 +223,26 @@ namespace D3D
D3DPRESENT_PARAMETERS d3dpp;
InitPP(adapter, resolution, aa_mode, &d3dpp);
if( FAILED( D3D->CreateDevice(
if (FAILED(D3D->CreateDevice(
adapter,
D3DDEVTYPE_HAL,
wnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&d3dpp, &dev ) ) )
&d3dpp, &dev)))
{
MessageBoxA(wnd,
"Sorry, but it looks like your 3D accelerator is too old,\n"
"or doesn't support features that Dolphin requires.\n"
"Falling back to software vertex processing.\n",
"Dolphin Direct3D plugin", MB_OK | MB_ICONERROR);
if( FAILED( D3D->CreateDevice(
if (FAILED(D3D->CreateDevice(
adapter,
D3DDEVTYPE_HAL,
wnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED,
// |D3DCREATE_MULTITHREADED /* | D3DCREATE_PUREDEVICE*/,
//D3DCREATE_SOFTWARE_VERTEXPROCESSING ,
&d3dpp, &dev ) ) )
&d3dpp, &dev)))
{
MessageBoxA(wnd,
"Software VP failed too. Upgrade your graphics card.",
@ -264,75 +253,53 @@ namespace D3D
dev->GetDeviceCaps(&caps);
dev->GetRenderTarget(0, &backBuffer);
Ps.Major = (D3D::caps.PixelShaderVersion >> 8) & 0xFF;
Ps.Minor = (D3D::caps.PixelShaderVersion) & 0xFF;
Vs.Major = (D3D::caps.VertexShaderVersion >>8) & 0xFF;
Vs.Minor = (D3D::caps.VertexShaderVersion) & 0xFF;
if (caps.NumSimultaneousRTs < 2)
{
MessageBoxA(0, "Warning - your graphics card does not support multiple render targets.", 0, 0);
}
// Device state would normally be set here
return S_OK;
}
ShaderVersion GetShaderVersion()
{
if (Ps.Major < 2)
{
return PSNONE;
}
//good enough estimate - we really only
//care about zero shader vs ps20
return (ShaderVersion)Ps.Major;
}
void Close()
{
dev->Release();
dev = 0;
}
void Shutdown()
{
D3D->Release();
D3D = 0;
}
const D3DCAPS9 &GetCaps()
{
return caps;
}
const D3DCAPS9 &GetCaps()
{
return caps;
}
const char *VertexShaderVersionString()
{
static const char *versions[5] = {"ERROR", "vs_1_4", "vs_2_0", "vs_3_0", "vs_4_0"};
int version = ((D3D::caps.VertexShaderVersion >> 8) & 0xFF);
return versions[std::min(4, version)];
}
LPDIRECT3DSURFACE9 GetBackBufferSurface()
{
return backBuffer;
}
const char *PixelShaderVersionString()
{
static const char *versions[5] = {"ERROR", "ps_1_4", "ps_2_0", "ps_3_0", "ps_4_0"};
int version = ((D3D::caps.PixelShaderVersion >> 8) & 0xFF);
return versions[std::min(4, version)];
}
void ShowD3DError(HRESULT err)
LPDIRECT3DSURFACE9 GetBackBufferSurface()
{
return backBuffer;
}
void ShowD3DError(HRESULT err)
{
switch (err)
{
switch (err)
{
case D3DERR_DEVICELOST:
MessageBoxA(0, "Device Lost", "D3D ERROR", 0);
break;
case D3DERR_INVALIDCALL:
MessageBoxA(0, "Invalid Call", "D3D ERROR", 0);
break;
case D3DERR_DRIVERINTERNALERROR:
MessageBoxA(0, "Driver Internal Error", "D3D ERROR", 0);
break;
case D3DERR_OUTOFVIDEOMEMORY:
MessageBoxA(0, "Out of vid mem", "D3D ERROR", 0);
break;
default:
// MessageBoxA(0,"Other error or success","ERROR",0);
break;
}
case D3DERR_DEVICELOST: PanicAlert("Device Lost"); break;
case D3DERR_INVALIDCALL: PanicAlert("Invalid Call"); break;
case D3DERR_DRIVERINTERNALERROR: PanicAlert("Driver Internal Error"); break;
case D3DERR_OUTOFVIDEOMEMORY: PanicAlert("Out of vid mem"); break;
default:
// MessageBoxA(0,"Other error or success","ERROR",0);
break;
}
}
void Reset()
{
@ -350,7 +317,7 @@ namespace D3D
return fullScreen;
}
int GetDisplayWidth()
int GetDisplayWidth()
{
return xres;
}
@ -369,11 +336,10 @@ namespace D3D
{
if (bFrameInProgress)
{
PanicAlert("BeginFrame WTF");
return false;
}
bFrameInProgress = true;
if (dev)
{
if (clear)
@ -388,14 +354,16 @@ namespace D3D
void EndFrame()
{
if (!bFrameInProgress)
{
PanicAlert("EndFrame WTF");
return;
}
bFrameInProgress = false;
if (dev)
{
dev->EndScene();
dev->Present( NULL, NULL, NULL, NULL );
dev->Present(NULL, NULL, NULL, NULL);
}
if (fullScreen != nextFullScreen)

View File

@ -18,87 +18,75 @@
#ifndef _D3DBASE_H
#define _D3DBASE_H
#include <d3d9.h>
#include <vector>
#include <set>
#ifndef SAFE_RELEASE
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
#endif
#include <d3d9.h>
#include "Common.h"
namespace D3D
{
enum ShaderVersion
{
PSNONE = 0,
PS20 = 2,
PS30 = 3,
PS40 = 4,
};
HRESULT Init();
HRESULT Create(int adapter, HWND wnd, bool fullscreen, int resolution, int aa_mode);
void Close();
void Shutdown();
HRESULT Init();
HRESULT Create(int adapter, HWND wnd, bool fullscreen, int resolution, int aa_mode);
void Close();
void Shutdown();
void Reset();
bool BeginFrame(bool clear=true, u32 color=0, float z=1.0f);
void EndFrame();
void SwitchFullscreen(bool fullscreen);
bool IsFullscreen();
int GetDisplayWidth();
int GetDisplayHeight();
ShaderVersion GetShaderVersion();
LPDIRECT3DSURFACE9 GetBackBufferSurface();
const D3DCAPS9 &GetCaps();
void ShowD3DError(HRESULT err);
void EnableAlphaToCoverage();
// Direct access to the device.
extern IDirect3DDevice9 *dev;
extern IDirect3DDevice9 *dev;
void Reset();
bool BeginFrame(bool clear, u32 color, float z);
void EndFrame();
void SwitchFullscreen(bool fullscreen);
bool IsFullscreen();
int GetDisplayWidth();
int GetDisplayHeight();
LPDIRECT3DSURFACE9 GetBackBufferSurface();
const D3DCAPS9 &GetCaps();
const char *PixelShaderVersionString();
const char *VertexShaderVersionString();
void ShowD3DError(HRESULT err);
// The following are "filtered" versions of the corresponding D3Ddev-> functions.
void SetTexture(DWORD Stage, IDirect3DBaseTexture9 *pTexture);
void SetRenderState(D3DRENDERSTATETYPE State, DWORD Value);
void SetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value);
void SetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value);
// The following are "filtered" versions of the corresponding D3Ddev-> functions.
void SetTexture(DWORD Stage, IDirect3DBaseTexture9 *pTexture);
void SetRenderState(D3DRENDERSTATETYPE State, DWORD Value);
void SetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value);
void SetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value);
struct Resolution
{
char name[32];
int xres;
int yres;
std::set<D3DFORMAT> bitdepths;
std::set<int> refreshes;
};
// Utility functions for vendor specific hacks. So far, just the one.
void EnableAlphaToCoverage();
struct AALevel
{
AALevel(const char *n, D3DMULTISAMPLE_TYPE m, int q) {strcpy(name, n); ms_setting=m; qual_setting=q;}
char name[32];
D3DMULTISAMPLE_TYPE ms_setting;
int qual_setting;
};
struct Resolution
{
char name[32];
int xres;
int yres;
std::set<D3DFORMAT> bitdepths;
std::set<int> refreshes;
};
struct Adapter
{
D3DADAPTER_IDENTIFIER9 ident;
std::vector<Resolution> resolutions;
std::vector<AALevel> aa_levels;
bool supports_alpha_to_coverage;
};
struct AALevel
{
AALevel(const char *n, D3DMULTISAMPLE_TYPE m, int q) {strcpy(name, n); ms_setting=m; qual_setting=q;}
char name[32];
D3DMULTISAMPLE_TYPE ms_setting;
int qual_setting;
};
struct Shader
{
int Minor;
int Major;
};
const Adapter &GetAdapter(int i);
const Adapter &GetCurAdapter();
int GetNumAdapters();
}
struct Adapter
{
D3DADAPTER_IDENTIFIER9 ident;
std::vector<Resolution> resolutions;
std::vector<AALevel> aa_levels;
bool supports_alpha_to_coverage;
};
const Adapter &GetAdapter(int i);
const Adapter &GetCurAdapter();
int GetNumAdapters();
} // namespace
#endif

View File

@ -23,9 +23,6 @@
namespace D3D
{
extern Shader Ps;
extern Shader Vs;
LPDIRECT3DVERTEXSHADER9 CompileVertexShader(const char *code, int len)
{
@ -33,15 +30,12 @@ LPDIRECT3DVERTEXSHADER9 CompileVertexShader(const char *code, int len)
LPD3DXBUFFER shaderBuffer = 0;
LPD3DXBUFFER errorBuffer = 0;
LPDIRECT3DVERTEXSHADER9 vShader = 0;
HRESULT hr;
static char *versions[5] = {"ERROR", "vs_1_4", "vs_2_0", "vs_3_0", "vs_4_0"};
hr = D3DXCompileShader(code, len, 0, 0, "main", versions[Vs.Major], 0, &shaderBuffer, &errorBuffer, 0);
HRESULT hr = D3DXCompileShader(code, len, 0, 0, "main", D3D::VertexShaderVersionString(),
0, &shaderBuffer, &errorBuffer, 0);
if (FAILED(hr))
{
//compilation error
if(g_Config.bShowShaderErrors) {
if (g_ActiveConfig.bShowShaderErrors) {
std::string hello = (char*)errorBuffer->GetBufferPointer();
hello += "\n\n";
hello += code;
@ -55,9 +49,9 @@ LPDIRECT3DVERTEXSHADER9 CompileVertexShader(const char *code, int len)
HRESULT hr = E_FAIL;
if (shaderBuffer)
hr = D3D::dev->CreateVertexShader((DWORD *)shaderBuffer->GetBufferPointer(), &vShader);
if ((FAILED(hr) || vShader == 0) && g_Config.bShowShaderErrors)
if ((FAILED(hr) || vShader == 0) && g_ActiveConfig.bShowShaderErrors)
{
MessageBoxA(0, code, (char*)errorBuffer->GetBufferPointer(),MB_ICONERROR);
MessageBoxA(0, code, (char*)errorBuffer->GetBufferPointer(), MB_ICONERROR);
}
}
@ -66,7 +60,6 @@ LPDIRECT3DVERTEXSHADER9 CompileVertexShader(const char *code, int len)
shaderBuffer->Release();
if (errorBuffer)
errorBuffer->Release();
return vShader;
}
@ -75,17 +68,16 @@ LPDIRECT3DPIXELSHADER9 CompilePixelShader(const char *code, int len)
LPD3DXBUFFER shaderBuffer = 0;
LPD3DXBUFFER errorBuffer = 0;
LPDIRECT3DPIXELSHADER9 pShader = 0;
static char *versions[5] = {"ERROR", "ps_1_4", "ps_2_0", "ps_3_0", "ps_4_0"};
HRESULT hr;
// For some reasons, i had this kind of errors : "Shader uses texture addressing operations
// Someone:
// For some reason, I had this kind of errors : "Shader uses texture addressing operations
// in a dependency chain that is too complex for the target shader model (ps_2_0) to handle."
hr = D3DXCompileShader(code, len, 0, 0, "main", versions[Ps.Major],
0, &shaderBuffer, &errorBuffer, 0);
HRESULT hr = D3DXCompileShader(code, len, 0, 0, "main", D3D::PixelShaderVersionString(),
0, &shaderBuffer, &errorBuffer, 0);
if (FAILED(hr))
{
if(g_Config.bShowShaderErrors) {
if (g_ActiveConfig.bShowShaderErrors) {
std::string hello = (char*)errorBuffer->GetBufferPointer();
hello += "\n\n";
hello += code;
@ -97,7 +89,7 @@ LPDIRECT3DPIXELSHADER9 CompilePixelShader(const char *code, int len)
{
//create it
HRESULT hr = D3D::dev->CreatePixelShader((DWORD *)shaderBuffer->GetBufferPointer(), &pShader);
if ((FAILED(hr) || pShader == 0) && g_Config.bShowShaderErrors)
if ((FAILED(hr) || pShader == 0) && g_ActiveConfig.bShowShaderErrors)
{
MessageBoxA(0, "damn", "error creating pixelshader", MB_ICONERROR);
}
@ -108,7 +100,6 @@ LPDIRECT3DPIXELSHADER9 CompilePixelShader(const char *code, int len)
shaderBuffer->Release();
if (errorBuffer)
errorBuffer->Release();
return pShader;
}

View File

@ -161,21 +161,22 @@ namespace D3D
int CD3DFont::Shutdown()
{
SAFE_RELEASE(m_pVB);
SAFE_RELEASE(m_pTexture);
m_pVB->Release();
m_pVB = NULL;
m_pTexture->Release();
m_pTexture = NULL;
return S_OK;
}
const int RS[6][2] =
{
{ D3DRS_ALPHABLENDENABLE, TRUE },
{ D3DRS_SRCBLEND, D3DBLEND_SRCALPHA },
{ D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA },
{ D3DRS_CULLMODE, D3DCULL_NONE },
{ D3DRS_ZENABLE, FALSE },
{ D3DRS_FOGENABLE, FALSE },
{D3DRS_ALPHABLENDENABLE, TRUE},
{D3DRS_SRCBLEND, D3DBLEND_SRCALPHA},
{D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA},
{D3DRS_CULLMODE, D3DCULL_NONE},
{D3DRS_ZENABLE, FALSE},
{D3DRS_FOGENABLE, FALSE},
};
const int TS[6][2] =
{
@ -250,8 +251,8 @@ namespace D3D
float vpWidth = 1;
float vpHeight = 1;
float sx = x*vpWidth-0.5f;
float sy = y*vpHeight-0.5f;
float sx = x*vpWidth-0.5f;
float sy = y*vpHeight-0.5f;
float fStartX = sx;
@ -267,12 +268,12 @@ namespace D3D
float mx=0;
float maxx=0;
while(*strText)
while (*strText)
{
char c = *strText++;
if (c == ('\n'))
mx=0;
mx = 0;
if (c < (' '))
continue;

View File

@ -19,7 +19,7 @@
#include "IniFile.h"
#include "Debugger.h"
#include "../Config.h"
#include "Config.h"
#include "../Globals.h"
#include "../D3DBase.h"

View File

@ -44,7 +44,7 @@ struct TabDirect3D : public W32Util::Tab
{
WCHAR tempwstr[2000];
for (int i=0; i<D3D::GetNumAdapters(); i++)
for (int i = 0; i < D3D::GetNumAdapters(); i++)
{
const D3D::Adapter &adapter = D3D::GetAdapter(i);
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, adapter.ident.Description, -1, tempwstr, 2000);
@ -52,8 +52,7 @@ struct TabDirect3D : public W32Util::Tab
}
const D3D::Adapter &adapter = D3D::GetAdapter(g_Config.iAdapter);
ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_ADAPTER),g_Config.iAdapter);
ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_ADAPTER), g_Config.iAdapter);
for (int i = 0; i < (int)adapter.aa_levels.size(); i++)
{
@ -86,7 +85,7 @@ struct TabDirect3D : public W32Util::Tab
CheckDlgButton(hDlg, IDC_FULLSCREENENABLE, g_Config.bFullscreen ? TRUE : FALSE);
CheckDlgButton(hDlg, IDC_VSYNC, g_Config.bVsync ? TRUE : FALSE);
CheckDlgButton(hDlg, IDC_RENDER_TO_MAINWINDOW, g_Config.renderToMainframe ? TRUE : FALSE);
CheckDlgButton(hDlg, IDC_RENDER_TO_MAINWINDOW, g_Config.RenderToMainframe ? TRUE : FALSE);
}
void Command(HWND hDlg,WPARAM wParam)
@ -108,8 +107,8 @@ struct TabDirect3D : public W32Util::Tab
g_Config.iFSResolution = ComboBox_GetCurSel(GetDlgItem(hDlg,IDC_RESOLUTION));
g_Config.bFullscreen = Button_GetCheck(GetDlgItem(hDlg, IDC_FULLSCREENENABLE)) ? true : false;
g_Config.bVsync = Button_GetCheck(GetDlgItem(hDlg, IDC_VSYNC)) ? true : false;
g_Config.renderToMainframe = Button_GetCheck(GetDlgItem(hDlg, IDC_RENDER_TO_MAINWINDOW)) ? true : false;
g_Config.Save();
g_Config.RenderToMainframe = Button_GetCheck(GetDlgItem(hDlg, IDC_RENDER_TO_MAINWINDOW)) ? true : false;
g_Config.Save(FULL_CONFIG_DIR "gfx_dx9.ini");
}
};
@ -171,6 +170,7 @@ struct TabAdvanced : public W32Util::Tab
//char temp[MAX_PATH];
//GetWindowText(GetDlgItem(hDlg,IDC_TEXDUMPPATH), temp, MAX_PATH); <-- Old method
//g_Config.texDumpPath = temp;
g_Config.Save(FULL_CONFIG_DIR "gfx_dx9.ini");
}
};
@ -179,7 +179,7 @@ struct TabEnhancements : public W32Util::Tab
void Init(HWND hDlg)
{
Button_SetCheck(GetDlgItem(hDlg,IDC_FORCEFILTERING),g_Config.bForceFiltering);
Button_SetCheck(GetDlgItem(hDlg,IDC_FORCEANISOTROPY),g_Config.bForceMaxAniso);
Button_SetCheck(GetDlgItem(hDlg,IDC_FORCEANISOTROPY),g_Config.iMaxAnisotropy > 1);
/*
Temporarily disabled the old postprocessing code since it wasn't working anyway.
New postprocessing code will come sooner or later, sharing shaders and framework with
@ -212,9 +212,9 @@ struct TabEnhancements : public W32Util::Tab
}
void Apply(HWND hDlg)
{
g_Config.bForceMaxAniso = Button_GetCheck(GetDlgItem(hDlg, IDC_FORCEANISOTROPY)) ? true : false;
g_Config.bForceFiltering = Button_GetCheck(GetDlgItem(hDlg,IDC_FORCEFILTERING)) ? true : false;
g_Config.iPostprocessEffect = ComboBox_GetCurSel(GetDlgItem(hDlg,IDC_POSTPROCESSEFFECT));
g_Config.iMaxAnisotropy = Button_GetCheck(GetDlgItem(hDlg, IDC_FORCEANISOTROPY)) ? 8 : 1;
g_Config.bForceFiltering = Button_GetCheck(GetDlgItem(hDlg, IDC_FORCEFILTERING)) ? true : false;
g_Config.Save(FULL_CONFIG_DIR "gfx_dx9.ini");
}
};
@ -224,11 +224,11 @@ void DlgSettings_Show(HINSTANCE hInstance, HWND _hParent)
bool tfoe = g_Config.bTexFmtOverlayEnable;
bool tfoc = g_Config.bTexFmtOverlayCenter;
g_Config.Load();
g_Config.Load(FULL_CONFIG_DIR "gfx_dx9.ini");
W32Util::PropSheet sheet;
sheet.Add(new TabDirect3D,(LPCTSTR)IDD_SETTINGS,_T("Direct3D"));
sheet.Add(new TabEnhancements,(LPCTSTR)IDD_ENHANCEMENTS,_T("Enhancements"));
sheet.Add(new TabAdvanced,(LPCTSTR)IDD_ADVANCED,_T("Advanced"));
sheet.Add(new TabDirect3D, (LPCTSTR)IDD_SETTINGS,_T("Direct3D"));
sheet.Add(new TabEnhancements, (LPCTSTR)IDD_ENHANCEMENTS,_T("Enhancements"));
sheet.Add(new TabAdvanced, (LPCTSTR)IDD_ADVANCED,_T("Advanced"));
#ifdef DEBUGFAST
sheet.Show(hInstance,_hParent,_T("DX9 Graphics Plugin (DEBUGFAST)"));
@ -240,8 +240,6 @@ void DlgSettings_Show(HINSTANCE hInstance, HWND _hParent)
#endif
#endif
g_Config.Save();
if(( tfoe != g_Config.bTexFmtOverlayEnable) ||
((g_Config.bTexFmtOverlayEnable) && ( tfoc != g_Config.bTexFmtOverlayCenter)))
{

View File

@ -27,20 +27,22 @@ HWND GetParentWnd()
LRESULT CALLBACK WndProc( HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam )
{
HDC hdc;
PAINTSTRUCT ps;
switch( iMsg )
{
case WM_PAINT:
hdc = BeginPaint( hWnd, &ps );
EndPaint( hWnd, &ps );
{
HDC hdc;
PAINTSTRUCT ps;
hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
}
return 0;
case WM_KEYDOWN:
switch( LOWORD( wParam ))
{
case VK_ESCAPE: // Pressing Esc switch FullScreen/Windowed
if (g_Config.bFullscreen)
if (g_ActiveConfig.bFullscreen)
{
DestroyWindow(hWnd);
PostQuitMessage(0);
@ -127,6 +129,7 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam )
case WM_SIZE:
// Reset the D3D Device here
// Also make damn sure that this is not called from inside rendering a frame :P
// Renderer::ReinitView();
break;
case WM_SYSCOMMAND:
@ -218,7 +221,6 @@ void Close()
UnregisterClass(m_szClassName, m_hInstance);
}
void SetSize(int width, int height)
{
RECT rc = {0, 0, width, height};
@ -233,4 +235,5 @@ void SetSize(int width, int height)
rc.bottom = rc.top + h;
::MoveWindow(m_hWnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, TRUE);
}
}

View File

@ -136,7 +136,7 @@ bool PixelShaderCache::SetShader(bool dstAlpha)
return true;
}
if (g_Config.bShowShaderErrors)
if (g_ActiveConfig.bShowShaderErrors)
{
PanicAlert("Failed to compile Pixel Shader:\n\n%s", code);
}

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();

View File

@ -48,7 +48,8 @@ void TextureCache::TCacheEntry::Destroy(bool shutdown)
if (texture)
texture->Release();
texture = 0;
if (!isRenderTarget && !shutdown) {
if (!isRenderTarget && !shutdown)
{
u32 *ptr = (u32*)g_VideoInitialize.pGetMemoryPointer(addr + hashoffset*4);
if (ptr && *ptr == hash)
*ptr = oldpixel;
@ -58,7 +59,7 @@ void TextureCache::TCacheEntry::Destroy(bool shutdown)
void TextureCache::Init()
{
temp = (u8*)AllocateMemoryPages(TEMP_SIZE);
TexDecoder_SetTexFmtOverlayOptions(g_Config.bTexFmtOverlayEnable, g_Config.bTexFmtOverlayCenter);
TexDecoder_SetTexFmtOverlayOptions(g_ActiveConfig.bTexFmtOverlayEnable, g_ActiveConfig.bTexFmtOverlayCenter);
}
void TextureCache::Invalidate(bool shutdown)
@ -71,16 +72,14 @@ void TextureCache::Invalidate(bool shutdown)
void TextureCache::Shutdown()
{
Invalidate(true);
FreeMemoryPages(temp, TEMP_SIZE);
temp = NULL;
}
void TextureCache::Cleanup()
{
TexCache::iterator iter=textures.begin();
while(iter != textures.end())
TexCache::iterator iter = textures.begin();
while (iter != textures.end())
{
if (frameCount > TEXTURE_KILL_THRESHOLD + iter->second.frameCount)
{
@ -138,14 +137,14 @@ TextureCache::TCacheEntry *TextureCache::Load(int stage, u32 address, int width,
u32 tex_hash = 0;
u32 texID = address;
if (g_Config.bDumpTextures || g_Config.bSafeTextureCache)
if (g_ActiveConfig.bDumpTextures || g_ActiveConfig.bSafeTextureCache)
{
tex_hash = hash_value;
if ((format == GX_TF_C4) || (format == GX_TF_C8) || (format == GX_TF_C14X2))
{
u32 tlutHash = TexDecoder_GetTlutHash(&texMem[tlutaddr], (format == GX_TF_C4) ? 32 : 128);
tex_hash ^= tlutHash;
if (g_Config.bSafeTextureCache)
if (g_ActiveConfig.bSafeTextureCache)
texID ^= tlutHash;
}
}
@ -154,7 +153,6 @@ TextureCache::TCacheEntry *TextureCache::Load(int stage, u32 address, int width,
if (iter != textures.end())
{
TCacheEntry &entry = iter->second;
if (entry.isRenderTarget || ((address == entry.addr) && (hash_value == entry.hash)))
{
entry.frameCount = frameCount;
@ -163,7 +161,7 @@ TextureCache::TCacheEntry *TextureCache::Load(int stage, u32 address, int width,
return &entry;
}
lastTexture[stage] = entry.texture;
D3D::SetTexture( stage, entry.texture );
D3D::SetTexture(stage, entry.texture);
return &entry;
}
else
@ -232,7 +230,7 @@ TextureCache::TCacheEntry *TextureCache::Load(int stage, u32 address, int width,
entry.fmt = format;
entry.mode = bpmem.tex[stage > 3].texMode0[stage & 3];
if (g_Config.bDumpTextures)
if (g_ActiveConfig.bDumpTextures)
{ // dump texture to file
char szTemp[MAX_PATH];
@ -262,7 +260,7 @@ TextureCache::TCacheEntry *TextureCache::Load(int stage, u32 address, int width,
SETSTAT(stats.numTexturesAlive, (int)textures.size());
//Set the texture!
D3D::SetTexture( stage, entry.texture );
D3D::SetTexture(stage, entry.texture);
lastTexture[stage] = entry.texture;

View File

@ -33,7 +33,7 @@
VertexShaderCache::VSCache VertexShaderCache::vshaders;
const VertexShaderCache::VSCacheEntry *VertexShaderCache::last_entry;
static float lastVSconstants[C_FOGPARAMS+8][4];
static float GC_ALIGNED16(lastVSconstants[C_FOGPARAMS+8][4]);
void SetVSConstant4f(int const_number, float f1, float f2, float f3, float f4)
{
@ -162,7 +162,7 @@ bool VertexShaderCache::SetShader(u32 components)
return true;
}
if (g_Config.bShowShaderErrors)
if (g_ActiveConfig.bShowShaderErrors)
{
PanicAlert("Failed to compile Vertex Shader:\n\n%s", code);
}

View File

@ -25,7 +25,6 @@
#include "LogManager.h"
#include "GlobalControl.h"
#if defined(HAVE_WX) && HAVE_WX
#include "Debugger/Debugger.h"
GFXDebuggerDX9 *m_DebuggerFrame = NULL;
@ -54,6 +53,9 @@ GFXDebuggerDX9 *m_DebuggerFrame = NULL;
#include "VideoState.h"
#include "XFBConvert.h"
// Having to include this is TERRIBLY ugly. FIXME x100
#include "../../../Core/Core/Src/ConfigManager.h" // FIXME
#include "Utils.h"
HINSTANCE g_hInstance = NULL;
@ -174,14 +176,15 @@ void UpdateFPSDisplay(const char *text)
bool Init()
{
g_Config.Load();
g_Config.GameIniLoad();
g_Config.Load(FULL_CONFIG_DIR "gfx_dx9.ini");
IniFile *iniFile = ((struct SConfig *)globals->config)->m_LocalCoreStartupParameter.gameIni;
g_Config.GameIniLoad(iniFile);
UpdateProjectionHack(g_Config.iPhackvalue); // DX9 projection hack could be disabled by commenting out this line
if (initCount == 0)
{
// create the window
if (!g_Config.renderToMainframe || g_VideoInitialize.pWindowHandle == NULL) // ignore parent for this plugin
if (!g_Config.RenderToMainframe || g_VideoInitialize.pWindowHandle == NULL) // ignore parent for this plugin
{
g_VideoInitialize.pWindowHandle = (void*)EmuWindow::Create(NULL, g_hInstance, _T("Loading - Please wait."));
}

View File

@ -75,9 +75,9 @@ STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_SYSMENU
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
GROUPBOX "Texture &filtering",IDC_STATIC,7,7,193,50
CONTROL "Force &bi/trilinear (may cause very small glitches)",IDC_FORCEFILTERING,
CONTROL "Force &bi/trilinear (breaks video in several Wii games)",IDC_FORCEFILTERING,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,20,170,9
CONTROL "Force 16x &anisotropy filtering",IDC_FORCEANISOTROPY,
CONTROL "Enable 16x &anisotropy filtering",IDC_FORCEANISOTROPY,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,35,110,10
GROUPBOX "Texture &enhancements",IDC_STATIC,7,61,193,34
CONTROL "Pre-&upscale:",IDC_PREUPSCALE,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,16,76,54,10