2009-07-28 21:32:10 +00:00
// Copyright (C) 2003 Dolphin Project.
2008-12-08 05:25:12 +00:00
// 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 "Common.h"
2009-09-04 17:29:16 +00:00
# include "Atomic.h"
2009-07-12 21:58:32 +00:00
# include "Thread.h"
# include "LogManager.h"
2008-12-08 05:25:12 +00:00
2010-06-13 19:41:07 +00:00
# if defined(HAVE_WX) && HAVE_WX
2010-11-15 09:54:07 +00:00
# include "VideoConfigDiag.h"
2010-06-13 19:41:07 +00:00
# endif // HAVE_WX
2009-09-02 06:33:41 +00:00
# if defined(HAVE_WX) && HAVE_WX
2010-12-05 14:15:36 +00:00
# include "DebuggerPanel.h"
2009-09-02 06:33:41 +00:00
# endif // HAVE_WX
2010-11-18 02:21:26 +00:00
# include "MainBase.h"
2008-12-08 05:25:12 +00:00
# include "main.h"
2009-09-13 09:23:30 +00:00
# include "VideoConfig.h"
2008-12-08 05:25:12 +00:00
# include "Fifo.h"
# include "OpcodeDecoding.h"
# include "TextureCache.h"
2009-06-22 09:31:30 +00:00
# include "BPStructs.h"
2008-12-08 05:25:12 +00:00
# include "VertexManager.h"
2010-11-18 02:21:26 +00:00
# include "FramebufferManager.h"
2008-12-25 20:07:13 +00:00
# include "VertexLoaderManager.h"
2009-03-07 23:20:14 +00:00
# include "VertexShaderManager.h"
# include "PixelShaderManager.h"
# include "VertexShaderCache.h"
# include "PixelShaderCache.h"
2009-10-10 21:19:39 +00:00
# include "CommandProcessor.h"
# include "PixelEngine.h"
2009-09-03 20:37:35 +00:00
# include "OnScreenDisplay.h"
2008-12-08 05:25:12 +00:00
# include "D3DTexture.h"
# include "D3DUtil.h"
# include "EmuWindow.h"
# include "VideoState.h"
# include "XFBConvert.h"
2009-09-20 03:29:43 +00:00
# include "render.h"
2010-08-29 23:08:56 +00:00
# include "DLCache.h"
2009-09-20 03:29:43 +00:00
2008-12-08 05:25:12 +00:00
HINSTANCE g_hInstance = NULL ;
2009-07-02 17:45:09 +00:00
2009-09-02 06:33:41 +00:00
// This is used for the functions right below here which use wxwidgets
# if defined(HAVE_WX) && HAVE_WX
2010-06-18 18:40:58 +00:00
WXDLLIMPEXP_BASE void wxSetInstance ( HINSTANCE hInst ) ;
2009-09-02 06:33:41 +00:00
# endif
2010-07-22 02:05:28 +00:00
void * DllDebugger ( void * _hParent , bool Show )
2008-12-08 05:25:12 +00:00
{
2010-02-24 19:32:32 +00:00
# if defined(HAVE_WX) && HAVE_WX
2010-12-05 14:15:36 +00:00
return new GFXDebuggerPanel ( ( wxWindow * ) _hParent ) ;
2010-07-22 02:05:28 +00:00
# else
return NULL ;
2009-09-02 06:33:41 +00:00
# endif
2010-02-24 19:32:32 +00:00
}
2009-09-02 06:33:41 +00:00
# if defined(HAVE_WX) && HAVE_WX
class wxDLLApp : public wxApp
{
bool OnInit ( )
{
return true ;
}
} ;
2010-09-28 02:15:02 +00:00
IMPLEMENT_APP_NO_MAIN ( wxDLLApp )
2009-09-02 06:33:41 +00:00
WXDLLIMPEXP_BASE void wxSetInstance ( HINSTANCE hInst ) ;
# endif
2009-09-12 15:00:08 +00:00
BOOL APIENTRY DllMain ( HINSTANCE hinstDLL , DWORD dwReason , LPVOID lpvReserved )
2008-12-08 05:25:12 +00:00
{
switch ( dwReason )
{
case DLL_PROCESS_ATTACH :
2009-09-02 06:33:41 +00:00
{
2010-02-24 19:32:32 +00:00
# if defined(HAVE_WX) && HAVE_WX
2009-09-02 06:33:41 +00:00
wxSetInstance ( ( HINSTANCE ) hinstDLL ) ;
2010-02-24 19:32:32 +00:00
wxInitialize ( ) ;
# endif
2009-09-02 06:33:41 +00:00
}
2008-12-08 05:25:12 +00:00
break ;
case DLL_PROCESS_DETACH :
2010-02-24 19:32:32 +00:00
# if defined(HAVE_WX) && HAVE_WX
wxUninitialize ( ) ;
# endif
2008-12-08 05:25:12 +00:00
break ;
}
g_hInstance = hinstDLL ;
return TRUE ;
}
2008-12-11 15:12:17 +00:00
unsigned int Callback_PeekMessages ( )
2008-12-08 05:25:12 +00:00
{
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 )
{
2010-05-23 02:29:23 +00:00
TCHAR temp [ 512 ] ;
2010-07-08 15:25:01 +00:00
swprintf_s ( temp , 512 , _T ( " SVN R%s: DX9: %hs " ) , svn_rev_str , text ) ;
2010-07-08 15:56:09 +00:00
SetWindowText ( EmuWindow : : GetWnd ( ) , temp ) ;
2008-12-08 05:25:12 +00:00
}
2010-09-28 02:15:02 +00:00
void GetDllInfo ( PLUGIN_INFO * _PluginInfo )
2008-12-08 05:25:12 +00:00
{
_PluginInfo - > Version = 0x0100 ;
_PluginInfo - > Type = PLUGIN_TYPE_VIDEO ;
2009-01-15 06:48:15 +00:00
# ifdef DEBUGFAST
2008-12-25 20:07:13 +00:00
sprintf_s ( _PluginInfo - > Name , 100 , " Dolphin Direct3D9 (DebugFast) " ) ;
2010-09-28 02:15:02 +00:00
# elif defined _DEBUG
sprintf_s ( _PluginInfo - > Name , 100 , " Dolphin Direct3D9 (Debug) " ) ;
2008-12-08 05:25:12 +00:00
# else
2008-12-25 20:07:13 +00:00
sprintf_s ( _PluginInfo - > Name , 100 , " Dolphin Direct3D9 " ) ;
2008-12-08 05:25:12 +00:00
# endif
}
2010-05-23 02:29:23 +00:00
void SetDllGlobals ( PLUGIN_GLOBALS * _pPluginGlobals )
{
2009-03-18 17:17:58 +00:00
globals = _pPluginGlobals ;
2010-05-23 02:29:23 +00:00
LogManager : : SetInstance ( ( LogManager * ) globals - > logManager ) ;
2009-01-08 12:12:15 +00:00
}
2009-01-15 06:48:15 +00:00
void DllAbout ( HWND _hParent )
2008-12-08 05:25:12 +00:00
{
2010-06-13 20:08:20 +00:00
//DialogBox(g_hInstance,(LPCTSTR)IDD_ABOUT,_hParent,(DLGPROC)AboutProc);
2008-12-08 05:25:12 +00:00
}
2010-11-22 22:17:35 +00:00
void InitBackendInfo ( )
2008-12-08 05:25:12 +00:00
{
2010-11-21 14:47:28 +00:00
g_Config . backend_info . APIType = API_D3D9 ;
2010-11-22 22:17:35 +00:00
g_Config . backend_info . bUseRGBATextures = true ;
2010-11-21 14:47:28 +00:00
g_Config . backend_info . bSupportsEFBToRAM = true ;
g_Config . backend_info . bSupportsRealXFB = true ;
2010-11-24 17:13:12 +00:00
g_Config . backend_info . bSupports3DVision = true ;
2010-11-21 14:47:28 +00:00
g_Config . backend_info . bAllowSignedBytes = false ;
2010-12-05 14:15:36 +00:00
g_Config . backend_info . bSupportsDualSourceBlend = false ;
2010-12-27 21:56:20 +00:00
g_Config . backend_info . bSupportsFormatReinterpretation = true ;
2010-11-22 22:17:35 +00:00
}
void DllConfig ( void * _hParent )
{
# if defined(HAVE_WX) && HAVE_WX
InitBackendInfo ( ) ;
2010-12-29 13:07:00 +00:00
D3D : : Init ( ) ;
2010-06-13 19:41:07 +00:00
2010-11-15 09:54:07 +00:00
// adapters
2010-11-22 22:17:35 +00:00
g_Config . backend_info . Adapters . clear ( ) ;
2010-11-15 09:54:07 +00:00
for ( int i = 0 ; i < D3D : : GetNumAdapters ( ) ; + + i )
2010-11-21 14:47:28 +00:00
g_Config . backend_info . Adapters . push_back ( D3D : : GetAdapter ( i ) . ident . Description ) ;
2010-11-15 09:54:07 +00:00
// aamodes
2010-11-22 22:17:35 +00:00
g_Config . backend_info . AAModes . clear ( ) ;
2010-11-15 09:54:07 +00:00
if ( g_Config . iAdapter < D3D : : GetNumAdapters ( ) )
{
const D3D : : Adapter & adapter = D3D : : GetAdapter ( g_Config . iAdapter ) ;
2010-11-29 16:16:48 +00:00
for ( int i = 0 ; i < ( int ) adapter . aa_levels . size ( ) ; + + i )
2010-11-21 14:47:28 +00:00
g_Config . backend_info . AAModes . push_back ( adapter . aa_levels [ i ] . name ) ;
2010-11-15 09:54:07 +00:00
}
2010-11-22 22:17:35 +00:00
VideoConfigDiag * const diag = new VideoConfigDiag ( ( wxWindow * ) _hParent , " Direct3D9 " , " gfx_dx9 " ) ;
2010-11-15 09:54:07 +00:00
diag - > ShowModal ( ) ;
diag - > Destroy ( ) ;
2010-12-29 13:07:00 +00:00
D3D : : Shutdown ( ) ;
2010-11-22 22:17:35 +00:00
# endif
2008-12-08 05:25:12 +00:00
}
2009-01-15 06:48:15 +00:00
void Initialize ( void * init )
2008-12-08 05:25:12 +00:00
{
2010-11-22 22:17:35 +00:00
InitBackendInfo ( ) ;
2008-12-08 05:25:12 +00:00
frameCount = 0 ;
2010-01-20 07:47:41 +00:00
SVideoInitialize * _pVideoInitialize = ( SVideoInitialize * ) init ;
2010-09-28 02:15:02 +00:00
// Create a shortcut to _pVideoInitialize that can also update it
g_VideoInitialize = * ( _pVideoInitialize ) ;
2010-01-20 07:47:41 +00:00
InitXFBConvTables ( ) ;
2009-09-13 17:46:33 +00:00
2010-02-02 21:56:29 +00:00
g_Config . Load ( ( std : : string ( File : : GetUserPath ( D_CONFIG_IDX ) ) + " gfx_dx9.ini " ) . c_str ( ) ) ;
2009-09-13 17:46:33 +00:00
g_Config . GameIniLoad ( globals - > game_ini ) ;
UpdateProjectionHack ( g_Config . iPhackvalue ) ; // DX9 projection hack could be disabled by commenting out this line
2010-01-20 07:47:41 +00:00
UpdateActiveConfig ( ) ;
2010-09-28 02:15:02 +00:00
2010-01-20 07:47:41 +00:00
g_VideoInitialize . pWindowHandle = ( void * ) EmuWindow : : Create ( ( HWND ) g_VideoInitialize . pWindowHandle , g_hInstance , _T ( " Loading - Please wait. " ) ) ;
2009-09-13 17:46:33 +00:00
if ( g_VideoInitialize . pWindowHandle = = NULL )
{
ERROR_LOG ( VIDEO , " An error has occurred while trying to create the window. " ) ;
return ;
}
2010-01-20 07:47:41 +00:00
else if ( FAILED ( D3D : : Init ( ) ) )
2009-09-13 17:46:33 +00:00
{
2010-05-23 02:29:23 +00:00
MessageBox ( GetActiveWindow ( ) , _T ( " Unable to initialize Direct3D. Please make sure that you have the latest version of DirectX 9.0c correctly installed. " ) , _T ( " Fatal Error " ) , MB_ICONERROR | MB_OK ) ;
2009-09-13 17:46:33 +00:00
return ;
}
2010-01-20 07:47:41 +00:00
g_VideoInitialize . pPeekMessages = & Callback_PeekMessages ;
g_VideoInitialize . pUpdateFPSDisplay = & UpdateFPSDisplay ;
2010-05-23 02:29:23 +00:00
_pVideoInitialize - > pPeekMessages = g_VideoInitialize . pPeekMessages ;
_pVideoInitialize - > pUpdateFPSDisplay = g_VideoInitialize . pUpdateFPSDisplay ;
2010-09-28 02:15:02 +00:00
// Now the window handle is written
2010-05-23 02:29:23 +00:00
_pVideoInitialize - > pWindowHandle = g_VideoInitialize . pWindowHandle ;
2010-01-20 07:47:41 +00:00
OSD : : AddMessage ( " Dolphin Direct3D9 Video Plugin. " , 5000 ) ;
2010-03-14 18:57:50 +00:00
s_PluginInitialized = true ;
2009-08-08 01:39:56 +00:00
}
2009-02-20 22:04:52 +00:00
2009-09-13 17:46:33 +00:00
void Video_Prepare ( )
2008-12-08 05:25:12 +00:00
{
2010-01-01 03:55:39 +00:00
// Better be safe...
s_efbAccessRequested = FALSE ;
s_FifoShuttingDown = FALSE ;
2010-03-14 18:57:50 +00:00
s_swapRequested = FALSE ;
2010-09-28 02:15:02 +00:00
// internal interfaces
2010-11-18 02:21:26 +00:00
g_renderer = new DX9 : : Renderer ;
2010-10-19 22:24:27 +00:00
g_texture_cache = new DX9 : : TextureCache ;
2010-10-03 00:41:06 +00:00
g_vertex_manager = new DX9 : : VertexManager ;
2010-09-28 02:15:02 +00:00
// VideoCommon
BPInit ( ) ;
2008-12-08 05:25:12 +00:00
Fifo_Init ( ) ;
2008-12-25 20:07:13 +00:00
VertexLoaderManager : : Init ( ) ;
2008-12-08 05:25:12 +00:00
OpcodeDecoder_Init ( ) ;
2009-03-07 23:20:14 +00:00
VertexShaderManager : : Init ( ) ;
PixelShaderManager : : Init ( ) ;
2010-05-23 02:29:23 +00:00
CommandProcessor : : Init ( ) ;
PixelEngine : : Init ( ) ;
2010-08-29 23:08:56 +00:00
DLCache : : Init ( ) ;
2010-09-28 02:15:02 +00:00
// Notify the core that the video plugin is ready
2010-04-15 20:58:34 +00:00
g_VideoInitialize . pCoreMessage ( WM_USER_CREATE ) ;
2008-12-08 05:25:12 +00:00
}
2009-09-13 17:46:33 +00:00
void Shutdown ( )
2008-12-08 05:25:12 +00:00
{
2010-09-28 02:15:02 +00:00
s_PluginInitialized = false ;
2009-09-13 17:46:33 +00:00
s_efbAccessRequested = FALSE ;
2010-01-01 03:55:39 +00:00
s_FifoShuttingDown = FALSE ;
2010-03-14 18:57:50 +00:00
s_swapRequested = FALSE ;
2010-09-28 02:15:02 +00:00
// VideoCommon
2010-08-29 23:08:56 +00:00
DLCache : : Shutdown ( ) ;
2008-12-08 05:25:12 +00:00
Fifo_Shutdown ( ) ;
2010-06-12 15:49:21 +00:00
CommandProcessor : : Shutdown ( ) ;
2009-03-07 23:20:14 +00:00
PixelShaderManager : : Shutdown ( ) ;
2010-09-28 02:15:02 +00:00
VertexShaderManager : : Shutdown ( ) ;
2009-09-13 17:46:33 +00:00
OpcodeDecoder_Shutdown ( ) ;
2010-09-28 02:15:02 +00:00
VertexLoaderManager : : Shutdown ( ) ;
// internal interfaces
PixelShaderCache : : Shutdown ( ) ;
VertexShaderCache : : Shutdown ( ) ;
2010-10-03 00:41:06 +00:00
delete g_vertex_manager ;
2010-10-19 22:24:27 +00:00
delete g_texture_cache ;
2010-11-18 02:21:26 +00:00
delete g_renderer ;
2009-09-13 17:46:33 +00:00
D3D : : Shutdown ( ) ;
EmuWindow : : Close ( ) ;
2008-12-08 05:25:12 +00:00
}