- Fixed: Crash when loading a rom with an unknown file extension.

- Fixed: Crash when stopping a game.
- Improved: DirectX Plugin.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@237 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
NunoRamiro 2008-08-17 19:28:24 +00:00
parent e3f3a7a41d
commit 8c132bdae5
19 changed files with 429 additions and 152 deletions

View File

@ -28,7 +28,7 @@ bool File::IsDirectory(const std::string &filename) {
std::string SanitizePath(const std::string &filename) {
std::string copy = filename;
for (int i = 0; i < copy.size(); i++)
for (size_t i = 0; i < copy.size(); i++)
if (copy[i] == '/')
copy[i] = '\\';
return copy;
@ -81,4 +81,4 @@ bool File::CreateDir(const std::string &path)
#else
// TODO: Insert POSIX code here.
#endif
}
}

View File

@ -323,7 +323,7 @@ bool IniFile::Load(const char* filename)
{
if (line[0] == '[')
{
int endpos = (int)line.find("]");
size_t endpos = line.find("]");
if (endpos != std::string::npos)
{

View File

@ -555,7 +555,7 @@ namespace Gen
}
}
void POP(int bits, const OpArg &reg)
void POP(int /*bits*/, const OpArg &reg)
{
if (reg.IsSimpleReg())
POP(reg.GetSimpleReg());

View File

@ -56,6 +56,7 @@ CEXIMemoryCard::CEXIMemoryCard(const std::string& _rName, const std::string& _rF
{
LOG(EXPANSIONINTERFACE, "No memory card found. Will create new.");
Flush();
Core::DisplayMessage(StringFromFormat("Wrote memory card contents to %s", m_strFilename.c_str()), 4000);
}
formatDelay = 0;
@ -84,14 +85,13 @@ void CEXIMemoryCard::Flush()
}
fwrite(memory_card_content, memory_card_size, 1, pFile);
fclose(pFile);
Core::DisplayMessage(StringFromFormat("Wrote memory card contents to %s", m_strFilename.c_str()), 4000);
}
void CEXIMemoryCard::FlushCallback(u64 userdata, int cyclesLate)
{
CEXIMemoryCard *ptr = reinterpret_cast<CEXIMemoryCard*>(userdata);
ptr->Flush();
Core::DisplayMessage(StringFromFormat("Wrote memory card contents to %s", ptr->GetFileName().c_str()), 4000);
}

View File

@ -36,6 +36,8 @@ public:
//! Is device present?
bool IsPresent();
inline const std::string &GetFileName() const { return m_strFilename; };
private:
// This is scheduled whenever a page write is issued. The this pointer is passed
// through the userdata parameter, so that it can then call Flush on the right card.

View File

@ -70,7 +70,10 @@ bool BootCore(const std::string& _rFilename)
#endif
#endif
StartUp.AutoSetup(SCoreStartupParameter::BOOT_DEFAULT);
if ( !StartUp.AutoSetup(SCoreStartupParameter::BOOT_DEFAULT) )
{
return false;
}
// Load overrides
IniFile ini;

View File

@ -195,7 +195,7 @@ void CFrame::CreateMenu()
pOptionsMenu->Append(IDM_CONFIG_PAD_PLUGIN, _T("&PAD settings"));
pOptionsMenu->AppendSeparator();
pOptionsMenu->Append(IDM_TOGGLE_FULLSCREEN, _T("&Fullscreen"));
pOptionsMenu->AppendCheckItem(IDM_TOGGLE_DUALCORE, _T("&Dual-core (instable!)"));
pOptionsMenu->AppendCheckItem(IDM_TOGGLE_DUALCORE, _T("&Dual-core (unstable!)"));
pOptionsMenu->Check(IDM_TOGGLE_DUALCORE, SConfig::GetInstance().m_LocalCoreStartupParameter.bUseDualCore);
pOptionsMenu->AppendCheckItem(IDM_TOGGLE_THROTTLE, _T("&Enable throttle"));
pOptionsMenu->Check(IDM_TOGGLE_THROTTLE, SConfig::GetInstance().m_LocalCoreStartupParameter.bThrottle);

View File

@ -94,9 +94,15 @@ void BPWritten(int addr, int changes, int newval)
{
CVertexHandler::Flush();
((u32*)&bpmem)[addr] = newval;
dev->SetRenderState(D3DRS_CULLMODE, d3dCullModes[bpmem.genMode.cullmode]);
// dev->SetRenderState(D3DRS_CULLMODE, d3dCullModes[bpmem.genMode.cullmode]);
Renderer::SetRenderState( D3DRS_CULLMODE, d3dCullModes[bpmem.genMode.cullmode] );
if (bpmem.genMode.cullmode == 3)
dev->SetRenderState(D3DRS_COLORWRITEENABLE, 0);
{
// dev->SetRenderState(D3DRS_COLORWRITEENABLE, 0);
Renderer::SetRenderState( D3DRS_COLORWRITEENABLE, 0 );
}
else
{
DWORD write = 0;
@ -104,7 +110,9 @@ void BPWritten(int addr, int changes, int newval)
write = D3DCOLORWRITEENABLE_ALPHA;
if (bpmem.blendmode.colorupdate)
write |= D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE;
dev->SetRenderState(D3DRS_COLORWRITEENABLE, write);
// dev->SetRenderState(D3DRS_COLORWRITEENABLE, write);
Renderer::SetRenderState( D3DRS_COLORWRITEENABLE, write );
}
}
break;
@ -139,15 +147,22 @@ void BPWritten(int addr, int changes, int newval)
((u32*)&bpmem)[addr] = newval;
if (bpmem.zmode.testenable)
{
dev->SetRenderState(D3DRS_ZENABLE, TRUE);
dev->SetRenderState(D3DRS_ZWRITEENABLE, bpmem.zmode.updateenable);
dev->SetRenderState(D3DRS_ZFUNC,d3dCmpFuncs[bpmem.zmode.func]);
// dev->SetRenderState(D3DRS_ZENABLE, TRUE);
// dev->SetRenderState(D3DRS_ZWRITEENABLE, bpmem.zmode.updateenable);
// dev->SetRenderState(D3DRS_ZFUNC,d3dCmpFuncs[bpmem.zmode.func]);
Renderer::SetRenderState( D3DRS_ZENABLE, TRUE );
Renderer::SetRenderState( D3DRS_ZWRITEENABLE, bpmem.zmode.updateenable );
Renderer::SetRenderState( D3DRS_ZFUNC, d3dCmpFuncs[bpmem.zmode.func] );
}
else
{
// if the test is disabled write is disabled too
dev->SetRenderState(D3DRS_ZENABLE, FALSE);
dev->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
// dev->SetRenderState(D3DRS_ZENABLE, FALSE);
// dev->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
Renderer::SetRenderState( D3DRS_ZENABLE, FALSE );
Renderer::SetRenderState( D3DRS_ZWRITEENABLE, FALSE );
}
}
break;
@ -167,9 +182,13 @@ void BPWritten(int addr, int changes, int newval)
if (D3D::GetShaderVersion() == PSNONE)
{
dev->SetRenderState(D3DRS_ALPHATESTENABLE, (Compare)bpmem.alphaFunc.comp0 != COMPARE_ALWAYS);
dev->SetRenderState(D3DRS_ALPHAREF, bpmem.alphaFunc.ref0*4);
dev->SetRenderState(D3DRS_ALPHAFUNC, d3dCmpFuncs[bpmem.alphaFunc.comp0]);
// dev->SetRenderState(D3DRS_ALPHATESTENABLE, (Compare)bpmem.alphaFunc.comp0 != COMPARE_ALWAYS);
// dev->SetRenderState(D3DRS_ALPHAREF, bpmem.alphaFunc.ref0*4);
// dev->SetRenderState(D3DRS_ALPHAFUNC, d3dCmpFuncs[bpmem.alphaFunc.comp0]);
Renderer::SetRenderState( D3DRS_ALPHATESTENABLE, (Compare)bpmem.alphaFunc.comp0 != COMPARE_ALWAYS );
Renderer::SetRenderState( D3DRS_ALPHAREF, bpmem.alphaFunc.ref0 * 4 );
Renderer::SetRenderState( D3DRS_ALPHAFUNC, d3dCmpFuncs[bpmem.alphaFunc.comp0] );
}
// Normally, use texkill in pixel shader to emulate alpha test
}
@ -205,7 +224,11 @@ void BPWritten(int addr, int changes, int newval)
{
CVertexHandler::Flush();
((u32*)&bpmem)[addr] = newval;
if (changes & 1) dev->SetRenderState(D3DRS_ALPHABLENDENABLE,bpmem.blendmode.blendenable);
if (changes & 1)
{
// dev->SetRenderState(D3DRS_ALPHABLENDENABLE,bpmem.blendmode.blendenable);
Renderer::SetRenderState( D3DRS_ALPHABLENDENABLE, bpmem.blendmode.blendenable );
}
if (changes & 2) {} // Logic op blending. D3D can't do this but can fake some modes.
if (changes & 4) {
// Dithering is pointless. Will make things uglier and will be different from GC.
@ -214,24 +237,42 @@ void BPWritten(int addr, int changes, int newval)
D3DBLEND src = d3dSrcFactors[bpmem.blendmode.srcfactor];
D3DBLEND dst = d3dDestFactors[bpmem.blendmode.dstfactor];
if (changes & 0x700) {
dev->SetRenderState(D3DRS_SRCBLEND, src);
if (changes & 0x700)
{
// dev->SetRenderState(D3DRS_SRCBLEND, src);
Renderer::SetRenderState( D3DRS_SRCBLEND, src );
}
if (changes & 0xE0) {
if (!bpmem.blendmode.subtract)
dev->SetRenderState(D3DRS_DESTBLEND, dst);
{
// dev->SetRenderState(D3DRS_DESTBLEND, dst);
Renderer::SetRenderState( D3DRS_DESTBLEND, dst );
}
else
dev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
{
// dev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
Renderer::SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );
}
}
if (changes & 0x800) {
if (bpmem.blendmode.subtract) {
dev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
dev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
} else {
dev->SetRenderState(D3DRS_SRCBLEND, src);
dev->SetRenderState(D3DRS_DESTBLEND, dst);
if (bpmem.blendmode.subtract)
{
// dev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
// dev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
Renderer::SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE );
Renderer::SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );
}
dev->SetRenderState(D3DRS_BLENDOP,bpmem.blendmode.subtract?D3DBLENDOP_SUBTRACT:D3DBLENDOP_ADD);
else
{
// dev->SetRenderState(D3DRS_SRCBLEND, src);
// dev->SetRenderState(D3DRS_DESTBLEND, dst);
Renderer::SetRenderState( D3DRS_SRCBLEND, src );
Renderer::SetRenderState( D3DRS_DESTBLEND, dst );
}
// dev->SetRenderState(D3DRS_BLENDOP,bpmem.blendmode.subtract?D3DBLENDOP_SUBTRACT:D3DBLENDOP_ADD);
Renderer::SetRenderState( D3DRS_BLENDOP, bpmem.blendmode.subtract ? D3DBLENDOP_SUBTRACT : D3DBLENDOP_ADD );
}
//if (bpmem.blendmode.logicopenable) // && bpmem.blendmode.logicmode == 4)
// MessageBox(0,"LOGIC",0,0);
@ -244,7 +285,9 @@ void BPWritten(int addr, int changes, int newval)
write = D3DCOLORWRITEENABLE_ALPHA;
if (bpmem.blendmode.colorupdate)
write |= D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE;
dev->SetRenderState(D3DRS_COLORWRITEENABLE, write);
// dev->SetRenderState(D3DRS_COLORWRITEENABLE, write);
Renderer::SetRenderState( D3DRS_COLORWRITEENABLE, write );
}
}
break;
@ -281,7 +324,9 @@ void BPWritten(int addr, int changes, int newval)
{
CVertexHandler::Flush();
((u32*)&bpmem)[addr] = newval;
dev->SetRenderState(D3DRS_FOGCOLOR,bpmem.fog.color);
// dev->SetRenderState(D3DRS_FOGCOLOR,bpmem.fog.color);
Renderer::SetRenderState( D3DRS_FOGCOLOR, bpmem.fog.color );
}
break;
@ -315,7 +360,10 @@ void BPWritten(int addr, int changes, int newval)
char temp[256];
sprintf(temp,"ScissorRect: %i %i %i %i",rc.left,rc.top,rc.right,rc.bottom);
g_VideoInitialize.pLog(temp, FALSE);
dev->SetRenderState(D3DRS_SCISSORTESTENABLE,TRUE);
// dev->SetRenderState(D3DRS_SCISSORTESTENABLE,TRUE);
Renderer::SetRenderState( D3DRS_SCISSORTESTENABLE, TRUE );
Renderer::SetScissorBox(rc);
}
break;

