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/
19 #include "VideoConfig.h"
21 #include "XFStructs.h"
22 #include "StringUtil.h"
25 HINSTANCE hD3DXDll
= NULL
;
26 D3DXSAVESURFACETOFILEATYPE PD3DXSaveSurfaceToFileA
= NULL
;
27 D3DXSAVETEXTURETOFILEATYPE PD3DXSaveTextureToFileA
= NULL
;
28 D3DXCOMPILESHADERTYPE PD3DXCompileShader
= NULL
;
33 LPDIRECT3D9 D3D
= NULL
; // Used to create the D3DDevice
34 LPDIRECT3DDEVICE9 dev
= NULL
; // Our rendering device
35 LPDIRECT3DSURFACE9 back_buffer
;
36 LPDIRECT3DSURFACE9 back_buffer_z
;
40 static int multisample
;
41 static int resolution
;
42 static int xres
, yres
;
43 static bool auto_depth_stencil
= false;
45 #define VENDOR_NVIDIA 4318
46 #define VENDOR_ATI 4098
48 bool bFrameInProgress
= false;
50 #define MAX_ADAPTERS 4
51 static Adapter adapters
[MAX_ADAPTERS
];
52 static int numAdapters
;
53 static int cur_adapter
;
55 // Value caches for state filtering
56 const int MaxTextureStages
= 9;
57 const int MaxRenderStates
= 210 + 46;
58 const int MaxTextureTypes
= 33;
59 const int MaxSamplerSize
= 13;
60 const int MaxSamplerTypes
= 15;
61 static bool m_RenderStatesSet
[MaxRenderStates
];
62 static DWORD m_RenderStates
[MaxRenderStates
];
63 static bool m_RenderStatesChanged
[MaxRenderStates
];
65 static DWORD m_TextureStageStates
[MaxTextureStages
][MaxTextureTypes
];
66 static bool m_TextureStageStatesSet
[MaxTextureStages
][MaxTextureTypes
];
67 static bool m_TextureStageStatesChanged
[MaxTextureStages
][MaxTextureTypes
];
69 static DWORD m_SamplerStates
[MaxSamplerSize
][MaxSamplerTypes
];
70 static bool m_SamplerStatesSet
[MaxSamplerSize
][MaxSamplerTypes
];
71 static bool m_SamplerStatesChanged
[MaxSamplerSize
][MaxSamplerTypes
];
73 LPDIRECT3DBASETEXTURE9 m_Textures
[16];
74 LPDIRECT3DVERTEXDECLARATION9 m_VtxDecl
;
75 LPDIRECT3DPIXELSHADER9 m_PixelShader
;
76 LPDIRECT3DVERTEXSHADER9 m_VertexShader
;
80 int GetNumAdapters() { return numAdapters
; }
81 const Adapter
&GetAdapter(int i
) { return adapters
[i
]; }
82 const Adapter
&GetCurAdapter() { return adapters
[cur_adapter
]; }
86 return GetCurAdapter().ident
.VendorId
== VENDOR_ATI
;
92 // Create the D3D object, which is needed to create the D3DDevice.
93 D3D
= Direct3DCreate9(D3D_SDK_VERSION
);
106 void EnableAlphaToCoverage()
108 // Each vendor has their own specific little hack.
109 if (GetCurAdapter().ident
.VendorId
== VENDOR_ATI
)
110 D3D::SetRenderState(D3DRS_POINTSIZE
, (D3DFORMAT
)MAKEFOURCC('A', '2', 'M', '1'));
112 D3D::SetRenderState(D3DRS_ADAPTIVETESS_Y
, (D3DFORMAT
)MAKEFOURCC('A', 'T', 'O', 'C'));
115 void InitPP(int adapter
, int f
, int aa_mode
, D3DPRESENT_PARAMETERS
*pp
)
117 ZeroMemory(pp
, sizeof(D3DPRESENT_PARAMETERS
));
118 pp
->hDeviceWindow
= hWnd
;
119 if (auto_depth_stencil
)
121 pp
->EnableAutoDepthStencil
= TRUE
;
122 pp
->AutoDepthStencilFormat
= D3DFMT_D24S8
;
124 pp
->EnableAutoDepthStencil
= FALSE
;
125 pp
->AutoDepthStencilFormat
= D3DFMT_UNKNOWN
;
127 pp
->BackBufferFormat
= D3DFMT_X8R8G8B8
;
128 if (aa_mode
>= (int)adapters
[adapter
].aa_levels
.size())
131 pp
->MultiSampleType
= adapters
[adapter
].aa_levels
[aa_mode
].ms_setting
;
132 pp
->MultiSampleQuality
= adapters
[adapter
].aa_levels
[aa_mode
].qual_setting
;
134 pp
->Flags
= auto_depth_stencil
? D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL
: 0;
137 GetClientRect(hWnd
, &client
);
138 xres
= pp
->BackBufferWidth
= client
.right
- client
.left
;
139 yres
= pp
->BackBufferHeight
= client
.bottom
- client
.top
;
140 pp
->SwapEffect
= D3DSWAPEFFECT_DISCARD
;
141 pp
->PresentationInterval
= g_Config
.bVSync
? D3DPRESENT_INTERVAL_DEFAULT
: D3DPRESENT_INTERVAL_IMMEDIATE
;
147 numAdapters
= D3D::D3D
->GetAdapterCount();
149 for (int i
= 0; i
< std::min(MAX_ADAPTERS
, numAdapters
); i
++)
151 Adapter
&a
= adapters
[i
];
153 a
.resolutions
.clear();
154 D3D::D3D
->GetAdapterIdentifier(i
, 0, &a
.ident
);
155 bool isNvidia
= a
.ident
.VendorId
== VENDOR_NVIDIA
;
157 // Add SuperSamples modes
158 a
.aa_levels
.push_back(AALevel("NONE", D3DMULTISAMPLE_NONE
, 0));
159 a
.aa_levels
.push_back(AALevel("4x SSAA", D3DMULTISAMPLE_NONE
, 0));
160 a
.aa_levels
.push_back(AALevel("9x SSAA", D3DMULTISAMPLE_NONE
, 0));
161 //Add multisample modes
162 //disable them will they are not implemnted
165 if (D3DERR_NOTAVAILABLE != D3D::D3D->CheckDeviceMultiSampleType(
166 i, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES, &qlevels))
168 a.aa_levels.push_back(AALevel("2x MSAA", D3DMULTISAMPLE_2_SAMPLES, 0));
170 if (D3DERR_NOTAVAILABLE != D3D::D3D->CheckDeviceMultiSampleType(
171 i, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES, &qlevels))
173 a.aa_levels.push_back(AALevel("4x MSAA", D3DMULTISAMPLE_4_SAMPLES, 0));
175 if (D3DERR_NOTAVAILABLE != D3D::D3D->CheckDeviceMultiSampleType(
176 i, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_8_SAMPLES, &qlevels))
178 a.aa_levels.push_back(AALevel("8x MSAA", D3DMULTISAMPLE_8_SAMPLES, 0));
183 if (D3DERR_NOTAVAILABLE != D3D::D3D->CheckDeviceMultiSampleType(
184 i, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_4_SAMPLES, &qlevels))
188 // 8x, 8xQ are available
189 // See http://developer.nvidia.com/object/coverage-sampled-aa.html
190 a.aa_levels.push_back(AALevel("8x CSAA", D3DMULTISAMPLE_4_SAMPLES, 2));
191 a.aa_levels.push_back(AALevel("8xQ CSAA", D3DMULTISAMPLE_8_SAMPLES, 0));
194 if (D3DERR_NOTAVAILABLE != D3D::D3D->CheckDeviceMultiSampleType(
195 i, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_8_SAMPLES, &qlevels))
199 // 16x, 16xQ are available
200 // See http://developer.nvidia.com/object/coverage-sampled-aa.html
201 a.aa_levels.push_back(AALevel("16x CSAA", D3DMULTISAMPLE_4_SAMPLES, 4));
202 a.aa_levels.push_back(AALevel("16xQ CSAA", D3DMULTISAMPLE_8_SAMPLES, 2));
207 // Determine if INTZ is supported. Code from ATI's doc.
208 // http://developer.amd.com/gpu_assets/Advanced%20DX9%20Capabilities%20for%20ATI%20Radeon%20Cards.pdf
209 a
.supports_intz
= D3D_OK
== D3D
->CheckDeviceFormat(
210 i
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
211 D3DUSAGE_DEPTHSTENCIL
, D3DRTYPE_TEXTURE
, FOURCC_INTZ
);
212 // Also check for RAWZ (nvidia only, but the only option to get Z24 textures on sub GF8800
213 a
.supports_rawz
= D3D_OK
== D3D
->CheckDeviceFormat(
214 i
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
215 D3DUSAGE_DEPTHSTENCIL
, D3DRTYPE_TEXTURE
, FOURCC_RAWZ
);
216 // Might as well check for RESZ and NULL too.
217 a
.supports_resz
= D3D_OK
== D3D
->CheckDeviceFormat(
218 i
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
219 D3DUSAGE_DEPTHSTENCIL
, D3DRTYPE_TEXTURE
, FOURCC_RESZ
);
220 a
.supports_null
= D3D_OK
== D3D
->CheckDeviceFormat(
221 i
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
222 D3DUSAGE_DEPTHSTENCIL
, D3DRTYPE_TEXTURE
, FOURCC_NULL
);
224 if (a
.aa_levels
.size() == 1)
226 strcpy(a
.aa_levels
[0].name
, "(Not supported on this device)");
228 int numModes
= D3D::D3D
->GetAdapterModeCount(i
, D3DFMT_X8R8G8B8
);
229 for (int m
= 0; m
< numModes
; m
++)
232 D3D::D3D
->EnumAdapterModes(i
, D3DFMT_X8R8G8B8
, m
, &mode
);
235 for (int x
= 0; x
< (int)a
.resolutions
.size(); x
++)
237 if (a
.resolutions
[x
].xres
== mode
.Width
&& a
.resolutions
[x
].yres
== mode
.Height
)
245 Resolution
&r
= found
==-1 ? temp
: a
.resolutions
[found
];
247 sprintf(r
.name
, "%ix%i", mode
.Width
, mode
.Height
);
248 r
.bitdepths
.insert(mode
.Format
);
249 r
.refreshes
.insert(mode
.RefreshRate
);
250 if (found
== -1 && mode
.Width
>= 640 && mode
.Height
>= 480)
253 r
.yres
= mode
.Height
;
254 a
.resolutions
.push_back(r
);
260 // dynamically picks one of the available d3dx9 dlls and loads it.
261 // we're first trying to load the dll Dolphin was compiled with, otherwise the most up-to-date one
265 hD3DXDll
= LoadLibraryA(StringFromFormat("d3dx9_%d.dll", D3DX_SDK_VERSION
).c_str());
266 if (hD3DXDll
!= NULL
)
268 NOTICE_LOG(VIDEO
, "Successfully loaded %s.", StringFromFormat("d3dx9_%d.dll", D3DX_SDK_VERSION
).c_str());
273 // if that fails, try loading older dlls (no need to look for newer ones)
274 for (unsigned int num
= D3DX_SDK_VERSION
-1; num
>= 24; --num
)
276 hD3DXDll
= LoadLibraryA(StringFromFormat("d3dx9_%d.dll", num
).c_str());
277 if (hD3DXDll
!= NULL
)
279 NOTICE_LOG(VIDEO
, "Successfully loaded %s. If you're having trouble, try updating your DX runtime first.", StringFromFormat("d3dx9_%d.dll", num
).c_str());
286 MessageBoxA(NULL
, "Failed to load any D3DX9 dll, update your DX9 runtime, please", "Critical error", MB_OK
| MB_ICONERROR
);
290 PD3DXCompileShader
= (D3DXCOMPILESHADERTYPE
)GetProcAddress(hD3DXDll
, "D3DXCompileShader");
291 if (PD3DXCompileShader
== NULL
)
293 MessageBoxA(NULL
, "GetProcAddress failed for D3DXCompileShader!", "Critical error", MB_OK
| MB_ICONERROR
);
297 PD3DXSaveSurfaceToFileA
= (D3DXSAVESURFACETOFILEATYPE
)GetProcAddress(hD3DXDll
, "D3DXSaveSurfaceToFileA");
298 if (PD3DXSaveSurfaceToFileA
== NULL
)
300 MessageBoxA(NULL
, "GetProcAddress failed for D3DXSaveSurfaceToFileA!", "Critical error", MB_OK
| MB_ICONERROR
);
304 PD3DXSaveTextureToFileA
= (D3DXSAVETEXTURETOFILEATYPE
)GetProcAddress(hD3DXDll
, "D3DXSaveTextureToFileA");
305 if (PD3DXSaveTextureToFileA
== NULL
)
307 MessageBoxA(NULL
, "GetProcAddress failed for D3DXSaveTextureToFileA!", "Critical error", MB_OK
| MB_ICONERROR
);
313 FreeLibrary(hD3DXDll
);
314 PD3DXCompileShader
= NULL
;
315 PD3DXSaveSurfaceToFileA
= NULL
;
316 PD3DXSaveTextureToFileA
= NULL
;
322 FreeLibrary(hD3DXDll
);
323 PD3DXCompileShader
= NULL
;
324 PD3DXSaveSurfaceToFileA
= NULL
;
325 PD3DXSaveTextureToFileA
= NULL
;
328 HRESULT
Create(int adapter
, HWND wnd
, int _resolution
, int aa_mode
, bool auto_depth
)
331 multisample
= aa_mode
;
332 resolution
= _resolution
;
333 auto_depth_stencil
= auto_depth
;
334 cur_adapter
= adapter
;
335 D3DPRESENT_PARAMETERS d3dpp
;
337 HRESULT hr
= LoadD3DX9();
338 if (FAILED(hr
)) return hr
;
340 InitPP(adapter
, resolution
, aa_mode
, &d3dpp
);
342 if (FAILED(D3D
->CreateDevice(
346 D3DCREATE_HARDWARE_VERTEXPROCESSING
| D3DCREATE_PUREDEVICE
, //doesn't seem to make a difference
349 if (FAILED(D3D
->CreateDevice(
353 D3DCREATE_SOFTWARE_VERTEXPROCESSING
,
357 _T("Failed to initialize Direct3D."),
358 _T("Dolphin Direct3D plugin"), MB_OK
| MB_ICONERROR
);
363 dev
->GetDeviceCaps(&caps
);
364 dev
->GetRenderTarget(0, &back_buffer
);
365 if (dev
->GetDepthStencilSurface(&back_buffer_z
) == D3DERR_NOTFOUND
)
366 back_buffer_z
= NULL
;
367 D3D::SetRenderState(D3DRS_ZENABLE
, D3DZB_TRUE
);
368 D3D::SetRenderState(D3DRS_FILLMODE
, g_Config
.bWireFrame
? D3DFILL_WIREFRAME
: D3DFILL_SOLID
);
369 memset(m_Textures
, 0, sizeof(m_Textures
));
370 memset(m_TextureStageStatesSet
, 0, sizeof(m_TextureStageStatesSet
));
371 memset(m_RenderStatesSet
, 0, sizeof(m_RenderStatesSet
));
372 memset(m_SamplerStatesSet
, 0, sizeof(m_SamplerStatesSet
));
373 memset(m_TextureStageStatesChanged
, 0, sizeof(m_TextureStageStatesChanged
));
374 memset(m_RenderStatesChanged
, 0, sizeof(m_RenderStatesChanged
));
375 memset(m_SamplerStatesChanged
, 0, sizeof(m_SamplerStatesChanged
));
377 m_PixelShader
= NULL
;
378 m_VertexShader
= NULL
;
379 // Device state would normally be set here
388 back_buffer_z
->Release();
389 back_buffer_z
= NULL
;
391 back_buffer
->Release();
394 ULONG references
= dev
->Release();
396 ERROR_LOG(VIDEO
, "Unreleased references: %i.", references
);
401 const D3DCAPS9
&GetCaps()
406 const char *VertexShaderVersionString()
408 static const char *versions
[5] = {"ERROR", "vs_1_4", "vs_2_0", "vs_3_0", "vs_4_0"};
409 int version
= ((D3D::caps
.VertexShaderVersion
>> 8) & 0xFF);
410 return versions
[std::min(4, version
)];
413 const char *PixelShaderVersionString()
415 static const char *versions
[5] = {"ERROR", "ps_1_4", "ps_2_0", "ps_3_0", "ps_4_0"};
416 int version
= ((D3D::caps
.PixelShaderVersion
>> 8) & 0xFF);
417 return versions
[std::min(4, version
)];
420 LPDIRECT3DSURFACE9
GetBackBufferSurface()
425 LPDIRECT3DSURFACE9
GetBackBufferDepthSurface()
427 return back_buffer_z
;
430 void ShowD3DError(HRESULT err
)
434 case D3DERR_DEVICELOST
:
435 PanicAlert("Device Lost");
437 case D3DERR_INVALIDCALL
:
438 PanicAlert("Invalid Call");
440 case D3DERR_DRIVERINTERNALERROR
:
441 PanicAlert("Driver Internal Error");
443 case D3DERR_OUTOFVIDEOMEMORY
:
444 PanicAlert("Out of vid mem");
447 // MessageBox(0,_T("Other error or success"),_T("ERROR"),0);
456 // ForgetCachedState();
458 // Can't keep a pointer around to the backbuffer surface when resetting.
460 back_buffer_z
->Release();
461 back_buffer_z
= NULL
;
462 back_buffer
->Release();
465 D3DPRESENT_PARAMETERS d3dpp
;
466 InitPP(cur_adapter
, resolution
, multisample
, &d3dpp
);
467 HRESULT hr
= dev
->Reset(&d3dpp
);
470 dev
->GetRenderTarget(0, &back_buffer
);
471 if (dev
->GetDepthStencilSurface(&back_buffer_z
) == D3DERR_NOTFOUND
)
472 back_buffer_z
= NULL
;
477 int GetBackBufferWidth()
482 int GetBackBufferHeight()
489 if (bFrameInProgress
)
491 PanicAlert("BeginFrame WTF");
494 bFrameInProgress
= true;
506 if (!bFrameInProgress
)
508 PanicAlert("EndFrame WTF");
511 bFrameInProgress
= false;
519 dev
->Present(NULL
, NULL
, NULL
, NULL
);
523 void ApplyCachedState()
525 for (int sampler
= 0; sampler
< 8; sampler
++)
527 for (int type
= 0; type
< MaxSamplerTypes
; type
++)
529 if(m_SamplerStatesSet
[sampler
][type
])
530 D3D::dev
->SetSamplerState(sampler
, (D3DSAMPLERSTATETYPE
)type
, m_SamplerStates
[sampler
][type
]);
534 for (int rs
= 0; rs
< MaxRenderStates
; rs
++)
536 if (m_RenderStatesSet
[rs
])
537 D3D::dev
->SetRenderState((D3DRENDERSTATETYPE
)rs
, m_RenderStates
[rs
]);
540 // We don't bother restoring these so let's just wipe the state copy
541 // so no stale state is around.
542 memset(m_Textures
, 0, sizeof(m_Textures
));
543 memset(m_TextureStageStatesSet
, 0, sizeof(m_TextureStageStatesSet
));
544 memset(m_TextureStageStatesChanged
, 0, sizeof(m_TextureStageStatesChanged
));
546 m_PixelShader
= NULL
;
547 m_VertexShader
= NULL
;
550 void SetTexture(DWORD Stage
, LPDIRECT3DBASETEXTURE9 pTexture
)
552 if (m_Textures
[Stage
] != pTexture
)
554 m_Textures
[Stage
] = pTexture
;
555 D3D::dev
->SetTexture(Stage
, pTexture
);
559 void RefreshRenderState(D3DRENDERSTATETYPE State
)
561 if(m_RenderStatesSet
[State
] && m_RenderStatesChanged
[State
])
563 D3D::dev
->SetRenderState(State
, m_RenderStates
[State
]);
564 m_RenderStatesChanged
[State
] = false;
568 void SetRenderState(D3DRENDERSTATETYPE State
, DWORD Value
)
570 if (m_RenderStates
[State
] != Value
|| !m_RenderStatesSet
[State
])
572 m_RenderStates
[State
] = Value
;
573 m_RenderStatesSet
[State
] = true;
574 m_RenderStatesChanged
[State
] = false;
575 D3D::dev
->SetRenderState(State
, Value
);
579 void ChangeRenderState(D3DRENDERSTATETYPE State
, DWORD Value
)
581 if (m_RenderStates
[State
] != Value
|| !m_RenderStatesSet
[State
])
583 m_RenderStatesChanged
[State
] = m_RenderStatesSet
[State
];
584 D3D::dev
->SetRenderState(State
, Value
);
588 m_RenderStatesChanged
[State
] = false;
592 void SetTextureStageState(DWORD Stage
, D3DTEXTURESTAGESTATETYPE Type
, DWORD Value
)
594 if (m_TextureStageStates
[Stage
][Type
] != Value
|| !m_TextureStageStatesSet
[Stage
][Type
])
596 m_TextureStageStates
[Stage
][Type
] = Value
;
597 m_TextureStageStatesSet
[Stage
][Type
]=true;
598 m_TextureStageStatesChanged
[Stage
][Type
]=false;
599 D3D::dev
->SetTextureStageState(Stage
, Type
, Value
);
603 void RefreshTextureStageState(DWORD Stage
, D3DTEXTURESTAGESTATETYPE Type
)
605 if(m_TextureStageStatesSet
[Stage
][Type
] && m_TextureStageStatesChanged
[Stage
][Type
])
607 D3D::dev
->SetTextureStageState(Stage
, Type
, m_TextureStageStates
[Stage
][Type
]);
608 m_TextureStageStatesChanged
[Stage
][Type
] = false;
612 void ChangeTextureStageState(DWORD Stage
, D3DTEXTURESTAGESTATETYPE Type
, DWORD Value
)
614 if (m_TextureStageStates
[Stage
][Type
] != Value
|| !m_TextureStageStatesSet
[Stage
][Type
])
616 m_TextureStageStatesChanged
[Stage
][Type
] = m_TextureStageStatesSet
[Stage
][Type
];
617 D3D::dev
->SetTextureStageState(Stage
, Type
, Value
);
621 m_TextureStageStatesChanged
[Stage
][Type
] = false;
625 void SetSamplerState(DWORD Sampler
, D3DSAMPLERSTATETYPE Type
, DWORD Value
)
627 if (m_SamplerStates
[Sampler
][Type
] != Value
|| !m_SamplerStatesSet
[Sampler
][Type
])
629 m_SamplerStates
[Sampler
][Type
] = Value
;
630 m_SamplerStatesSet
[Sampler
][Type
] = true;
631 m_SamplerStatesChanged
[Sampler
][Type
] = false;
632 D3D::dev
->SetSamplerState(Sampler
, Type
, Value
);
636 void RefreshSamplerState(DWORD Sampler
, D3DSAMPLERSTATETYPE Type
)
638 if(m_SamplerStatesSet
[Sampler
][Type
] && m_SamplerStatesChanged
[Sampler
][Type
])
640 D3D::dev
->SetSamplerState(Sampler
, Type
, m_SamplerStates
[Sampler
][Type
]);
641 m_SamplerStatesChanged
[Sampler
][Type
] = false;
645 void ChangeSamplerState(DWORD Sampler
, D3DSAMPLERSTATETYPE Type
, DWORD Value
)
647 if (m_SamplerStates
[Sampler
][Type
] != Value
|| !m_SamplerStatesSet
[Sampler
][Type
])
649 m_SamplerStatesChanged
[Sampler
][Type
] = m_SamplerStatesSet
[Sampler
][Type
];
650 D3D::dev
->SetSamplerState(Sampler
, Type
, Value
);
654 m_SamplerStatesChanged
[Sampler
][Type
] = false;
658 void RefreshVertexDeclaration()
662 D3D::dev
->SetVertexDeclaration(m_VtxDecl
);
666 void SetVertexDeclaration(LPDIRECT3DVERTEXDECLARATION9 decl
)
672 if (decl
!= m_VtxDecl
)
674 D3D::dev
->SetVertexDeclaration(decl
);
679 void RefreshVertexShader()
683 D3D::dev
->SetVertexShader(m_VertexShader
);
687 void SetVertexShader(LPDIRECT3DVERTEXSHADER9 shader
)
690 m_VertexShader
= NULL
;
693 if (shader
!= m_VertexShader
)
695 D3D::dev
->SetVertexShader(shader
);
696 m_VertexShader
= shader
;
700 void RefreshPixelShader()
704 D3D::dev
->SetPixelShader(m_PixelShader
);
708 void SetPixelShader(LPDIRECT3DPIXELSHADER9 shader
)
711 m_PixelShader
= NULL
;
714 if (shader
!= m_PixelShader
)
716 D3D::dev
->SetPixelShader(shader
);
717 m_PixelShader
= shader
;