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 "D3DBase.h"
2009-09-13 17:46:33 +00:00
# include "VideoConfig.h"
2008-12-08 05:25:12 +00:00
# include "Render.h"
2009-09-06 17:47:48 +00:00
# include "XFStructs.h"
2010-07-17 11:42:28 +00:00
# include "StringUtil.h"
2011-01-02 23:13:29 +00:00
# include "VideoCommon.h"
2010-07-17 11:42:28 +00:00
D3DXSAVESURFACETOFILEATYPE PD3DXSaveSurfaceToFileA = NULL ;
D3DXSAVETEXTURETOFILEATYPE PD3DXSaveTextureToFileA = NULL ;
D3DXCOMPILESHADERTYPE PD3DXCompileShader = NULL ;
2011-01-29 20:16:51 +00:00
namespace DX9
{
// D3DX
HINSTANCE hD3DXDll = NULL ;
2010-12-29 13:07:00 +00:00
int d3dx_dll_ref = 0 ;
2008-12-08 05:25:12 +00:00
2010-11-21 15:44:50 +00:00
typedef IDirect3D9 * ( WINAPI * DIRECT3DCREATE9 ) ( UINT ) ;
DIRECT3DCREATE9 PDirect3DCreate9 = NULL ;
HINSTANCE hD3DDll = NULL ;
2010-12-29 13:07:00 +00:00
int d3d_dll_ref = 0 ;
2010-11-21 15:44:50 +00:00
2008-12-08 05:25:12 +00:00
namespace D3D
{
2009-09-13 08:21:35 +00:00
LPDIRECT3D9 D3D = NULL ; // Used to create the D3DDevice
LPDIRECT3DDEVICE9 dev = NULL ; // Our rendering device
2009-09-13 17:46:33 +00:00
LPDIRECT3DSURFACE9 back_buffer ;
LPDIRECT3DSURFACE9 back_buffer_z ;
2009-09-13 08:21:35 +00:00
D3DCAPS9 caps ;
HWND hWnd ;
2008-12-08 05:25:12 +00:00
2009-09-13 08:21:35 +00:00
static int multisample ;
static int resolution ;
static int xres , yres ;
2009-09-15 19:53:22 +00:00
static bool auto_depth_stencil = false ;
2008-12-08 05:25:12 +00:00
2009-09-13 08:21:35 +00:00
# define VENDOR_NVIDIA 4318
# define VENDOR_ATI 4098
2008-12-08 05:25:12 +00:00
2009-09-18 02:03:56 +00:00
bool bFrameInProgress = false ;
2008-12-08 05:25:12 +00:00
2009-09-13 08:21:35 +00:00
# define MAX_ADAPTERS 4
static Adapter adapters [ MAX_ADAPTERS ] ;
static int numAdapters ;
static int cur_adapter ;
2008-12-08 05:25:12 +00:00
2009-09-13 08:21:35 +00:00
// Value caches for state filtering
const int MaxTextureStages = 9 ;
2009-09-16 20:12:14 +00:00
const int MaxRenderStates = 210 + 46 ;
const int MaxTextureTypes = 33 ;
const int MaxSamplerSize = 13 ;
const int MaxSamplerTypes = 15 ;
static bool m_RenderStatesSet [ MaxRenderStates ] ;
static DWORD m_RenderStates [ MaxRenderStates ] ;
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
static bool m_RenderStatesChanged [ MaxRenderStates ] ;
2009-09-13 08:21:35 +00:00
static DWORD m_TextureStageStates [ MaxTextureStages ] [ MaxTextureTypes ] ;
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
static bool m_TextureStageStatesSet [ MaxTextureStages ] [ MaxTextureTypes ] ;
static bool m_TextureStageStatesChanged [ MaxTextureStages ] [ MaxTextureTypes ] ;
2009-09-13 08:21:35 +00:00
static DWORD m_SamplerStates [ MaxSamplerSize ] [ MaxSamplerTypes ] ;
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
static bool m_SamplerStatesSet [ MaxSamplerSize ] [ MaxSamplerTypes ] ;
static bool m_SamplerStatesChanged [ MaxSamplerSize ] [ MaxSamplerTypes ] ;
2009-09-13 08:21:35 +00:00
LPDIRECT3DBASETEXTURE9 m_Textures [ 16 ] ;
2009-09-19 10:46:25 +00:00
LPDIRECT3DVERTEXDECLARATION9 m_VtxDecl ;
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
LPDIRECT3DPIXELSHADER9 m_PixelShader ;
LPDIRECT3DVERTEXSHADER9 m_VertexShader ;
2008-12-08 05:25:12 +00:00
2011-01-04 12:56:52 +00:00
// Z buffer formats to be used for EFB depth surface
D3DFORMAT DepthFormats [ ] = {
FOURCC_INTZ ,
FOURCC_DF24 ,
FOURCC_RAWZ ,
FOURCC_DF16 ,
D3DFMT_D24X8 ,
D3DFMT_D24X4S4 ,
D3DFMT_D24S8 ,
D3DFMT_D24FS8 ,
D3DFMT_D32 , // too much precision, but who cares
D3DFMT_D16 , // much lower precision, but better than nothing
D3DFMT_D15S1 ,
} ;
2009-09-13 08:21:35 +00:00
void Enumerate ( ) ;
2008-12-08 05:25:12 +00:00
2009-09-13 08:21:35 +00:00
int GetNumAdapters ( ) { return numAdapters ; }
const Adapter & GetAdapter ( int i ) { return adapters [ i ] ; }
const Adapter & GetCurAdapter ( ) { return adapters [ cur_adapter ] ; }
2008-12-08 05:25:12 +00:00
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
bool IsATIDevice ( )
{
return GetCurAdapter ( ) . ident . VendorId = = VENDOR_ATI ;
}
2009-09-13 08:21:35 +00:00
HRESULT Init ( )
{
2010-12-29 13:07:00 +00:00
if ( d3d_dll_ref + + > 0 ) return S_OK ;
2010-11-21 15:44:50 +00:00
hD3DDll = LoadLibraryA ( " d3d9.dll " ) ;
if ( ! hD3DDll )
{
MessageBoxA ( NULL , " Failed to load d3d9.dll " , " Critical error " , MB_OK | MB_ICONERROR ) ;
return E_FAIL ;
}
PDirect3DCreate9 = ( DIRECT3DCREATE9 ) GetProcAddress ( hD3DDll , " Direct3DCreate9 " ) ;
if ( PDirect3DCreate9 = = NULL ) MessageBoxA ( NULL , " GetProcAddress failed for Direct3DCreate9! " , " Critical error " , MB_OK | MB_ICONERROR ) ;
2009-09-13 08:21:35 +00:00
// Create the D3D object, which is needed to create the D3DDevice.
2010-11-21 15:44:50 +00:00
D3D = PDirect3DCreate9 ( D3D_SDK_VERSION ) ;
2009-09-13 08:21:35 +00:00
if ( ! D3D )
2010-12-29 13:07:00 +00:00
{
- - d3d_dll_ref ;
2009-09-13 08:21:35 +00:00
return E_FAIL ;
2010-12-29 13:07:00 +00:00
}
2011-02-13 23:44:55 +00:00
// Init the caps structure using data from the currently selected device
int adapter = g_Config . iAdapter ;
D3D - > GetDeviceCaps ( ( adapter > = 0 & & adapter < std : : min ( MAX_ADAPTERS , numAdapters ) ) ? adapter : D3DADAPTER_DEFAULT , D3DDEVTYPE_HAL , & caps ) ;
2009-09-13 08:21:35 +00:00
Enumerate ( ) ;
2011-02-13 23:44:55 +00:00
2009-09-13 08:21:35 +00:00
return S_OK ;
}
2008-12-08 05:25:12 +00:00
2009-09-13 08:21:35 +00:00
void Shutdown ( )
{
2010-12-29 13:07:00 +00:00
if ( ! d3d_dll_ref ) return ;
if ( - - d3d_dll_ref ! = 0 ) return ;
if ( D3D ) D3D - > Release ( ) ;
2010-11-21 15:44:50 +00:00
D3D = NULL ;
if ( hD3DDll ) FreeLibrary ( hD3DDll ) ;
PDirect3DCreate9 = NULL ;
2009-09-13 08:21:35 +00:00
}
2008-12-08 05:25:12 +00:00
2009-09-13 08:21:35 +00:00
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
2010-06-05 01:38:22 +00:00
D3D : : SetRenderState ( D3DRS_ADAPTIVETESS_Y , ( D3DFORMAT ) MAKEFOURCC ( ' A ' , ' T ' , ' O ' , ' C ' ) ) ;
2009-09-13 08:21:35 +00:00
}
2008-12-08 05:25:12 +00:00
2009-09-15 21:25:34 +00:00
void InitPP ( int adapter , int f , int aa_mode , D3DPRESENT_PARAMETERS * pp )
{
ZeroMemory ( pp , sizeof ( D3DPRESENT_PARAMETERS ) ) ;
pp - > hDeviceWindow = hWnd ;
if ( auto_depth_stencil )
{
pp - > EnableAutoDepthStencil = TRUE ;
pp - > AutoDepthStencilFormat = D3DFMT_D24S8 ;
} else {
pp - > EnableAutoDepthStencil = FALSE ;
pp - > AutoDepthStencilFormat = D3DFMT_UNKNOWN ;
2008-12-08 05:25:12 +00:00
}
2010-07-09 20:56:16 +00:00
pp - > BackBufferFormat = D3DFMT_X8R8G8B8 ;
2009-09-15 21:25:34 +00:00
if ( aa_mode > = ( int ) adapters [ adapter ] . aa_levels . size ( ) )
aa_mode = 0 ;
pp - > MultiSampleType = adapters [ adapter ] . aa_levels [ aa_mode ] . ms_setting ;
pp - > MultiSampleQuality = adapters [ adapter ] . aa_levels [ aa_mode ] . qual_setting ;
2009-10-17 09:09:52 +00:00
2009-09-15 21:25:34 +00:00
pp - > Flags = auto_depth_stencil ? D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL : 0 ;
2010-04-12 01:33:10 +00:00
RECT client ;
GetClientRect ( hWnd , & client ) ;
xres = pp - > BackBufferWidth = client . right - client . left ;
yres = pp - > BackBufferHeight = client . bottom - client . top ;
pp - > SwapEffect = D3DSWAPEFFECT_DISCARD ;
pp - > PresentationInterval = g_Config . bVSync ? D3DPRESENT_INTERVAL_DEFAULT : D3DPRESENT_INTERVAL_IMMEDIATE ;
2010-11-08 22:17:51 +00:00
pp - > Windowed = ! g_Config . b3DVision ;
2009-09-15 21:25:34 +00:00
}
2008-12-08 05:25:12 +00:00
2009-09-15 21:25:34 +00:00
void Enumerate ( )
{
numAdapters = D3D : : D3D - > GetAdapterCount ( ) ;
2009-10-17 09:09:52 +00:00
2009-09-15 21:25:34 +00:00
for ( int i = 0 ; i < std : : min ( MAX_ADAPTERS , numAdapters ) ; i + + )
{
Adapter & a = adapters [ i ] ;
2009-10-17 09:09:52 +00:00
a . aa_levels . clear ( ) ;
a . resolutions . clear ( ) ;
2009-09-15 21:25:34 +00:00
D3D : : D3D - > GetAdapterIdentifier ( i , 0 , & a . ident ) ;
bool isNvidia = a . ident . VendorId = = VENDOR_NVIDIA ;
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
2010-02-05 21:55:02 +00:00
// Add SuperSamples modes
2010-08-03 18:57:59 +00:00
a . aa_levels . push_back ( AALevel ( " None " , D3DMULTISAMPLE_NONE , 0 ) ) ;
2010-06-09 15:33:01 +00:00
a . aa_levels . push_back ( AALevel ( " 4x SSAA " , D3DMULTISAMPLE_NONE , 0 ) ) ;
a . aa_levels . push_back ( AALevel ( " 9x SSAA " , D3DMULTISAMPLE_NONE , 0 ) ) ;
2010-02-05 21:55:02 +00:00
//Add multisample modes
2010-02-08 23:23:04 +00:00
//disable them will they are not implemnted
/*
2009-09-15 21:25:34 +00:00
DWORD qlevels = 0 ;
if ( D3DERR_NOTAVAILABLE ! = D3D : : D3D - > CheckDeviceMultiSampleType (
i , D3DDEVTYPE_HAL , D3DFMT_X8R8G8B8 , TRUE , D3DMULTISAMPLE_2_SAMPLES , & qlevels ) )
if ( qlevels > 0 )
a . aa_levels . push_back ( AALevel ( " 2x MSAA " , D3DMULTISAMPLE_2_SAMPLES , 0 ) ) ;
if ( D3DERR_NOTAVAILABLE ! = D3D : : D3D - > CheckDeviceMultiSampleType (
i , D3DDEVTYPE_HAL , D3DFMT_X8R8G8B8 , TRUE , D3DMULTISAMPLE_2_SAMPLES , & qlevels ) )
if ( qlevels > 0 )
a . aa_levels . push_back ( AALevel ( " 4x MSAA " , D3DMULTISAMPLE_4_SAMPLES , 0 ) ) ;
2008-12-08 05:25:12 +00:00
2009-09-15 21:25:34 +00:00
if ( D3DERR_NOTAVAILABLE ! = D3D : : D3D - > CheckDeviceMultiSampleType (
i , D3DDEVTYPE_HAL , D3DFMT_X8R8G8B8 , TRUE , D3DMULTISAMPLE_8_SAMPLES , & qlevels ) )
if ( qlevels > 0 )
a . aa_levels . push_back ( AALevel ( " 8x MSAA " , D3DMULTISAMPLE_8_SAMPLES , 0 ) ) ;
2008-12-08 05:25:12 +00:00
2009-09-15 21:25:34 +00:00
if ( isNvidia )
{
// CSAA support
2008-12-08 05:25:12 +00:00
if ( D3DERR_NOTAVAILABLE ! = D3D : : D3D - > CheckDeviceMultiSampleType (
2009-09-15 21:25:34 +00:00
i , D3DDEVTYPE_HAL , D3DFMT_X8R8G8B8 , TRUE , D3DMULTISAMPLE_4_SAMPLES , & qlevels ) )
2008-12-08 05:25:12 +00:00
{
2009-09-15 21:25:34 +00:00
if ( qlevels > 2 )
2008-12-08 05:25:12 +00:00
{
2009-09-15 21:25:34 +00:00
// 8x, 8xQ are available
// See http://developer.nvidia.com/object/coverage-sampled-aa.html
a . aa_levels . push_back ( AALevel ( " 8x CSAA " , D3DMULTISAMPLE_4_SAMPLES , 2 ) ) ;
a . aa_levels . push_back ( AALevel ( " 8xQ CSAA " , D3DMULTISAMPLE_8_SAMPLES , 0 ) ) ;
2008-12-08 05:25:12 +00:00
}
2009-09-15 21:25:34 +00:00
}
if ( D3DERR_NOTAVAILABLE ! = D3D : : D3D - > CheckDeviceMultiSampleType (
2010-06-05 01:38:22 +00:00
i , D3DDEVTYPE_HAL , D3DFMT_X8R8G8B8 , TRUE , D3DMULTISAMPLE_8_SAMPLES , & qlevels ) )
2009-09-15 21:25:34 +00:00
{
if ( qlevels > 2 )
2008-12-08 05:25:12 +00:00
{
2009-09-15 21:25:34 +00:00
// 16x, 16xQ are available
// See http://developer.nvidia.com/object/coverage-sampled-aa.html
a . aa_levels . push_back ( AALevel ( " 16x CSAA " , D3DMULTISAMPLE_4_SAMPLES , 4 ) ) ;
a . aa_levels . push_back ( AALevel ( " 16xQ CSAA " , D3DMULTISAMPLE_8_SAMPLES , 2 ) ) ;
2008-12-08 05:25:12 +00:00
}
}
2009-09-15 21:25:34 +00:00
}
2010-02-08 23:23:04 +00:00
*/
2009-09-16 20:12:14 +00:00
// Determine if INTZ is supported. Code from ATI's doc.
// http://developer.amd.com/gpu_assets/Advanced%20DX9%20Capabilities%20for%20ATI%20Radeon%20Cards.pdf
a . supports_intz = D3D_OK = = D3D - > CheckDeviceFormat (
i , D3DDEVTYPE_HAL , D3DFMT_X8R8G8B8 ,
D3DUSAGE_DEPTHSTENCIL , D3DRTYPE_TEXTURE , FOURCC_INTZ ) ;
// Also check for RAWZ (nvidia only, but the only option to get Z24 textures on sub GF8800
a . supports_rawz = D3D_OK = = D3D - > CheckDeviceFormat (
i , D3DDEVTYPE_HAL , D3DFMT_X8R8G8B8 ,
2010-06-05 01:38:22 +00:00
D3DUSAGE_DEPTHSTENCIL , D3DRTYPE_TEXTURE , FOURCC_RAWZ ) ;
2009-09-16 20:12:14 +00:00
// Might as well check for RESZ and NULL too.
a . supports_resz = D3D_OK = = D3D - > CheckDeviceFormat (
i , D3DDEVTYPE_HAL , D3DFMT_X8R8G8B8 ,
2010-06-05 01:38:22 +00:00
D3DUSAGE_DEPTHSTENCIL , D3DRTYPE_TEXTURE , FOURCC_RESZ ) ;
2009-09-28 16:39:29 +00:00
a . supports_null = D3D_OK = = D3D - > CheckDeviceFormat (
2009-09-16 20:12:14 +00:00
i , D3DDEVTYPE_HAL , D3DFMT_X8R8G8B8 ,
2010-06-05 01:38:22 +00:00
D3DUSAGE_DEPTHSTENCIL , D3DRTYPE_TEXTURE , FOURCC_NULL ) ;
2009-09-16 20:12:14 +00:00
2009-09-15 21:25:34 +00:00
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 ;
D3D : : D3D - > EnumAdapterModes ( i , D3DFMT_X8R8G8B8 , m , & mode ) ;
int found = - 1 ;
for ( int x = 0 ; x < ( int ) a . resolutions . size ( ) ; x + + )
2008-12-08 05:25:12 +00:00
{
2009-09-15 21:25:34 +00:00
if ( a . resolutions [ x ] . xres = = mode . Width & & a . resolutions [ x ] . yres = = mode . Height )
2008-12-08 05:25:12 +00:00
{
2009-09-15 21:25:34 +00:00
found = x ;
break ;
2008-12-08 05:25:12 +00:00
}
2009-09-15 21:25:34 +00:00
}
2008-12-08 05:25:12 +00:00
2009-09-15 21:25:34 +00:00
Resolution temp ;
Resolution & r = found = = - 1 ? temp : a . resolutions [ found ] ;
sprintf ( r . name , " %ix%i " , mode . Width , mode . Height ) ;
r . bitdepths . insert ( mode . Format ) ;
r . refreshes . insert ( mode . RefreshRate ) ;
if ( found = = - 1 & & mode . Width > = 640 & & mode . Height > = 480 )
{
r . xres = mode . Width ;
r . yres = mode . Height ;
a . resolutions . push_back ( r ) ;
2008-12-08 05:25:12 +00:00
}
}
}
2009-09-15 21:25:34 +00:00
}
2008-12-08 05:25:12 +00:00
2010-07-17 11:42:28 +00:00
// dynamically picks one of the available d3dx9 dlls and loads it.
// we're first trying to load the dll Dolphin was compiled with, otherwise the most up-to-date one
HRESULT LoadD3DX9 ( )
{
2010-12-29 13:07:00 +00:00
if ( d3dx_dll_ref + + > 0 ) return S_OK ;
2010-07-17 11:42:28 +00:00
HRESULT hr = E_FAIL ;
hD3DXDll = LoadLibraryA ( StringFromFormat ( " d3dx9_%d.dll " , D3DX_SDK_VERSION ) . c_str ( ) ) ;
if ( hD3DXDll ! = NULL )
{
hr = S_OK ;
}
else
{
// if that fails, try loading older dlls (no need to look for newer ones)
for ( unsigned int num = D3DX_SDK_VERSION - 1 ; num > = 24 ; - - num )
{
hD3DXDll = LoadLibraryA ( StringFromFormat ( " d3dx9_%d.dll " , num ) . c_str ( ) ) ;
if ( hD3DXDll ! = NULL )
{
NOTICE_LOG ( VIDEO , " Successfully loaded %s. If you're having trouble, try updating your DX runtime first. " , StringFromFormat ( " d3dx9_%d.dll " , num ) . c_str ( ) ) ;
hr = S_OK ;
break ;
}
}
if ( FAILED ( hr ) )
{
MessageBoxA ( NULL , " Failed to load any D3DX9 dll, update your DX9 runtime, please " , " Critical error " , MB_OK | MB_ICONERROR ) ;
return hr ;
}
}
PD3DXCompileShader = ( D3DXCOMPILESHADERTYPE ) GetProcAddress ( hD3DXDll , " D3DXCompileShader " ) ;
if ( PD3DXCompileShader = = NULL )
{
MessageBoxA ( NULL , " GetProcAddress failed for D3DXCompileShader! " , " Critical error " , MB_OK | MB_ICONERROR ) ;
goto fail ;
}
PD3DXSaveSurfaceToFileA = ( D3DXSAVESURFACETOFILEATYPE ) GetProcAddress ( hD3DXDll , " D3DXSaveSurfaceToFileA " ) ;
if ( PD3DXSaveSurfaceToFileA = = NULL )
{
MessageBoxA ( NULL , " GetProcAddress failed for D3DXSaveSurfaceToFileA! " , " Critical error " , MB_OK | MB_ICONERROR ) ;
goto fail ;
}
PD3DXSaveTextureToFileA = ( D3DXSAVETEXTURETOFILEATYPE ) GetProcAddress ( hD3DXDll , " D3DXSaveTextureToFileA " ) ;
if ( PD3DXSaveTextureToFileA = = NULL )
{
MessageBoxA ( NULL , " GetProcAddress failed for D3DXSaveTextureToFileA! " , " Critical error " , MB_OK | MB_ICONERROR ) ;
goto fail ;
}
return S_OK ;
fail :
2010-12-29 13:07:00 +00:00
- - d3dx_dll_ref ;
2010-07-17 11:42:28 +00:00
FreeLibrary ( hD3DXDll ) ;
PD3DXCompileShader = NULL ;
PD3DXSaveSurfaceToFileA = NULL ;
PD3DXSaveTextureToFileA = NULL ;
return E_FAIL ;
}
void UnloadD3DX9 ( )
{
2010-12-29 13:07:00 +00:00
if ( ! d3dx_dll_ref ) return ;
if ( - - d3dx_dll_ref ! = 0 ) return ;
2010-07-17 11:42:28 +00:00
FreeLibrary ( hD3DXDll ) ;
PD3DXCompileShader = NULL ;
PD3DXSaveSurfaceToFileA = NULL ;
PD3DXSaveTextureToFileA = NULL ;
}
2010-04-12 01:33:10 +00:00
HRESULT Create ( int adapter , HWND wnd , int _resolution , int aa_mode , bool auto_depth )
2009-09-15 21:25:34 +00:00
{
hWnd = wnd ;
multisample = aa_mode ;
resolution = _resolution ;
auto_depth_stencil = auto_depth ;
cur_adapter = adapter ;
2010-07-17 11:42:28 +00:00
D3DPRESENT_PARAMETERS d3dpp ;
HRESULT hr = LoadD3DX9 ( ) ;
if ( FAILED ( hr ) ) return hr ;
2009-09-15 21:25:34 +00:00
InitPP ( adapter , resolution , aa_mode , & d3dpp ) ;
if ( FAILED ( D3D - > CreateDevice (
adapter ,
D3DDEVTYPE_HAL ,
wnd ,
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE , //doesn't seem to make a difference
2009-09-15 21:25:34 +00:00
& d3dpp , & dev ) ) )
2008-12-08 05:25:12 +00:00
{
2009-09-13 08:21:35 +00:00
if ( FAILED ( D3D - > CreateDevice (
2008-12-08 05:25:12 +00:00
adapter ,
D3DDEVTYPE_HAL ,
wnd ,
2009-09-19 10:46:25 +00:00
D3DCREATE_SOFTWARE_VERTEXPROCESSING ,
2009-09-13 08:21:35 +00:00
& d3dpp , & dev ) ) )
2008-12-08 05:25:12 +00:00
{
2009-09-15 08:13:45 +00:00
MessageBox ( wnd ,
2009-09-19 10:46:25 +00:00
_T ( " Failed to initialize Direct3D. " ) ,
2011-02-14 02:18:03 +00:00
_T ( " Dolphin Direct3D Backend " ) , MB_OK | MB_ICONERROR ) ;
2009-09-15 21:25:34 +00:00
return E_FAIL ;
2008-12-08 05:25:12 +00:00
}
}
2009-09-16 20:12:14 +00:00
2009-09-15 21:25:34 +00:00
dev - > GetDeviceCaps ( & caps ) ;
dev - > GetRenderTarget ( 0 , & back_buffer ) ;
if ( dev - > GetDepthStencilSurface ( & back_buffer_z ) = = D3DERR_NOTFOUND )
back_buffer_z = NULL ;
2010-06-05 01:38:22 +00:00
D3D : : SetRenderState ( D3DRS_ZENABLE , D3DZB_TRUE ) ;
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
D3D : : SetRenderState ( D3DRS_FILLMODE , g_Config . bWireFrame ? D3DFILL_WIREFRAME : D3DFILL_SOLID ) ;
memset ( m_Textures , 0 , sizeof ( m_Textures ) ) ;
memset ( m_TextureStageStatesSet , 0 , sizeof ( m_TextureStageStatesSet ) ) ;
memset ( m_RenderStatesSet , 0 , sizeof ( m_RenderStatesSet ) ) ;
memset ( m_SamplerStatesSet , 0 , sizeof ( m_SamplerStatesSet ) ) ;
memset ( m_TextureStageStatesChanged , 0 , sizeof ( m_TextureStageStatesChanged ) ) ;
memset ( m_RenderStatesChanged , 0 , sizeof ( m_RenderStatesChanged ) ) ;
memset ( m_SamplerStatesChanged , 0 , sizeof ( m_SamplerStatesChanged ) ) ;
m_VtxDecl = NULL ;
m_PixelShader = NULL ;
m_VertexShader = NULL ;
2009-09-15 21:25:34 +00:00
// Device state would normally be set here
return S_OK ;
}
void Close ( )
{
2010-07-17 11:42:28 +00:00
UnloadD3DX9 ( ) ;
2010-02-25 03:14:40 +00:00
if ( back_buffer_z )
back_buffer_z - > Release ( ) ;
back_buffer_z = NULL ;
2010-06-05 01:38:22 +00:00
if ( back_buffer )
back_buffer - > Release ( ) ;
2010-02-25 03:14:40 +00:00
back_buffer = NULL ;
ULONG references = dev - > Release ( ) ;
if ( references )
ERROR_LOG ( VIDEO , " Unreleased references: %i. " , references ) ;
2010-06-05 01:38:22 +00:00
dev = NULL ;
2009-09-15 21:25:34 +00:00
}
2008-12-08 05:25:12 +00:00
2009-09-13 08:21:35 +00:00
const D3DCAPS9 & GetCaps ( )
{
return caps ;
}
2008-12-08 05:25:12 +00:00
2011-01-02 23:13:29 +00:00
// returns true if size was changed
bool FixTextureSize ( int & width , int & height )
{
int oldw = width , oldh = height ;
// conditional nonpow2 support should work fine for us
if ( ( caps . TextureCaps & D3DPTEXTURECAPS_POW2 ) & & ! ( caps . TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL ) )
{
// all texture dimensions need to be powers of two
2011-01-03 14:35:07 +00:00
width = ( int ) MakePow2 ( ( u32 ) width ) ;
height = ( int ) MakePow2 ( ( u32 ) height ) ;
2011-01-02 23:13:29 +00:00
}
if ( caps . TextureCaps & D3DPTEXTURECAPS_SQUAREONLY )
{
width = height = max ( width , height ) ;
}
width = min ( width , ( int ) caps . MaxTextureWidth ) ;
height = min ( height , ( int ) caps . MaxTextureHeight ) ;
return ( width ! = oldw ) | | ( height ! = oldh ) ;
}
2011-01-03 14:35:07 +00:00
// returns true if format is supported
bool CheckTextureSupport ( DWORD usage , D3DFORMAT tex_format )
{
return D3D_OK = = D3D - > CheckDeviceFormat ( cur_adapter , D3DDEVTYPE_HAL , D3DFMT_X8R8G8B8 , usage , D3DRTYPE_TEXTURE , tex_format ) ;
}
bool CheckDepthStencilSupport ( D3DFORMAT target_format , D3DFORMAT depth_format )
{
return D3D_OK = = D3D - > CheckDepthStencilMatch ( cur_adapter , D3DDEVTYPE_HAL , D3DFMT_X8R8G8B8 , target_format , depth_format ) ;
}
2011-01-04 12:56:52 +00:00
D3DFORMAT GetSupportedDepthTextureFormat ( )
{
for ( int i = 0 ; i < sizeof ( DepthFormats ) / sizeof ( D3DFORMAT ) ; + + i )
if ( D3D : : CheckTextureSupport ( D3DUSAGE_DEPTHSTENCIL , DepthFormats [ i ] ) )
return DepthFormats [ i ] ;
return D3DFMT_UNKNOWN ;
}
D3DFORMAT GetSupportedDepthSurfaceFormat ( D3DFORMAT target_format )
{
for ( int i = 0 ; i < sizeof ( DepthFormats ) / sizeof ( D3DFORMAT ) ; + + i )
if ( D3D : : CheckDepthStencilSupport ( target_format , DepthFormats [ i ] ) )
return DepthFormats [ i ] ;
return D3DFMT_UNKNOWN ;
}
2009-09-13 08:21:35 +00:00
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 ) ] ;
}
2008-12-08 05:25:12 +00:00
2009-09-13 08:21:35 +00:00
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 ) ] ;
}
LPDIRECT3DSURFACE9 GetBackBufferSurface ( )
{
2009-09-13 17:46:33 +00:00
return back_buffer ;
}
LPDIRECT3DSURFACE9 GetBackBufferDepthSurface ( )
{
return back_buffer_z ;
2009-09-13 08:21:35 +00:00
}
2008-12-08 05:25:12 +00:00
2009-09-13 08:21:35 +00:00
void ShowD3DError ( HRESULT err )
{
2010-06-05 01:38:22 +00:00
switch ( err )
2008-12-08 05:25:12 +00:00
{
2010-06-05 01:38:22 +00:00
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 ;
2009-09-13 08:21:35 +00:00
default :
2010-06-05 01:38:22 +00:00
// MessageBox(0,_T("Other error or success"),_T("ERROR"),0);
2009-09-13 08:21:35 +00:00
break ;
2008-12-08 05:25:12 +00:00
}
2009-09-13 08:21:35 +00:00
}
2008-12-08 05:25:12 +00:00
2009-09-15 21:25:34 +00:00
void Reset ( )
{
if ( dev )
2008-12-08 05:25:12 +00:00
{
2009-09-16 20:12:14 +00:00
// ForgetCachedState();
2009-09-15 19:53:22 +00:00
2009-09-15 21:25:34 +00:00
// Can't keep a pointer around to the backbuffer surface when resetting.
if ( back_buffer_z )
back_buffer_z - > Release ( ) ;
back_buffer_z = NULL ;
back_buffer - > Release ( ) ;
back_buffer = NULL ;
2009-09-15 19:53:22 +00:00
2010-06-05 01:38:22 +00:00
D3DPRESENT_PARAMETERS d3dpp ;
2009-09-15 21:25:34 +00:00
InitPP ( cur_adapter , resolution , multisample , & d3dpp ) ;
HRESULT hr = dev - > Reset ( & d3dpp ) ;
ShowD3DError ( hr ) ;
2008-12-08 05:25:12 +00:00
2009-09-15 21:25:34 +00:00
dev - > GetRenderTarget ( 0 , & back_buffer ) ;
if ( dev - > GetDepthStencilSurface ( & back_buffer_z ) = = D3DERR_NOTFOUND )
back_buffer_z = NULL ;
2009-09-16 20:12:14 +00:00
ApplyCachedState ( ) ;
2008-12-08 05:25:12 +00:00
}
2009-09-15 21:25:34 +00:00
}
int GetBackBufferWidth ( )
{
return xres ;
}
2008-12-08 05:25:12 +00:00
2009-09-15 21:25:34 +00:00
int GetBackBufferHeight ( )
{
return yres ;
}
bool BeginFrame ( )
{
if ( bFrameInProgress )
2008-12-08 05:25:12 +00:00
{
2009-09-15 21:25:34 +00:00
PanicAlert ( " BeginFrame WTF " ) ;
return false ;
2008-12-08 05:25:12 +00:00
}
2009-09-15 21:25:34 +00:00
bFrameInProgress = true ;
if ( dev )
2008-12-08 05:25:12 +00:00
{
2009-09-15 21:25:34 +00:00
dev - > BeginScene ( ) ;
return true ;
2008-12-08 05:25:12 +00:00
}
2009-09-15 21:25:34 +00:00
else
return false ;
}
2008-12-26 17:02:46 +00:00
2009-09-15 21:25:34 +00:00
void EndFrame ( )
{
if ( ! bFrameInProgress )
2008-12-08 05:25:12 +00:00
{
2009-09-15 21:25:34 +00:00
PanicAlert ( " EndFrame WTF " ) ;
return ;
2008-12-08 05:25:12 +00:00
}
2009-09-15 21:25:34 +00:00
bFrameInProgress = false ;
2009-09-20 05:04:45 +00:00
dev - > EndScene ( ) ;
2009-09-20 03:29:43 +00:00
}
2008-12-08 05:25:12 +00:00
2009-09-20 03:29:43 +00:00
void Present ( )
{
2009-09-15 21:25:34 +00:00
if ( dev )
2008-12-08 05:25:12 +00:00
{
2009-09-15 21:25:34 +00:00
dev - > Present ( NULL , NULL , NULL , NULL ) ;
2008-12-08 05:25:12 +00:00
}
2009-09-15 21:25:34 +00:00
}
2009-09-16 20:12:14 +00:00
void ApplyCachedState ( )
2009-09-15 21:25:34 +00:00
{
2009-09-16 20:12:14 +00:00
for ( int sampler = 0 ; sampler < 8 ; sampler + + )
{
for ( int type = 0 ; type < MaxSamplerTypes ; type + + )
{
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
if ( m_SamplerStatesSet [ sampler ] [ type ] )
D3D : : dev - > SetSamplerState ( sampler , ( D3DSAMPLERSTATETYPE ) type , m_SamplerStates [ sampler ] [ type ] ) ;
2009-09-16 20:12:14 +00:00
}
}
for ( int rs = 0 ; rs < MaxRenderStates ; rs + + )
{
if ( m_RenderStatesSet [ rs ] )
D3D : : dev - > SetRenderState ( ( D3DRENDERSTATETYPE ) rs , m_RenderStates [ rs ] ) ;
}
// We don't bother restoring these so let's just wipe the state copy
// so no stale state is around.
2009-09-15 21:25:34 +00:00
memset ( m_Textures , 0 , sizeof ( m_Textures ) ) ;
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
memset ( m_TextureStageStatesSet , 0 , sizeof ( m_TextureStageStatesSet ) ) ;
2010-06-05 01:38:22 +00:00
memset ( m_TextureStageStatesChanged , 0 , sizeof ( m_TextureStageStatesChanged ) ) ;
2009-09-19 10:46:25 +00:00
m_VtxDecl = NULL ;
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
m_PixelShader = NULL ;
m_VertexShader = NULL ;
2009-09-15 21:25:34 +00:00
}
2008-12-08 05:25:12 +00:00
2009-09-03 19:24:16 +00:00
void SetTexture ( DWORD Stage , LPDIRECT3DBASETEXTURE9 pTexture )
{
if ( m_Textures [ Stage ] ! = pTexture )
{
m_Textures [ Stage ] = pTexture ;
D3D : : dev - > SetTexture ( Stage , pTexture ) ;
}
}
2009-12-15 01:40:54 +00:00
void RefreshRenderState ( D3DRENDERSTATETYPE State )
{
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
if ( m_RenderStatesSet [ State ] & & m_RenderStatesChanged [ State ] )
{
D3D : : dev - > SetRenderState ( State , m_RenderStates [ State ] ) ;
m_RenderStatesChanged [ State ] = false ;
}
2009-12-15 01:40:54 +00:00
}
2009-09-03 19:24:16 +00:00
void SetRenderState ( D3DRENDERSTATETYPE State , DWORD Value )
{
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
if ( m_RenderStates [ State ] ! = Value | | ! m_RenderStatesSet [ State ] )
2009-09-03 19:24:16 +00:00
{
m_RenderStates [ State ] = Value ;
2009-09-16 20:12:14 +00:00
m_RenderStatesSet [ State ] = true ;
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
m_RenderStatesChanged [ State ] = false ;
D3D : : dev - > SetRenderState ( State , Value ) ;
}
}
void ChangeRenderState ( D3DRENDERSTATETYPE State , DWORD Value )
{
if ( m_RenderStates [ State ] ! = Value | | ! m_RenderStatesSet [ State ] )
{
m_RenderStatesChanged [ State ] = m_RenderStatesSet [ State ] ;
2009-09-03 19:24:16 +00:00
D3D : : dev - > SetRenderState ( State , Value ) ;
}
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
else
{
m_RenderStatesChanged [ State ] = false ;
}
2009-09-03 19:24:16 +00:00
}
void SetTextureStageState ( DWORD Stage , D3DTEXTURESTAGESTATETYPE Type , DWORD Value )
{
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
if ( m_TextureStageStates [ Stage ] [ Type ] ! = Value | | ! m_TextureStageStatesSet [ Stage ] [ Type ] )
2009-09-03 19:24:16 +00:00
{
m_TextureStageStates [ Stage ] [ Type ] = Value ;
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
m_TextureStageStatesSet [ Stage ] [ Type ] = true ;
m_TextureStageStatesChanged [ Stage ] [ Type ] = false ;
2009-09-03 19:24:16 +00:00
D3D : : dev - > SetTextureStageState ( Stage , Type , Value ) ;
}
}
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
void RefreshTextureStageState ( DWORD Stage , D3DTEXTURESTAGESTATETYPE Type )
2009-11-22 02:37:00 +00:00
{
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
if ( m_TextureStageStatesSet [ Stage ] [ Type ] & & m_TextureStageStatesChanged [ Stage ] [ Type ] )
{
D3D : : dev - > SetTextureStageState ( Stage , Type , m_TextureStageStates [ Stage ] [ Type ] ) ;
m_TextureStageStatesChanged [ Stage ] [ Type ] = false ;
}
}
void ChangeTextureStageState ( DWORD Stage , D3DTEXTURESTAGESTATETYPE Type , DWORD Value )
{
if ( m_TextureStageStates [ Stage ] [ Type ] ! = Value | | ! m_TextureStageStatesSet [ Stage ] [ Type ] )
{
m_TextureStageStatesChanged [ Stage ] [ Type ] = m_TextureStageStatesSet [ Stage ] [ Type ] ;
D3D : : dev - > SetTextureStageState ( Stage , Type , Value ) ;
}
else
{
m_TextureStageStatesChanged [ Stage ] [ Type ] = false ;
}
2009-11-22 02:37:00 +00:00
}
2009-09-03 19:24:16 +00:00
void SetSamplerState ( DWORD Sampler , D3DSAMPLERSTATETYPE Type , DWORD Value )
{
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
if ( m_SamplerStates [ Sampler ] [ Type ] ! = Value | | ! m_SamplerStatesSet [ Sampler ] [ Type ] )
2009-09-03 19:24:16 +00:00
{
m_SamplerStates [ Sampler ] [ Type ] = Value ;
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
m_SamplerStatesSet [ Sampler ] [ Type ] = true ;
m_SamplerStatesChanged [ Sampler ] [ Type ] = false ;
2009-09-03 19:24:16 +00:00
D3D : : dev - > SetSamplerState ( Sampler , Type , Value ) ;
}
}
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
void RefreshSamplerState ( DWORD Sampler , D3DSAMPLERSTATETYPE Type )
{
if ( m_SamplerStatesSet [ Sampler ] [ Type ] & & m_SamplerStatesChanged [ Sampler ] [ Type ] )
{
2010-06-05 01:38:22 +00:00
D3D : : dev - > SetSamplerState ( Sampler , Type , m_SamplerStates [ Sampler ] [ Type ] ) ;
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
m_SamplerStatesChanged [ Sampler ] [ Type ] = false ;
}
}
void ChangeSamplerState ( DWORD Sampler , D3DSAMPLERSTATETYPE Type , DWORD Value )
{
if ( m_SamplerStates [ Sampler ] [ Type ] ! = Value | | ! m_SamplerStatesSet [ Sampler ] [ Type ] )
{
m_SamplerStatesChanged [ Sampler ] [ Type ] = m_SamplerStatesSet [ Sampler ] [ Type ] ;
D3D : : dev - > SetSamplerState ( Sampler , Type , Value ) ;
}
else
{
m_SamplerStatesChanged [ Sampler ] [ Type ] = false ;
}
}
2009-11-08 20:35:11 +00:00
void RefreshVertexDeclaration ( )
{
if ( m_VtxDecl )
{
2010-06-05 01:38:22 +00:00
D3D : : dev - > SetVertexDeclaration ( m_VtxDecl ) ;
2009-11-08 20:35:11 +00:00
}
}
2009-09-19 10:46:25 +00:00
void SetVertexDeclaration ( LPDIRECT3DVERTEXDECLARATION9 decl )
{
if ( ! decl ) {
m_VtxDecl = NULL ;
return ;
}
if ( decl ! = m_VtxDecl )
{
D3D : : dev - > SetVertexDeclaration ( decl ) ;
m_VtxDecl = decl ;
}
}
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
void RefreshVertexShader ( )
{
if ( m_VertexShader )
{
2010-06-05 01:38:22 +00:00
D3D : : dev - > SetVertexShader ( m_VertexShader ) ;
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
}
}
void SetVertexShader ( LPDIRECT3DVERTEXSHADER9 shader )
{
if ( ! shader ) {
m_VertexShader = NULL ;
return ;
}
if ( shader ! = m_VertexShader )
{
D3D : : dev - > SetVertexShader ( shader ) ;
m_VertexShader = shader ;
}
}
void RefreshPixelShader ( )
{
if ( m_PixelShader )
{
2010-06-05 01:38:22 +00:00
D3D : : dev - > SetPixelShader ( m_PixelShader ) ;
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
}
}
void SetPixelShader ( LPDIRECT3DPIXELSHADER9 shader )
{
if ( ! shader ) {
m_PixelShader = NULL ;
return ;
}
if ( shader ! = m_PixelShader )
{
D3D : : dev - > SetPixelShader ( shader ) ;
m_PixelShader = shader ;
}
}
2008-12-26 17:02:46 +00:00
} // namespace
2011-01-29 20:16:51 +00:00
2011-02-14 02:18:03 +00:00
} // namespace DX9