2008-12-07 22:25:12 -07:00
|
|
|
// Copyright (C) 2003-2008 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 <tchar.h>
|
2009-01-15 19:58:34 -07:00
|
|
|
#include <windows.h>
|
2008-12-07 22:25:12 -07:00
|
|
|
#include <d3dx9.h>
|
|
|
|
|
|
|
|
#include "Common.h"
|
|
|
|
|
|
|
|
#include "svnrev.h"
|
|
|
|
#include "resource.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "Config.h"
|
|
|
|
#include "Fifo.h"
|
|
|
|
#include "OpcodeDecoding.h"
|
|
|
|
#include "TextureCache.h"
|
2009-06-22 03:31:30 -06:00
|
|
|
#include "BPStructs.h"
|
2008-12-07 22:25:12 -07:00
|
|
|
#include "VertexManager.h"
|
2008-12-25 13:07:13 -07:00
|
|
|
#include "VertexLoaderManager.h"
|
2009-03-07 16:20:14 -07:00
|
|
|
#include "VertexShaderManager.h"
|
|
|
|
#include "PixelShaderManager.h"
|
|
|
|
#include "VertexShaderCache.h"
|
|
|
|
#include "PixelShaderCache.h"
|
2008-12-07 22:25:12 -07:00
|
|
|
#include "DlgSettings.h"
|
|
|
|
#include "D3DPostprocess.h"
|
|
|
|
#include "D3DTexture.h"
|
|
|
|
#include "D3DUtil.h"
|
|
|
|
#include "W32Util/Misc.h"
|
|
|
|
#include "EmuWindow.h"
|
|
|
|
#include "VideoState.h"
|
|
|
|
#include "XFBConvert.h"
|
|
|
|
|
|
|
|
#include "Utils.h"
|
|
|
|
|
|
|
|
HINSTANCE g_hInstance = NULL;
|
|
|
|
SVideoInitialize g_VideoInitialize;
|
2009-03-18 11:17:58 -06:00
|
|
|
PLUGIN_GLOBALS* globals = NULL;
|
2008-12-07 22:25:12 -07:00
|
|
|
int initCount = 0;
|
|
|
|
|
2009-07-02 11:45:09 -06:00
|
|
|
static volatile u32 s_AccessEFBResult = 0, s_EFBx, s_EFBy;
|
|
|
|
static volatile EFBAccessType s_AccessEFBType;
|
|
|
|
static Common::Event s_AccessEFBDone;
|
|
|
|
static Common::CriticalSection s_criticalEFB;
|
|
|
|
|
2008-12-07 22:25:12 -07:00
|
|
|
|
|
|
|
void DllDebugger(HWND _hParent, bool Show)
|
|
|
|
{
|
|
|
|
// TODO: implement
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOL APIENTRY DllMain( HINSTANCE hinstDLL, // DLL module handle
|
|
|
|
DWORD dwReason, // reason called
|
|
|
|
LPVOID lpvReserved) // reserved
|
|
|
|
{
|
|
|
|
switch (dwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
break;
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hInstance = hinstDLL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-12-11 08:12:17 -07:00
|
|
|
unsigned int Callback_PeekMessages()
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
|
|
|
//TODO: peek message
|
|
|
|
MSG msg;
|
|
|
|
while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
|
|
|
|
{
|
|
|
|
if (msg.message == WM_QUIT)
|
|
|
|
return FALSE;
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UpdateFPSDisplay(const char *text)
|
|
|
|
{
|
|
|
|
char temp[512];
|
|
|
|
sprintf_s(temp, 512, "SVN R%i: DX9: %s", SVN_REV, text);
|
2008-12-25 13:07:13 -07:00
|
|
|
SetWindowText(EmuWindow::GetWnd(), temp);
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Init()
|
|
|
|
{
|
|
|
|
g_Config.Load();
|
|
|
|
|
|
|
|
if (initCount == 0)
|
|
|
|
{
|
|
|
|
// create the window
|
2008-12-25 13:07:13 -07:00
|
|
|
if (!g_Config.renderToMainframe || g_VideoInitialize.pWindowHandle == NULL) // ignore parent for this plugin
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
|
|
|
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, "Loading - Please wait.");
|
|
|
|
}
|
|
|
|
|
2008-12-25 13:07:13 -07:00
|
|
|
if (g_VideoInitialize.pWindowHandle == NULL)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
|
|
|
MessageBox(GetActiveWindow(), "An error has occurred while trying to create the window.", "Fatal Error", MB_OK);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
EmuWindow::Show();
|
|
|
|
g_VideoInitialize.pPeekMessages = Callback_PeekMessages;
|
|
|
|
g_VideoInitialize.pUpdateFPSDisplay = UpdateFPSDisplay;
|
|
|
|
|
|
|
|
if (FAILED(D3D::Init()))
|
|
|
|
{
|
|
|
|
MessageBox(GetActiveWindow(), "Unable to initialize Direct3D. Please make sure that you have DirectX 9.0c correctly installed.", "Fatal Error", MB_OK);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
InitLUTs();
|
|
|
|
InitXFBConvTables();
|
|
|
|
}
|
|
|
|
initCount++;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeInit()
|
|
|
|
{
|
|
|
|
initCount--;
|
2008-12-25 13:07:13 -07:00
|
|
|
if (initCount == 0)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
|
|
|
D3D::Shutdown();
|
|
|
|
EmuWindow::Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-14 23:48:15 -07:00
|
|
|
void GetDllInfo (PLUGIN_INFO* _PluginInfo)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
|
|
|
_PluginInfo->Version = 0x0100;
|
|
|
|
_PluginInfo->Type = PLUGIN_TYPE_VIDEO;
|
2009-01-14 23:48:15 -07:00
|
|
|
#ifdef DEBUGFAST
|
2008-12-25 13:07:13 -07:00
|
|
|
sprintf_s(_PluginInfo->Name, 100, "Dolphin Direct3D9 (DebugFast)");
|
2008-12-07 22:25:12 -07:00
|
|
|
#else
|
|
|
|
#ifndef _DEBUG
|
2008-12-25 13:07:13 -07:00
|
|
|
sprintf_s(_PluginInfo->Name, 100, "Dolphin Direct3D9");
|
2008-12-07 22:25:12 -07:00
|
|
|
#else
|
2008-12-25 13:07:13 -07:00
|
|
|
sprintf_s(_PluginInfo->Name, 100, "Dolphin Direct3D9 (Debug)");
|
2008-12-07 22:25:12 -07:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-01-08 05:12:15 -07:00
|
|
|
void SetDllGlobals(PLUGIN_GLOBALS* _pPluginGlobals) {
|
2009-03-18 11:17:58 -06:00
|
|
|
globals = _pPluginGlobals;
|
|
|
|
LogManager::SetInstance((LogManager *)globals->logManager);
|
2009-01-08 05:12:15 -07:00
|
|
|
}
|
|
|
|
|
2009-01-14 23:48:15 -07:00
|
|
|
void DllAbout(HWND _hParent)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
|
|
|
DialogBox(g_hInstance,(LPCSTR)IDD_ABOUT,_hParent,(DLGPROC)AboutProc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DllConfig(HWND _hParent)
|
|
|
|
{
|
|
|
|
if (Init())
|
|
|
|
{
|
|
|
|
DlgSettings_Show(g_hInstance,_hParent);
|
|
|
|
DeInit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-14 23:48:15 -07:00
|
|
|
void Initialize(void *init)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
|
|
|
|
2009-01-14 23:48:15 -07:00
|
|
|
SVideoInitialize *_pVideoInitialize = (SVideoInitialize*)init;
|
2008-12-07 22:25:12 -07:00
|
|
|
frameCount = 0;
|
|
|
|
g_VideoInitialize = *_pVideoInitialize;
|
|
|
|
Init();
|
|
|
|
_pVideoInitialize->pPeekMessages = g_VideoInitialize.pPeekMessages;
|
|
|
|
_pVideoInitialize->pUpdateFPSDisplay = g_VideoInitialize.pUpdateFPSDisplay;
|
|
|
|
_pVideoInitialize->pWindowHandle = g_VideoInitialize.pWindowHandle;
|
|
|
|
|
|
|
|
Renderer::AddMessage("Dolphin Direct3D9 Video Plugin.",5000);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-01-14 23:48:15 -07:00
|
|
|
void DoState(unsigned char **ptr, int mode) {
|
2008-12-07 22:25:12 -07:00
|
|
|
// Clear all caches
|
2009-03-06 09:47:04 -07:00
|
|
|
TextureCache::Invalidate(false);
|
2008-12-07 22:25:12 -07:00
|
|
|
|
|
|
|
PointerWrap p(ptr, mode);
|
|
|
|
VideoCommon_DoState(p);
|
|
|
|
//PanicAlert("Saving/Loading state from DirectX9");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Video_EnterLoop()
|
|
|
|
{
|
|
|
|
Fifo_EnterLoop(g_VideoInitialize);
|
|
|
|
}
|
|
|
|
|
2009-02-20 15:04:52 -07:00
|
|
|
void Video_ExitLoop()
|
|
|
|
{
|
|
|
|
Fifo_ExitLoop();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-07 22:25:12 -07:00
|
|
|
void Video_Prepare(void)
|
|
|
|
{
|
|
|
|
Renderer::Init(g_VideoInitialize);
|
|
|
|
|
|
|
|
TextureCache::Init();
|
|
|
|
|
2009-06-22 03:31:30 -06:00
|
|
|
BPInit();
|
2008-12-07 22:25:12 -07:00
|
|
|
VertexManager::Init();
|
|
|
|
Fifo_Init();
|
2008-12-25 13:07:13 -07:00
|
|
|
VertexLoaderManager::Init();
|
2008-12-07 22:25:12 -07:00
|
|
|
OpcodeDecoder_Init();
|
2009-03-07 16:20:14 -07:00
|
|
|
VertexShaderCache::Init();
|
|
|
|
VertexShaderManager::Init();
|
|
|
|
PixelShaderCache::Init();
|
|
|
|
PixelShaderManager::Init();
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
|
|
|
|
2009-01-14 23:48:15 -07:00
|
|
|
void Shutdown(void)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
|
|
|
Fifo_Shutdown();
|
2008-12-25 13:07:13 -07:00
|
|
|
OpcodeDecoder_Shutdown();
|
2008-12-07 22:25:12 -07:00
|
|
|
VertexManager::Shutdown();
|
2009-03-07 16:20:14 -07:00
|
|
|
VertexShaderManager::Shutdown();
|
|
|
|
VertexLoaderManager::Shutdown();
|
|
|
|
VertexShaderCache::Shutdown();
|
|
|
|
PixelShaderCache::Shutdown();
|
|
|
|
PixelShaderManager::Shutdown();
|
2008-12-07 22:25:12 -07:00
|
|
|
TextureCache::Shutdown();
|
|
|
|
Renderer::Shutdown();
|
|
|
|
DeInit();
|
|
|
|
}
|
|
|
|
|
2009-07-10 20:34:16 -06:00
|
|
|
void VideoFifo_CheckSwapRequest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoFifo_CheckSwapRequestAt(u32 xfbAddr, u32 fbWidth, u32 fbHeight)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-07-11 10:52:34 -06:00
|
|
|
void VideoFifo_CheckEFBAccess()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-07-10 20:34:16 -06:00
|
|
|
void Video_BeginField(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
ConvertXFB(tempBuffer, _pXFB, _dwWidth, _dwHeight);
|
|
|
|
|
|
|
|
// blubb
|
|
|
|
static LPDIRECT3DTEXTURE9 pTexture = D3D::CreateTexture2D((BYTE*)tempBuffer, _dwWidth, _dwHeight, _dwWidth, D3DFMT_A8R8G8B8);
|
|
|
|
|
|
|
|
D3D::ReplaceTexture2D(pTexture, (BYTE*)tempBuffer, _dwWidth, _dwHeight, _dwWidth, D3DFMT_A8R8G8B8);
|
|
|
|
D3D::dev->SetTexture(0, pTexture);
|
|
|
|
|
|
|
|
D3D::quad2d(0,0,(float)Postprocess::GetWidth(),(float)Postprocess::GetHeight(), 0xFFFFFFFF);
|
|
|
|
|
|
|
|
D3D::EndFrame();
|
|
|
|
D3D::BeginFrame();*/
|
|
|
|
}
|
|
|
|
|
2009-02-20 15:04:52 -07:00
|
|
|
void Video_AddMessage(const char* pstr, u32 milliseconds)
|
|
|
|
{
|
|
|
|
Renderer::AddMessage(pstr,milliseconds);
|
|
|
|
}
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2009-02-26 20:56:34 -07:00
|
|
|
HRESULT ScreenShot(const char *File)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
|
|
|
if (D3D::dev == NULL)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
D3DDISPLAYMODE DisplayMode;
|
|
|
|
if (FAILED(D3D::dev->GetDisplayMode(0, &DisplayMode)))
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
LPDIRECT3DSURFACE9 surf;
|
|
|
|
if (FAILED(D3D::dev->CreateOffscreenPlainSurface(DisplayMode.Width, DisplayMode.Height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surf, NULL)))
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
if (FAILED(D3D::dev->GetFrontBufferData(0, surf)))
|
|
|
|
{
|
2009-01-14 23:48:15 -07:00
|
|
|
surf->Release();
|
2008-12-07 22:25:12 -07:00
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RECT rect;
|
|
|
|
::GetWindowRect(EmuWindow::GetWnd(), &rect);
|
2009-01-14 23:48:15 -07:00
|
|
|
if (FAILED(D3DXSaveSurfaceToFile(File, D3DXIFF_JPG, surf, NULL, &rect)))
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
|
|
|
surf->Release();
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
surf->Release();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-02-26 20:56:34 -07:00
|
|
|
void Video_Screenshot(const char *_szFilename)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2009-03-01 03:53:23 -07:00
|
|
|
if (ScreenShot(_szFilename) != S_OK)
|
2009-02-26 20:56:34 -07:00
|
|
|
PanicAlert("Error while capturing screen");
|
2009-02-27 04:45:07 -07:00
|
|
|
else {
|
|
|
|
std::string message = "Saved ";
|
|
|
|
message += _szFilename;
|
|
|
|
Renderer::AddMessage(message, 2000);
|
|
|
|
}
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
2009-07-02 11:45:09 -06:00
|
|
|
|
|
|
|
void Video_OnThreadAccessEFB()
|
|
|
|
{
|
|
|
|
s_criticalEFB.Enter();
|
|
|
|
s_AccessEFBResult = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
switch (s_AccessEFBType)
|
|
|
|
{
|
|
|
|
case PEEK_Z:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case POKE_Z:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PEEK_COLOR:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case POKE_COLOR:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
s_AccessEFBDone.Set();
|
|
|
|
|
|
|
|
s_criticalEFB.Leave();
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 Video_AccessEFB(EFBAccessType type, u32 x, u32 y)
|
|
|
|
{
|
|
|
|
u32 result;
|
|
|
|
|
|
|
|
s_criticalEFB.Enter();
|
|
|
|
|
|
|
|
s_AccessEFBType = type;
|
|
|
|
s_EFBx = x;
|
|
|
|
s_EFBy = y;
|
|
|
|
|
|
|
|
if (g_VideoInitialize.bUseDualCore)
|
|
|
|
{
|
|
|
|
g_EFBAccessRequested = true;
|
|
|
|
s_AccessEFBDone.Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
s_criticalEFB.Leave();
|
|
|
|
|
|
|
|
if (g_VideoInitialize.bUseDualCore)
|
|
|
|
s_AccessEFBDone.Wait();
|
|
|
|
else
|
|
|
|
Video_OnThreadAccessEFB();
|
|
|
|
|
|
|
|
s_criticalEFB.Enter();
|
|
|
|
if (g_VideoInitialize.bUseDualCore)
|
|
|
|
s_AccessEFBDone.Shutdown();
|
|
|
|
|
|
|
|
result = s_AccessEFBResult;
|
|
|
|
s_criticalEFB.Leave();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|