View File

@ -1,4 +1,6 @@
#include "D3DBase.h"
#include "Render.h"
namespace D3D
{
@ -10,16 +12,14 @@ namespace D3D
int multisample;
int resolution;
#define VENDOR_NVIDIA 4318
#define VENDOR_NVIDIA 4318
RECT client;
HWND hWnd;
int xres, yres;
int cur_adapter;
int psMajor;
int psMinor;
int vsMajor;
int vsMinor;
Shader Ps;
Shader Vs;
bool bFrameInProgress = false;
@ -56,7 +56,8 @@ namespace D3D
void EnableAlphaToCoverage()
{
dev->SetRenderState(D3DRS_ADAPTIVETESS_Y, (D3DFORMAT)MAKEFOURCC('A', 'T', 'O', 'C'));
// dev->SetRenderState(D3DRS_ADAPTIVETESS_Y, (D3DFORMAT)MAKEFOURCC('A', 'T', 'O', 'C'));
Renderer::SetRenderState( D3DRS_ADAPTIVETESS_Y, (D3DFORMAT)MAKEFOURCC('A', 'T', 'O', 'C') );
}
void InitPP(int adapter, int resolution, int aa_mode, D3DPRESENT_PARAMETERS *pp)
@ -234,10 +235,10 @@ namespace D3D
dev->GetDeviceCaps(&caps);
dev->GetRenderTarget(0,&backBuffer);
psMajor = (D3D::caps.PixelShaderVersion >> 8) & 0xFF;
psMinor = (D3D::caps.PixelShaderVersion) & 0xFF;
vsMajor = (D3D::caps.VertexShaderVersion >>8) & 0xFF;
vsMinor = (D3D::caps.VertexShaderVersion) & 0xFF;
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;
// Device state would normally be set here
return S_OK;
@ -245,12 +246,14 @@ namespace D3D
ShaderVersion GetShaderVersion()
{
if (psMajor < 2)
if (Ps.Major < 2)
{
return PSNONE;
else
//good enough estimate - we really only
//care about zero shader vs ps20
return (ShaderVersion)psMajor;
}
//good enough estimate - we really only
//care about zero shader vs ps20
return (ShaderVersion)Ps.Major;
}
void Close()
@ -328,8 +331,10 @@ namespace D3D
bool BeginFrame(bool clear, u32 color, float z)
{
if (bFrameInProgress)
if (bFrameInProgress)
{
return false;
}
bFrameInProgress = true;

View File

@ -16,10 +16,10 @@ namespace D3D
{
enum ShaderVersion
{
PSNONE=0,
PS20=2,
PS30,
PS40,
PSNONE = 0,
PS20 = 2,
PS30 = 3,
PS40 = 4,
};
HRESULT Init();
@ -41,11 +41,6 @@ namespace D3D
void ShowD3DError(HRESULT err);
void EnableAlphaToCoverage();
extern int psMajor;
extern int psMinor;
extern int vsMajor;
extern int vsMinor;
struct Resolution
{
char name[32];
@ -70,10 +65,16 @@ namespace D3D
std::vector<AALevel> aa_levels;
bool supports_alpha_to_coverage;
};
struct Shader
{
int Minor;
int Major;
};
const Adapter &GetAdapter(int i);
const Adapter &GetCurAdapter();
int GetNumAdapters();
}
#endif
#endif

View File

@ -6,6 +6,8 @@
#include "Globals.h"
#include "Render.h"
using namespace D3D;
namespace Postprocess
@ -97,7 +99,10 @@ namespace Postprocess
CreateStuff();
dev->SetRenderTarget(0,mainColorBuffer);
dev->SetDepthStencilSurface(mainZStencilBuffer);
dev->SetRenderState(D3DRS_ZENABLE,TRUE);
// dev->SetRenderState(D3DRS_ZENABLE,TRUE);
Renderer::SetRenderState( D3DRS_ZENABLE, TRUE );
dev->Clear(0,0,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,0,1,0);
}
else
@ -108,26 +113,33 @@ namespace Postprocess
dev->SetDepthStencilSurface(displayZStencilBuffer);
DestroyStuff();
}
dev->SetRenderState(D3DRS_ZENABLE,TRUE);
// dev->SetRenderState(D3DRS_ZENABLE,TRUE);
Renderer::SetRenderState( D3DRS_ZENABLE, TRUE );
}
}
int filterKernel[8] = {0x40,0x80,0xc0,0xFF,0xFF,0xc0,0x80,0x40}; //goodlooking almostgaussian
int filterKernel[8] = {0x40,0x80,0xc0,0xFF,0xFF,0xc0,0x80,0x40}; //good looking almost Gaussian
//int filterKernel[8] = {0xFF,0xc0,0x80,0x40,0x40,0x80,0xc0,0xFF,}; //crazy filter
void NightGlow(bool intense, bool original)
{
dev->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_SUBTRACT);
dev->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
dev->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_ONE);
dev->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ONE);
// dev->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_SUBTRACT);
// dev->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
// dev->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_ONE);
// dev->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ONE);
Renderer::SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SUBTRACT );
Renderer::SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
Renderer::SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE );
Renderer::SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );
dev->SetDepthStencilSurface(0);
dev->SetTexture(0,mainColorBufferTexture);
//dev->SetTexture(0,mainColorBufferTexture);
Renderer::SetTexture( 0, mainColorBufferTexture );
dev->SetRenderTarget(0,scratchSurface[0]);
dev->SetSamplerState(0,D3DSAMP_ADDRESSU,D3DTADDRESS_CLAMP);
dev->SetSamplerState(0,D3DSAMP_ADDRESSV,D3DTADDRESS_CLAMP);
@ -144,9 +156,11 @@ namespace Postprocess
float f=0.008f;
QOFF(0,0,0xa0a0a0a0);
dev->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);
// dev->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);
//dev->SetTexture(0,scratch[0]);
Renderer::SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
Renderer::SetTexture( 0, scratch[0] );
dev->SetTexture(0,scratch[0]);
dev->SetRenderTarget(0,scratchSurface[1]);
dev->Clear(0,0,D3DCLEAR_TARGET,0,0,0);
@ -159,7 +173,9 @@ namespace Postprocess
QOFF(0,(i-3.5f) * f * yMul,c);
}
dev->SetTexture(0,scratch[1]);
//dev->SetTexture(0,scratch[1]);
Renderer::SetTexture( 0, scratch[1] );
dev->SetRenderTarget(0,scratchSurface[0]);
dev->Clear(0,0,D3DCLEAR_TARGET,0,0,0);
for (int i=0; i<8; i++)
@ -170,23 +186,33 @@ namespace Postprocess
QOFF((i-3.5f) * f,0,c);
}
dev->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);
// dev->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);
Renderer::SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
if (intense)
{
dev->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_ONE);
dev->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_SRCALPHA);
// dev->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_ONE);
// dev->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_SRCALPHA);
Renderer::SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE );
Renderer::SetRenderState( D3DRS_DESTBLEND, D3DBLEND_SRCALPHA );
}
else
{
dev->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_INVDESTCOLOR);
dev->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ONE);
// dev->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_INVDESTCOLOR);
// dev->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ONE);
Renderer::SetRenderState( D3DRS_SRCBLEND, D3DBLEND_INVDESTCOLOR );
Renderer::SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );
}
dev->SetTexture(0,scratch[0]);
// dev->SetTexture(0,scratch[0]);
Renderer::SetTexture( 0, scratch[0] );
dev->SetRenderTarget(0,mainColorBuffer);
quad2d(0,0,(float)mainWidth,(float)mainHeight,original?0xCFFFFFFF:0xFFFFFFFF,0,0,1,1);
dev->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
// dev->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
Renderer::SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
dev->SetSamplerState(0,D3DSAMP_ADDRESSU,D3DTADDRESS_WRAP);
dev->SetSamplerState(0,D3DSAMP_ADDRESSV,D3DTADDRESS_WRAP);
//dev->SetSamplerState(0,D3DSAMP_MIPMAPLODBIAS,0);
@ -208,15 +234,25 @@ namespace Postprocess
{
if (initialized)
{
dev->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
dev->SetRenderState(D3DRS_ZENABLE,FALSE);
dev->SetRenderState(D3DRS_FOGENABLE,FALSE);
dev->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
dev->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);
dev->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);
dev->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
dev->SetTextureStageState(0,D3DTSS_ALPHAARG2,D3DTA_DIFFUSE);
dev->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG2);
// dev->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
// dev->SetRenderState(D3DRS_ZENABLE,FALSE);
// dev->SetRenderState(D3DRS_FOGENABLE,FALSE);
// dev->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
// dev->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);
// dev->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);
// dev->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
// dev->SetTextureStageState(0,D3DTSS_ALPHAARG2,D3DTA_DIFFUSE);
// dev->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG2);
Renderer::SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
Renderer::SetRenderState( D3DRS_ZENABLE, FALSE );
Renderer::SetRenderState( D3DRS_FOGENABLE, FALSE );
Renderer::SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
Renderer::SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);
Renderer::SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);
Renderer::SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
Renderer::SetTextureStageState(0,D3DTSS_ALPHAARG2,D3DTA_DIFFUSE);
Renderer::SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG2);
switch(g_Config.iPostprocessEffect) {
case 1:
@ -231,8 +267,11 @@ namespace Postprocess
dev->SetRenderTarget(0,displayColorBuffer);
dev->SetDepthStencilSurface(displayZStencilBuffer);
dev->SetTexture(0,mainColorBufferTexture);
// dev->SetTexture(0,mainColorBufferTexture);
Renderer::SetTexture( 0, mainColorBufferTexture );
quad2d(0, 0, (float)displayWidth, (float)displayHeight, 0xFFFFFFFF);
}
}
}
}

