Dependency cleanup in DX9.
[dolphin.git] / Source / Plugins / Plugin_VideoDX9 / Src / D3DBase.h
blob533978a46ca95e9c022fdd577b09f2e98df61677
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/
18 #ifndef _D3DBASE_H
19 #define _D3DBASE_H
21 #include <vector>
22 #include <set>
24 #include <d3dx9.h>
26 #include "Common.h"
28 namespace D3D
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:
34 // Z texture formats
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')))
47 bool IsATIDevice();
48 HRESULT Init();
49 HRESULT Create(int adapter, HWND wnd, int resolution, int aa_mode, bool auto_depth);
50 void Close();
51 void Shutdown();
53 // Direct access to the device.
54 extern LPDIRECT3DDEVICE9 dev;
55 extern bool bFrameInProgress;
57 void Reset();
58 bool BeginFrame();
59 void EndFrame();
60 void Present();
61 bool CanUseINTZ();
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();
102 struct Resolution
104 char name[32];
105 int xres;
106 int yres;
107 std::set<D3DFORMAT> bitdepths;
108 std::set<int> refreshes;
111 struct AALevel
113 AALevel(const char *n, D3DMULTISAMPLE_TYPE m, int q) {
114 strncpy(name, n, 32);
115 name[31] = '\0';
116 ms_setting = m;
117 qual_setting = q;
119 char name[32];
120 D3DMULTISAMPLE_TYPE ms_setting;
121 int qual_setting;
124 struct Adapter
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.
132 bool supports_intz;
133 bool supports_rawz;
134 bool supports_resz;
135 bool supports_null;
138 const Adapter &GetAdapter(int i);
139 const Adapter &GetCurAdapter();
140 int GetNumAdapters();
142 } // namespace
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;
159 #endif