2009-07-29 00:32:10 +03:00
// Copyright (C) 2003 Dolphin Project.
2008-12-08 07:25:12 +02: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 20:29:16 +03:00
# include "Atomic.h"
2009-07-13 00:58:32 +03:00
# include "Thread.h"
# include "LogManager.h"
2008-12-08 07:25:12 +02:00
2010-06-13 22:41:07 +03:00
# if defined(HAVE_WX) && HAVE_WX
2010-11-15 11:54:07 +02:00
# include "VideoConfigDiag.h"
2010-06-13 22:41:07 +03:00
# endif // HAVE_WX
2009-09-02 09:33:41 +03:00
# if defined(HAVE_WX) && HAVE_WX
2011-02-13 08:06:32 +02:00
# include "Debugger/DebuggerPanel.h"
2009-09-02 09:33:41 +03:00
# endif // HAVE_WX
2010-11-18 04:21:26 +02:00
# include "MainBase.h"
2008-12-08 07:25:12 +02:00
# include "main.h"
2009-09-13 12:23:30 +03:00
# include "VideoConfig.h"
2008-12-08 07:25:12 +02:00
# include "Fifo.h"
# include "OpcodeDecoding.h"
# include "TextureCache.h"
2009-06-22 12:31:30 +03:00
# include "BPStructs.h"
2008-12-08 07:25:12 +02:00
# include "VertexManager.h"
2010-11-18 04:21:26 +02:00
# include "FramebufferManager.h"
2008-12-25 22:07:13 +02:00
# include "VertexLoaderManager.h"
2009-03-08 01:20:14 +02:00
# include "VertexShaderManager.h"
# include "PixelShaderManager.h"
# include "VertexShaderCache.h"
# include "PixelShaderCache.h"
2009-10-11 00:19:39 +03:00
# include "CommandProcessor.h"
# include "PixelEngine.h"
2009-09-03 23:37:35 +03:00
# include "OnScreenDisplay.h"
2008-12-08 07:25:12 +02:00
# include "D3DTexture.h"
# include "D3DUtil.h"
# include "EmuWindow.h"
# include "VideoState.h"
2009-09-20 06:29:43 +03:00
# include "render.h"
2010-08-30 02:08:56 +03:00
# include "DLCache.h"
2011-01-14 17:09:30 +02:00
# include "IniFile.h"
2011-01-31 03:28:32 +02:00
# include "Core.h"
2011-03-16 01:09:12 +02:00
# include "Host.h"
2009-09-20 06:29:43 +03:00
2011-01-31 03:28:32 +02:00
# include "ConfigManager.h"
# include "VideoBackend.h"
2009-07-02 20:45:09 +03:00
2011-01-31 03:28:32 +02:00
namespace DX9
2011-01-14 17:09:30 +02:00
{
2011-01-31 03:28:32 +02:00
unsigned int VideoBackend : : PeekMessages ( )
2008-12-08 07:25:12 +02:00
{
MSG msg ;
while ( PeekMessage ( & msg , 0 , 0 , 0 , PM_REMOVE ) )
{
if ( msg . message = = WM_QUIT )
return FALSE ;
TranslateMessage ( & msg ) ;
DispatchMessage ( & msg ) ;
}
return TRUE ;
}
2011-01-31 03:28:32 +02:00
void VideoBackend : : UpdateFPSDisplay ( const char * text )
2008-12-08 07:25:12 +02:00
{
2011-01-23 03:07:53 +02:00
TCHAR temp [ 512 ] ;
2011-01-24 06:42:34 +02:00
swprintf_s ( temp , sizeof ( temp ) / sizeof ( TCHAR ) , _T ( " %hs | DX9 | %hs " ) , svn_rev_str , text ) ;
2010-07-08 18:56:09 +03:00
SetWindowText ( EmuWindow : : GetWnd ( ) , temp ) ;
2008-12-08 07:25:12 +02:00
}
2011-01-31 03:28:32 +02:00
std : : string VideoBackend : : GetName ( )
2010-05-23 05:29:23 +03:00
{
2011-01-31 03:28:32 +02:00
return " Direct3D9 " ;
2008-12-08 07:25:12 +02:00
}
2010-11-23 00:17:35 +02:00
void InitBackendInfo ( )
2008-12-08 07:25:12 +02:00
{
2010-11-21 16:47:28 +02:00
g_Config . backend_info . APIType = API_D3D9 ;
2011-03-21 07:46:33 +02:00
g_Config . backend_info . bUseRGBATextures = false ;
2010-11-24 19:13:12 +02:00
g_Config . backend_info . bSupports3DVision = true ;
2010-12-05 16:15:36 +02:00
g_Config . backend_info . bSupportsDualSourceBlend = false ;
2010-12-27 23:56:20 +02:00
g_Config . backend_info . bSupportsFormatReinterpretation = true ;
2011-03-21 07:46:33 +02:00
const int shaderModel = ( ( DX9 : : D3D : : GetCaps ( ) . PixelShaderVersion > > 8 ) & 0xFF ) ;
const int maxConstants = ( shaderModel < 3 ) ? 32 : ( ( shaderModel < 4 ) ? 224 : 65536 ) ;
2011-01-09 16:13:24 +02:00
g_Config . backend_info . bSupportsPixelLighting = C_PLIGHTS + 40 < = maxConstants & & C_PMATERIALS + 4 < = maxConstants ;
2010-11-23 00:17:35 +02:00
}
2011-01-31 03:28:32 +02:00
void VideoBackend : : ShowConfig ( void * parent )
2010-11-23 00:17:35 +02:00
{
# if defined(HAVE_WX) && HAVE_WX
2011-01-29 22:16:51 +02:00
DX9 : : D3D : : Init ( ) ;
2011-02-14 01:44:55 +02:00
InitBackendInfo ( ) ;
2010-06-13 22:41:07 +03:00
2010-11-15 11:54:07 +02:00
// adapters
2010-11-23 00:17:35 +02:00
g_Config . backend_info . Adapters . clear ( ) ;
2011-01-29 22:16:51 +02:00
for ( int i = 0 ; i < DX9 : : D3D : : GetNumAdapters ( ) ; + + i )
g_Config . backend_info . Adapters . push_back ( DX9 : : D3D : : GetAdapter ( i ) . ident . Description ) ;
2010-11-15 11:54:07 +02:00
// aamodes
2010-11-23 00:17:35 +02:00
g_Config . backend_info . AAModes . clear ( ) ;
2011-01-29 22:16:51 +02:00
if ( g_Config . iAdapter < DX9 : : D3D : : GetNumAdapters ( ) )
2010-11-15 11:54:07 +02:00
{
2011-01-29 22:16:51 +02:00
const DX9 : : D3D : : Adapter & adapter = DX9 : : D3D : : GetAdapter ( g_Config . iAdapter ) ;
2010-11-15 11:54:07 +02:00
2010-11-29 18:16:48 +02:00
for ( int i = 0 ; i < ( int ) adapter . aa_levels . size ( ) ; + + i )
2010-11-21 16:47:28 +02:00
g_Config . backend_info . AAModes . push_back ( adapter . aa_levels [ i ] . name ) ;
2010-11-15 11:54:07 +02:00
}
2011-02-05 04:13:33 +02:00
// Clear ppshaders string vector
g_Config . backend_info . PPShaders . clear ( ) ;
2011-03-21 21:57:31 +02:00
VideoConfigDiag diag ( ( wxWindow * ) parent , _trans ( " Direct3D9 " ) , " gfx_dx9 " ) ;
2011-03-17 00:22:21 +02:00
diag . ShowModal ( ) ;
2010-11-15 11:54:07 +02:00
2011-02-02 19:09:39 +02:00
g_Config . backend_info . Adapters . clear ( ) ;
2011-01-29 22:16:51 +02:00
DX9 : : D3D : : Shutdown ( ) ;
2010-11-23 00:17:35 +02:00
# endif
2008-12-08 07:25:12 +02:00
}
2011-02-25 23:14:13 +02:00
bool VideoBackend : : Initialize ( void * & window_handle )
2008-12-08 07:25:12 +02:00
{
2010-11-23 00:17:35 +02:00
InitBackendInfo ( ) ;
2008-12-08 07:25:12 +02:00
frameCount = 0 ;
2009-09-13 20:46:33 +03:00
2011-04-25 23:06:45 +03:00
g_Config . Load ( ( File : : GetUserPath ( D_CONFIG_IDX ) + " gfx_dx9.ini " ) . c_str ( ) ) ;
g_Config . GameIniLoad ( SConfig : : GetInstance ( ) . m_LocalCoreStartupParameter . m_strGameIni . c_str ( ) ) ;
2011-03-21 21:57:31 +02:00
UpdateProjectionHack ( g_Config . iPhackvalue , g_Config . sPhackvalue ) ;
2010-01-20 09:47:41 +02:00
UpdateActiveConfig ( ) ;
2010-09-28 05:15:02 +03:00
2011-02-25 23:14:13 +02:00
window_handle = ( void * ) EmuWindow : : Create ( ( HWND ) window_handle , GetModuleHandle ( 0 ) , _T ( " Loading - Please wait. " ) ) ;
if ( window_handle = = NULL )
2009-09-13 20:46:33 +03:00
{
ERROR_LOG ( VIDEO , " An error has occurred while trying to create the window. " ) ;
2011-02-25 23:14:13 +02:00
return false ;
2009-09-13 20:46:33 +03:00
}
2011-01-29 22:16:51 +02:00
else if ( FAILED ( DX9 : : D3D : : Init ( ) ) )
2009-09-13 20:46:33 +03:00
{
2010-05-23 05:29:23 +03: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 ) ;
2011-02-25 23:14:13 +02:00
return false ;
2009-09-13 20:46:33 +03:00
}
2010-01-20 09:47:41 +02:00
2011-02-14 04:18:03 +02:00
s_BackendInitialized = true ;
2011-02-25 23:14:13 +02:00
2011-03-02 17:13:13 +02:00
return true ;
}
void VideoBackend : : Video_Prepare ( )
{
2010-01-01 05:55:39 +02:00
// Better be safe...
s_efbAccessRequested = FALSE ;
s_FifoShuttingDown = FALSE ;
2010-03-14 20:57:50 +02:00
s_swapRequested = FALSE ;
2010-09-28 05:15:02 +03:00
// internal interfaces
2011-01-31 03:28:32 +02:00
g_renderer = new Renderer ;
g_texture_cache = new TextureCache ;
g_vertex_manager = new VertexManager ;
2010-09-28 05:15:02 +03:00
// VideoCommon
BPInit ( ) ;
2008-12-08 07:25:12 +02:00
Fifo_Init ( ) ;
2008-12-25 22:07:13 +02:00
VertexLoaderManager : : Init ( ) ;
2008-12-08 07:25:12 +02:00
OpcodeDecoder_Init ( ) ;
2009-03-08 01:20:14 +02:00
VertexShaderManager : : Init ( ) ;
PixelShaderManager : : Init ( ) ;
2010-05-23 05:29:23 +03:00
CommandProcessor : : Init ( ) ;
PixelEngine : : Init ( ) ;
2010-08-30 02:08:56 +03:00
DLCache : : Init ( ) ;
2010-09-28 05:15:02 +03:00
2011-02-14 04:18:03 +02:00
// Notify the core that the video backend is ready
2011-03-16 01:09:12 +02:00
Host_Message ( WM_USER_CREATE ) ;
2008-12-08 07:25:12 +02:00
}
2011-01-31 03:28:32 +02:00
void VideoBackend : : Shutdown ( )
2008-12-08 07:25:12 +02:00
{
2011-02-14 04:18:03 +02:00
s_BackendInitialized = false ;
2010-09-28 05:15:02 +03:00
2011-03-02 17:13:13 +02:00
if ( g_renderer )
{
s_efbAccessRequested = FALSE ;
s_FifoShuttingDown = FALSE ;
s_swapRequested = FALSE ;
// VideoCommon
DLCache : : Shutdown ( ) ;
Fifo_Shutdown ( ) ;
CommandProcessor : : Shutdown ( ) ;
PixelShaderManager : : Shutdown ( ) ;
VertexShaderManager : : Shutdown ( ) ;
OpcodeDecoder_Shutdown ( ) ;
VertexLoaderManager : : Shutdown ( ) ;
// internal interfaces
PixelShaderCache : : Shutdown ( ) ;
VertexShaderCache : : Shutdown ( ) ;
delete g_vertex_manager ;
delete g_texture_cache ;
delete g_renderer ;
g_renderer = NULL ;
}
2011-01-31 03:28:32 +02:00
D3D : : Shutdown ( ) ;
2008-12-08 07:25:12 +02:00
}
2011-01-31 03:28:32 +02:00
}