View File

@ -2,6 +2,7 @@
#include "D3DBase.h"
#include "D3DUtil.h"
#include "Render.h"
namespace D3D
{
@ -194,27 +195,44 @@ namespace D3D
void CD3DFont::SetRenderStates()
{
dev->SetTexture(0, m_pTexture);
// dev->SetTexture(0, m_pTexture);
Renderer::SetTexture( 0, m_pTexture );
dev->SetPixelShader(0);
dev->SetVertexShader(0);
dev->SetVertexDeclaration(0);
dev->SetFVF(D3DFVF_FONT2DVERTEX);
// dev->SetFVF(D3DFVF_FONT2DVERTEX);
Renderer::SetFVF(D3DFVF_FONT2DVERTEX);
for (int i = 0; i < 6; i++) {
dev->SetRenderState((_D3DRENDERSTATETYPE)RS[i][0],RS[i][1]);
dev->SetTextureStageState(0, (_D3DTEXTURESTAGESTATETYPE)int(TS[i][0]), TS[i][1]);
// dev->SetRenderState((_D3DRENDERSTATETYPE)RS[i][0],RS[i][1]);
// dev->SetTextureStageState(0, (_D3DTEXTURESTAGESTATETYPE)int(TS[i][0]), TS[i][1]);
Renderer::SetRenderState( (_D3DRENDERSTATETYPE)RS[i][0], RS[i][1] );
Renderer::SetTextureStageState( 0, (_D3DTEXTURESTAGESTATETYPE)int(TS[i][0]), TS[i][1] );
}
}
void RestoreRenderStates()
{
dev->SetTexture(0, texture_old);
// dev->SetTexture(0, texture_old);
Renderer::SetTexture( 0, texture_old );
dev->SetPixelShader(ps_old);
dev->SetVertexShader(vs_old);
dev->SetVertexDeclaration(decl_old);
dev->SetFVF(FVF_old);
for (int i = 0; i < 6; i++) {
dev->SetRenderState((_D3DRENDERSTATETYPE)RS[i][0], RS_old[i]);
dev->SetTextureStageState(0, (_D3DTEXTURESTAGESTATETYPE)int(TS[i][0]), TS_old[i]);
// dev->SetFVF(FVF_old);
Renderer::SetFVF(FVF_old);
for (int i = 0; i < 6; i++)
{
// dev->SetRenderState((_D3DRENDERSTATETYPE)RS[i][0], RS_old[i]);
// dev->SetTextureStageState(0, (_D3DTEXTURESTAGESTATETYPE)int(TS[i][0]), TS_old[i]);
Renderer::SetRenderState( (_D3DRENDERSTATETYPE)RS[i][0], RS_old[i] );
Renderer::SetTextureStageState( 0, (_D3DTEXTURESTAGESTATETYPE)int(TS[i][0]), TS_old[i] );
}
}
@ -312,11 +330,14 @@ namespace D3D
pVertices+=6;
dwNumTriangles += 2;
if( dwNumTriangles*3 > (MAX_NUM_VERTICES-6) )
if( dwNumTriangles * 3 > (MAX_NUM_VERTICES-6) )
{
// Unlock, render, and relock the vertex buffer
m_pVB->Unlock();
dev->DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles );
// dev->DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles );
Renderer::DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles );
m_pVB->Lock( 0, 0, (void**)&pVertices, D3DLOCK_DISCARD );
dwNumTriangles = 0;
}
@ -327,7 +348,10 @@ namespace D3D
// Unlock and render the vertex buffer
m_pVB->Unlock();
if( dwNumTriangles > 0 )
dev->DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles );
{
// dev->DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles );
Renderer::DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles );
}
RestoreRenderStates();
return S_OK;
}
@ -344,8 +368,12 @@ namespace D3D
dev->SetPixelShader(0);
dev->SetVertexShader(0);
dev->SetVertexDeclaration(0);
dev->SetFVF(D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1);
dev->DrawPrimitiveUP(D3DPT_TRIANGLEFAN,2,coords,sizeof(Q2DVertex));
// dev->SetFVF(D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1);
// dev->DrawPrimitiveUP(D3DPT_TRIANGLEFAN,2,coords,sizeof(Q2DVertex));
Renderer::SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);
Renderer::DrawPrimitiveUP(D3DPT_TRIANGLEFAN,2,coords,sizeof(Q2DVertex));
RestoreRenderStates();
}

