1 // Copyright (C) 2003 Dolphin Project.
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0.
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License 2.0 for more details.
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
15 // Official SVN repository and contact information can be found at
16 // http://code.google.com/p/dolphin-emu/
31 // From http://developer.amd.com/gpu_assets/Advanced%20DX9%20Capabilities%20for%20ATI%20Radeon%20Cards.pdf
32 // Magic FourCC's to unlock undocumented D3D9 features:
35 #define FOURCC_INTZ ((D3DFORMAT)(MAKEFOURCC('I','N','T','Z')))
36 #define FOURCC_RAWZ ((D3DFORMAT)(MAKEFOURCC('R','A','W','Z')))
37 #define FOURCC_DF24 ((D3DFORMAT)(MAKEFOURCC('D','F','2','4')))
38 #define FOURCC_DF16 ((D3DFORMAT)(MAKEFOURCC('D','F','1','6')))
40 // Depth buffer resolve:
41 #define FOURCC_RESZ ((D3DFORMAT)(MAKEFOURCC('R','E','S','Z')))
42 #define RESZ_CODE 0x7fa05000
44 // Null render target to do Z-only shadow maps: (probably not useful for Dolphin)
45 #define FOURCC_NULL ((D3DFORMAT)(MAKEFOURCC('N','U','L','L')))
49 HRESULT
Create(int adapter
, HWND wnd
, int resolution
, int aa_mode
, bool auto_depth
);
53 // Direct access to the device.
54 extern LPDIRECT3DDEVICE9 dev
;
55 extern bool bFrameInProgress
;
63 int GetBackBufferWidth();
64 int GetBackBufferHeight();
65 LPDIRECT3DSURFACE9
GetBackBufferSurface();
66 LPDIRECT3DSURFACE9
GetBackBufferDepthSurface();
67 LPDIRECT3DVERTEXBUFFER9
GetquadVB();
68 LPDIRECT3DVERTEXDECLARATION9
GetBasicvertexDecl();
69 const D3DCAPS9
&GetCaps();
70 const char *PixelShaderVersionString();
71 const char *VertexShaderVersionString();
72 void ShowD3DError(HRESULT err
);
74 // The following are "filtered" versions of the corresponding D3Ddev-> functions.
75 void SetTexture(DWORD Stage
, IDirect3DBaseTexture9
*pTexture
);
76 void SetRenderState(D3DRENDERSTATETYPE State
, DWORD Value
);
77 void RefreshRenderState(D3DRENDERSTATETYPE State
);
78 void ChangeRenderState(D3DRENDERSTATETYPE State
, DWORD Value
);
80 void SetTextureStageState(DWORD Stage
, D3DTEXTURESTAGESTATETYPE Type
, DWORD Value
);
81 void RefreshTextureStageState(DWORD Stage
, D3DTEXTURESTAGESTATETYPE Type
);
82 void ChangeTextureStageState(DWORD Stage
, D3DTEXTURESTAGESTATETYPE Type
, DWORD Value
);
84 void SetSamplerState(DWORD Sampler
, D3DSAMPLERSTATETYPE Type
, DWORD Value
);
85 void RefreshSamplerState(DWORD Sampler
, D3DSAMPLERSTATETYPE Type
);
86 void ChangeSamplerState(DWORD Sampler
, D3DSAMPLERSTATETYPE Type
, DWORD Value
);
88 void RefreshVertexDeclaration();
89 void SetVertexDeclaration(LPDIRECT3DVERTEXDECLARATION9 decl
);
91 void RefreshVertexShader();
92 void SetVertexShader(LPDIRECT3DVERTEXSHADER9 shader
);
94 void RefreshPixelShader();
95 void SetPixelShader(LPDIRECT3DPIXELSHADER9 shader
);
97 void ApplyCachedState();
99 // Utility functions for vendor specific hacks. So far, just the one.
100 void EnableAlphaToCoverage();
107 std::set
<D3DFORMAT
> bitdepths
;
108 std::set
<int> refreshes
;
113 AALevel(const char *n
, D3DMULTISAMPLE_TYPE m
, int q
) {
114 strncpy(name
, n
, 32);
120 D3DMULTISAMPLE_TYPE ms_setting
;
126 D3DADAPTER_IDENTIFIER9 ident
;
127 std::vector
<Resolution
> resolutions
;
128 std::vector
<AALevel
> aa_levels
;
129 bool supports_alpha_to_coverage
;
131 // Magic render targets, see the top of this file.
138 const Adapter
&GetAdapter(int i
);
139 const Adapter
&GetCurAdapter();
140 int GetNumAdapters();
145 // Used to not require the SDK and runtime versions to match:
146 // Linking with d3dx9.lib makes the most recent d3dx9_xx.dll of the
147 // compiler's SDK an actually unnecessary requirement.
148 // Add any d3dx9 functions which you want to use here and load them in LoadD3DX9()
149 typedef HRESULT (WINAPI
* D3DXSAVESURFACETOFILEATYPE
)(LPCSTR
, D3DXIMAGE_FILEFORMAT
, LPDIRECT3DSURFACE9
, CONST PALETTEENTRY
*, CONST RECT
*);
150 typedef HRESULT (WINAPI
* D3DXSAVETEXTURETOFILEATYPE
)(LPCSTR
, D3DXIMAGE_FILEFORMAT
, LPDIRECT3DBASETEXTURE9
, CONST PALETTEENTRY
*);
151 typedef HRESULT (WINAPI
* D3DXCOMPILESHADERTYPE
)(LPCSTR
, UINT
, CONST D3DXMACRO
*, LPD3DXINCLUDE
, LPCSTR
, LPCSTR
, DWORD
, LPD3DXBUFFER
*, LPD3DXBUFFER
*, LPD3DXCONSTANTTABLE
*);
153 extern D3DXSAVESURFACETOFILEATYPE PD3DXSaveSurfaceToFileA
;
154 extern D3DXSAVETEXTURETOFILEATYPE PD3DXSaveTextureToFileA
;
155 extern D3DXCOMPILESHADERTYPE PD3DXCompileShader
;