View File

@ -2,8 +2,6 @@
#include "Common.h"
#include "D3DBase.h"
#include "Globals.h"
#include "main.h"
#include "VertexHandler.h"
@ -19,21 +17,29 @@
#include "EmuWindow.h"
#include <list>
using namespace std;
float Renderer::m_x,Renderer::m_y,Renderer::m_width, Renderer::m_height, Renderer::xScale,Renderer::yScale;
std::vector<LPDIRECT3DBASETEXTURE9> Renderer::m_Textures;
DWORD Renderer::m_RenderStates[MaxRenderStates];
DWORD Renderer::m_TextureStageStates[MaxTextureStages][MaxTextureTypes];
DWORD Renderer::m_SamplerStates[MaxSamplerSize][MaxSamplerTypes];
DWORD Renderer::m_FVF;
#define NUMWNDRES 6
extern int g_Res[NUMWNDRES][2];
struct MESSAGE
struct Message
{
MESSAGE() {}
MESSAGE(const char* p, u32 dw) { strcpy(str, p); dwTimeStamp = dw; }
char str[255];
Message(const std::string &msg, u32 dw) : message( msg ), dwTimeStamp( dw )
{
}
std::string message;
u32 dwTimeStamp;
};
static std::list<MESSAGE> s_listMsgs;
};
static std::list<Message> s_listMsgs;
void Renderer::Init(SVideoInitialize &_VideoInitialize)
{
@ -64,11 +70,14 @@ void Renderer::Shutdown(void)
void Renderer::Initialize(void)
{
D3D::dev->SetRenderState(D3DRS_LIGHTING,FALSE);
D3D::dev->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);
D3D::dev->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
D3D::dev->SetRenderState(D3DRS_FOGENABLE, FALSE);
D3D::dev->SetRenderState(D3DRS_FILLMODE, g_Config.bWireFrame?D3DFILL_WIREFRAME:D3DFILL_SOLID);
m_FVF = 0;
m_Textures.reserve( MaxTextureStages );
for ( int i = 0; i < MaxTextureStages; i++ )
{
m_Textures.push_back( NULL );
}
for (int i=0; i<8; i++)
{
D3D::dev->SetSamplerState(i, D3DSAMP_MAXANISOTROPY, 16);
@ -81,16 +90,16 @@ void Renderer::Initialize(void)
CVertexHandler::BeginFrame();
}
void Renderer::AddMessage(const char* pstr, u32 ms)
void Renderer::AddMessage(const std::string &message, u32 ms)
{
s_listMsgs.push_back(MESSAGE(pstr, timeGetTime()+ms));
s_listMsgs.push_back(Message(message, timeGetTime()+ms));
}
void Renderer::ProcessMessages()
{
if (s_listMsgs.size() > 0) {
int left = 25, top = 15;
list<MESSAGE>::iterator it = s_listMsgs.begin();
std::list<Message>::iterator it = s_listMsgs.begin();
while( it != s_listMsgs.end() )
{
@ -105,8 +114,8 @@ void Renderer::ProcessMessages()
alpha <<= 24;
RenderText(it->str, left+1, top+1, 0x000000|alpha);
RenderText(it->str, left, top, 0xffff30|alpha);
RenderText(it->message, left+1, top+1, 0x000000|alpha);
RenderText(it->message, left, top, 0xffff30|alpha);
top += 15;
if (time_left <= 0)
@ -116,9 +125,9 @@ void Renderer::ProcessMessages()
}
}
void Renderer::RenderText(const char* pstr, int left, int top, u32 color)
void Renderer::RenderText(const std::string &text, int left, int top, u32 color)
{
D3D::font.DrawTextScaled(left,top,20,20,0.0f,color,pstr,false);
D3D::font.DrawTextScaled((float)left, (float)top, 20, 20, 0.0f, color, text.c_str(), false);
}
void dumpMatrix(D3DXMATRIX &mtx)
@ -250,7 +259,7 @@ void Renderer::SwapBuffers(void)
CVertexHandler::BeginFrame();
if (g_Config.bOldCard)
D3D::font.SetRenderStates(); //compatibility with lowend cards
D3D::font.SetRenderStates(); //compatibility with low end cards
}
void Renderer::Flush(void)
@ -359,4 +368,66 @@ void Renderer::SetProjection(float* pMatrix, int constantIndex)
mtx.m[3][3] = 1.0f;
}
D3D::dev->SetVertexShaderConstantF(constantIndex, mtx, 4);
}
}
void Renderer::SetTexture( DWORD Stage, LPDIRECT3DBASETEXTURE9 pTexture )
{
if ( m_Textures[Stage] != pTexture )
{
m_Textures[Stage] = pTexture;
D3D::dev->SetTexture( Stage, pTexture );
}
}
void Renderer::SetFVF( DWORD FVF )
{
if ( m_FVF != FVF )
{
m_FVF = FVF;
D3D::dev->SetFVF( FVF );
}
}
void Renderer::SetRenderState( D3DRENDERSTATETYPE State, DWORD Value )
{
if ( m_RenderStates[State] != Value )
{
m_RenderStates[State] = Value;
D3D::dev->SetRenderState( State, Value );
}
}
void Renderer::SetTextureStageState( DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value )
{
if ( m_TextureStageStates[Stage][Type] != Value )
{
m_TextureStageStates[Stage][Type] = Value;
D3D::dev->SetTextureStageState( Stage, Type, Value );
}
}
void Renderer::SetSamplerState( DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value )
{
if ( m_SamplerStates[Sampler][Type] != Value )
{
m_SamplerStates[Sampler][Type] = Value;
D3D::dev->SetSamplerState( Sampler, Type, Value );
}
}
void Renderer::DrawPrimitiveUP( D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, const void* pVertexStreamZeroData, UINT VertexStreamZeroStride )
{
D3D::dev->DrawPrimitiveUP( PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride );
}
void Renderer::DrawPrimitive( D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount )
{
D3D::dev->DrawPrimitive( PrimitiveType, StartVertex, PrimitiveCount );
}

View File

@ -1,20 +1,35 @@
#pragma once
#ifndef __H_RENDER__
#define __H_RENDER__
#include "PluginSpecs_Video.h"
#include <vector>
#include <string>
#include "D3DBase.h"
class Renderer
{
// screen offset
static float m_x,m_y,m_width, m_height,xScale,yScale;
const static int MaxTextureStages = 9;
const static int MaxRenderStates = 210;
const static DWORD MaxTextureTypes = 33;
const static DWORD MaxSamplerSize = 13;
const static DWORD MaxSamplerTypes = 15;
static std::vector<LPDIRECT3DBASETEXTURE9> m_Textures;
static DWORD m_RenderStates[MaxRenderStates];
static DWORD m_TextureStageStates[MaxTextureStages][MaxTextureTypes];
static DWORD m_SamplerStates[MaxSamplerSize][MaxSamplerTypes];
static DWORD m_FVF;
public:
static void Init(SVideoInitialize &_VideoInitialize);
static void Shutdown();
// initialize opengl standard values (like viewport)
// initialize opengl standard values (like view port)
static void Initialize(void);
// must be called if the windowsize has changed
// must be called if the window size has changed
static void ReinitView(void);
//
// --- Render Functions ---
@ -29,8 +44,63 @@ public:
static void SetProjection(float* _pProjection, int constantIndex = -1);
static void AddMessage(const char* pstr, unsigned int ms);
static void AddMessage(const std::string &message, unsigned int ms);
static void ProcessMessages();
static void RenderText(const char* pstr, int left, int top, unsigned int color);
static void RenderText(const std::string &text, int left, int top, unsigned int color);
/**
* Assigns a texture to a device stage.
* @param Stage Stage to assign to.
* @param pTexture Texture to be assigned.
*/
static void SetTexture( DWORD Stage, IDirect3DBaseTexture9 *pTexture );
/**
* Sets the current vertex stream declaration.
* @param FVF Fixed function vertex type
*/
static void SetFVF( DWORD FVF );
/**
* Sets a single device render-state parameter.
* @param State Device state variable that is being modified.
* @param Value New value for the device render state to be set.
*/
static void SetRenderState( D3DRENDERSTATETYPE State, DWORD Value );
/**
* Sets the state value for the currently assigned texture.
* @param Stage Stage identifier of the texture for which the state value is set.
* @param Type Texture state to set.
* @param Value State value to set.
*/
static void SetTextureStageState( DWORD Stage, D3DTEXTURESTAGESTATETYPE Type,DWORD Value );
/**
* Sets the sampler state value.
* @param Sampler The sampler stage index.
* @param Type Type of the sampler.
* @param Value State value to set.
*/
static void SetSamplerState( DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value );
/**
* Renders data specified by a user memory pointer as a sequence of geometric primitives of the specified type.
* @param PrimitiveType Type of primitive to render.
* @param PrimitiveCount Number of primitives to render.
* @param pVertexStreamZeroData User memory pointer to the vertex data.
* @param VertexStreamZeroStride The number of bytes of data for each vertex.
*/
static void DrawPrimitiveUP( D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount,
const void* pVertexStreamZeroData, UINT VertexStreamZeroStride );
/**
* Renders a sequence of non indexed, geometric primitives of the specified type from the current set of data input streams.
* @param PrimitiveType Type of primitive to render.
* @param StartVertex Index of the first vertex to load.
* @param PrimitiveCount Number of primitives to render.
*/
static void DrawPrimitive( D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount );
};
#endif // __H_RENDER__

View File

@ -117,7 +117,10 @@ void TextureCache::Load(int stage, DWORD address, int width, int height, int for
return;
}
lastTexture[stage] = iter->second.texture;
D3D::dev->SetTexture(stage,iter->second.texture);
// D3D::dev->SetTexture(stage,iter->second.texture);
Renderer::SetTexture( stage, iter->second.texture );
return;
}
else
@ -182,7 +185,9 @@ void TextureCache::Load(int stage, DWORD address, int width, int height, int for
SETSTAT(stats.numTexturesAlive, (int)textures.size());
//Set the texture!
D3D::dev->SetTexture(stage,entry.texture);
// D3D::dev->SetTexture(stage,entry.texture);
Renderer::SetTexture( stage, entry.texture );
lastTexture[stage] = entry.texture;
}
@ -219,4 +224,4 @@ void TextureCache::CopyEFBToRenderTarget(DWORD address, RECT *source)
srcSurface = D3D::GetBackBufferSurface();
D3D::dev->StretchRect(srcSurface,source,destSurface,0,D3DTEXF_NONE);
destSurface->Release();
}
}

View File

@ -33,7 +33,7 @@ void InitLUTs()
}
// Message handler for about box.
LRESULT CALLBACK AboutProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK AboutProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM /*lParam*/)
{
switch (message)
{

View File

@ -49,7 +49,7 @@ inline float Memory_Read_Float(u32 _uAddress)
extern int g_bWriteProfile; // global variable to enable/disable profiling (if DVPROFILE is defined)
// IMPORTANT: For every Reigster there must be an End
// IMPORTANT: For every Register there must be an End
void DVProfRegister(char* pname); // first checks if this profiler exists in g_listProfilers
void DVProfEnd(u32 dwUserData);
void DVProfWrite(char* pfilename, u32 frames = 0);

View File

@ -202,10 +202,12 @@ void CVertexHandler::Flush()
else
{
D3D::dev->SetIndices(0);
D3D::dev->DrawPrimitiveUP(D3DPT_POINTLIST,
numVertices,
fakeVBuffer,
sizeof(D3DVertex));
// D3D::dev->DrawPrimitiveUP(D3DPT_POINTLIST,
// numVertices,
// fakeVBuffer,
// sizeof(D3DVertex));
Renderer::DrawPrimitiveUP( D3DPT_POINTLIST, numVertices, fakeVBuffer, sizeof(D3DVertex) );
}
}
collection = C_NOTHING;

View File

@ -47,7 +47,7 @@ BOOL APIENTRY DllMain( HINSTANCE hinstDLL, // DLL module handle
BOOL Callback_PeekMessages()
{
//TODO: peekmessage
//TODO: peek message
MSG msg;
while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
@ -59,31 +59,34 @@ BOOL Callback_PeekMessages()
return TRUE;
}
void UpdateFPSDisplay(const char *text)
{
char temp[512];
sprintf(temp, "SVN R%i: %s", SVN_REV, text);
SetWindowText(EmuWindow::GetWnd(), temp);
sprintf_s(temp, 512, "SVN R%i: %s", SVN_REV, text);
SetWindowText( EmuWindow::GetWnd(), temp);
}
bool Init()
{
g_Config.Load();
if (initCount==0)
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, "Please wait...");
g_VideoInitialize.pWindowHandle = (void*)EmuWindow::Create(NULL, g_hInstance, "Loading - Please wait.");
}
else
{
g_VideoInitialize.pWindowHandle = (void*)EmuWindow::Create((HWND)g_VideoInitialize.pWindowHandle, g_hInstance, "Please wait...");
g_VideoInitialize.pWindowHandle = (void*)EmuWindow::Create((HWND)g_VideoInitialize.pWindowHandle, g_hInstance, "Loading - Please wait.");
}
if( g_VideoInitialize.pWindowHandle == NULL ) {
MessageBox(GetActiveWindow(), "failed to create window", "Fatal Error", MB_OK);
if ( g_VideoInitialize.pWindowHandle == NULL )
{
MessageBox(GetActiveWindow(), "An error has occurred while trying to create the window.", "Fatal Error", MB_OK);
return false;
}
@ -93,7 +96,7 @@ bool Init()
if (FAILED(D3D::Init()))
{
MessageBox(GetActiveWindow(), "Cant Init D3d.\nYou probably havn't installed\nthe last version(9.0c)", "Fatal Error", MB_OK);
MessageBox(GetActiveWindow(), "Unable to initialize Direct3D. Please make sure that you have DirectX 9.0c correctly installed.", "Fatal Error", MB_OK);
return false;
}
InitLUTs();
@ -184,7 +187,7 @@ void Video_Shutdown(void)
DeInit();
}
void Video_UpdateXFB(BYTE* _pXFB, DWORD _dwWidth, DWORD _dwHeight)
void Video_UpdateXFB(BYTE* /*_pXFB*/, DWORD /*_dwWidth*/, DWORD /*_dwHeight*/)
{
/*
ConvertXFB(tempBuffer, _pXFB, _dwWidth, _dwHeight);