Mercurial > mm7
comparison Engine/Graphics/RenderD3D11.cpp @ 2496:5abd8fc8f1c6
for ITEM_ARTIFACT_LADYS_ESCORT
author | Ritor1 |
---|---|
date | Thu, 18 Sep 2014 17:38:54 +0600 |
parents | |
children | 68cdef6879a0 |
comparison
equal
deleted
inserted
replaced
2495:7b076fe64f23 | 2496:5abd8fc8f1c6 |
---|---|
1 #include <d3dcompiler.h> | |
2 #include <comdef.h> // _com_error | |
3 | |
4 #include "ErrorHandling.h" | |
5 #include "RenderD3D11.h" | |
6 #include "mm7_data.h" | |
7 | |
8 #define ErrorD3D(x)\ | |
9 {\ | |
10 HRESULT hr = x;\ | |
11 if (FAILED(hr))\ | |
12 {\ | |
13 _com_error com_error(hr);\ | |
14 Error("HRESULT = %08X\n%S", hr, com_error.ErrorMessage());\ | |
15 }\ | |
16 } | |
17 | |
18 | |
19 RenderD3D11::RenderD3D11() {} | |
20 RenderD3D11::~RenderD3D11() {} | |
21 | |
22 | |
23 void RenderD3D11::ClearBlack() {__debugbreak();} | |
24 void RenderD3D11::SaveWinnersCertificate(const char *a1) {__debugbreak();} | |
25 void RenderD3D11::Present() {__debugbreak();} | |
26 void RenderD3D11::_49FD3A_fullscreen() {__debugbreak();} | |
27 bool RenderD3D11::InitializeFullscreen() {__debugbreak(); return 0;} | |
28 void RenderD3D11::CreateZBuffer() {__debugbreak();} | |
29 void RenderD3D11::Release() {__debugbreak();} | |
30 void RenderD3D11::RasterLine2D(signed int uX, signed int uY, signed int uZ, signed int uW, unsigned __int16 uColor) {__debugbreak();} | |
31 void RenderD3D11::ClearZBuffer(int a2, int a3) {__debugbreak();} | |
32 void RenderD3D11::SetRasterClipRect(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW) {__debugbreak();} | |
33 bool RenderD3D11::LockSurface_DDraw4(IDirectDrawSurface4 *pSurface, DDSURFACEDESC2 *pDesc, unsigned int uLockFlags) {__debugbreak(); return 0;} | |
34 void RenderD3D11::GetTargetPixelFormat(DDPIXELFORMAT *pOut) {__debugbreak();} | |
35 void RenderD3D11::LockRenderSurface(void **pOutSurfacePtr, unsigned int *pOutPixelsPerRow) {__debugbreak();} | |
36 void RenderD3D11::UnlockBackBuffer() {__debugbreak();} | |
37 void RenderD3D11::LockFrontBuffer(void **pOutSurface, unsigned int *pOutPixelsPerRow) {__debugbreak();} | |
38 void RenderD3D11::UnlockFrontBuffer() {__debugbreak();} | |
39 void RenderD3D11::RestoreFrontBuffer() {__debugbreak();} | |
40 void RenderD3D11::RestoreBackBuffer() {__debugbreak();} | |
41 void RenderD3D11::BltToFront(RECT *pDstRect, IDirectDrawSurface *pSrcSurface, RECT *pSrcRect, unsigned int uBltFlags) {__debugbreak();} | |
42 void RenderD3D11::BltBackToFontFast(int a2, int a3, RECT *a4) {__debugbreak();} | |
43 void RenderD3D11::BeginSceneD3D() {__debugbreak();} | |
44 unsigned int RenderD3D11::GetActorTintColor(float a2, int tint, int a4, int a5, RenderBillboard *a6) {__debugbreak(); return 0;} | |
45 void RenderD3D11::DrawPolygon(unsigned int uNumVertices, struct Polygon *a3, ODMFace *a4, IDirect3DTexture2 *pTexture) {__debugbreak();} | |
46 void RenderD3D11::DrawTerrainPolygon(unsigned int uNumVertices, struct Polygon *a4, IDirect3DTexture2 *a5, bool transparent, bool clampAtTextureBorders) {__debugbreak();} | |
47 void RenderD3D11::DrawIndoorPolygon(unsigned int uNumVertices, struct BLVFace *a3, IDirect3DTexture2 *pHwTex, struct Texture *pTex, int uPackedID, unsigned int uColor, int a8) {__debugbreak();} | |
48 void RenderD3D11::MakeParticleBillboardAndPush_BLV(RenderBillboardTransform_local0 *a2, IDirect3DTexture2 *a3, unsigned int uDiffuse, int angle) {__debugbreak();} | |
49 void RenderD3D11::MakeParticleBillboardAndPush_ODM(RenderBillboardTransform_local0 *a2, IDirect3DTexture2 *a3, unsigned int uDiffuse, int angle) {__debugbreak();} | |
50 void RenderD3D11::DrawBillboards_And_MaybeRenderSpecialEffects_And_EndScene() {__debugbreak();} | |
51 void RenderD3D11::DrawBillboard_Indoor(RenderBillboardTransform_local0 *pSoftBillboard, Sprite *pSprite, int dimming_level) {__debugbreak();} | |
52 void RenderD3D11::_4A4CC9_AddSomeBillboard(struct stru6_stru1_indoor_sw_billboard *a1, int diffuse) {__debugbreak();} | |
53 void RenderD3D11::TransformBillboardsAndSetPalettesODM() {__debugbreak();} | |
54 void RenderD3D11::DrawBillboardList_BLV() {__debugbreak();} | |
55 void RenderD3D11::DrawProjectile(float srcX, float srcY, float a3, float a4, float dstX, float dstY, float a7, float a8, IDirect3DTexture2 *a9) {__debugbreak();} | |
56 bool RenderD3D11::LoadTexture(const char *pName, unsigned int bMipMaps, IDirectDrawSurface4 **pOutSurface, IDirect3DTexture2 **pOutTexture) {__debugbreak(); return 0;} | |
57 bool RenderD3D11::MoveSpriteToDevice(Sprite *pSprite) {__debugbreak(); return 0;} | |
58 void RenderD3D11::ScreenFade(unsigned int color, float t) {__debugbreak();} | |
59 void RenderD3D11::SetTextureClipRect(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW) {__debugbreak();} | |
60 void RenderD3D11::ResetTextureClipRect() {__debugbreak();} | |
61 void RenderD3D11::CreditsTextureScroll(unsigned int pX, unsigned int pY, int move_X, int move_Y, RGBTexture *pTexture) {__debugbreak();} | |
62 void RenderD3D11::DrawTextureIndexed(unsigned int uX, unsigned int uY, struct Texture *a4) {__debugbreak();} | |
63 void RenderD3D11::ZBuffer_Fill_2(signed int a2, signed int a3, struct Texture *pTexture, int a5) {__debugbreak();} | |
64 void RenderD3D11::DrawMaskToZBuffer(signed int uOutX, unsigned int uOutY, struct Texture *pTexture, int zVal) {__debugbreak();} | |
65 void RenderD3D11::DrawTextureTransparent(unsigned int uX, unsigned int uY, struct Texture *pTexture) {__debugbreak();} | |
66 void RenderD3D11::DrawAura(unsigned int a2, unsigned int a3, struct Texture *a4, struct Texture *a5, int a6, int a7, int a8) {__debugbreak();} | |
67 void RenderD3D11::_4A65CC(unsigned int x, unsigned int y, struct Texture *a4, struct Texture *a5, int a6, int a7, int a8) {__debugbreak();} | |
68 void RenderD3D11::DrawTransparentRedShade(unsigned int a2, unsigned int a3, struct Texture *a4) {__debugbreak();} | |
69 void RenderD3D11::DrawTransparentGreenShade(signed int a2, signed int a3, struct Texture *pTexture) {__debugbreak();} | |
70 void RenderD3D11::DrawFansTransparent(const RenderVertexD3D3 *vertices, unsigned int num_vertices) {__debugbreak();} | |
71 void RenderD3D11::DrawMasked(signed int a2, signed int a3, struct Texture *pTexture, unsigned __int16 mask) {__debugbreak();} | |
72 void RenderD3D11::GetLeather(unsigned int a2, unsigned int a3, struct Texture *a4, __int16 height) {__debugbreak();} | |
73 void RenderD3D11::DrawTextPalette(int x, int y, unsigned char* font_pixels, int a5, unsigned int uFontHeight, unsigned __int16 *pPalette, int a8) {__debugbreak();} | |
74 void RenderD3D11::DrawText(signed int uOutX, signed int uOutY, unsigned __int8 *pFontPixels, unsigned int uCharWidth, unsigned int uCharHeight, unsigned __int16 *pFontPalette, unsigned __int16 uFaceColor, unsigned __int16 uShadowColor) {__debugbreak();} | |
75 void RenderD3D11::FillRectFast(unsigned int uX, unsigned int uY, unsigned int uWidth, unsigned int uHeight, unsigned int uColor16) {__debugbreak();} | |
76 void RenderD3D11::_4A6DF5(unsigned __int16 *pBitmap, unsigned int uBitmapPitch, struct Vec2_int_ *pBitmapXY, void *pTarget, unsigned int uTargetPitch, Vec4_int_ *a7) {__debugbreak();} | |
77 void RenderD3D11::DrawTranslucent(unsigned int a2, unsigned int a3, struct Texture *a4) {__debugbreak();} | |
78 void RenderD3D11::DrawBuildingsD3D() {__debugbreak();} | |
79 void RenderD3D11::DrawIndoorSky(unsigned int uNumVertices, unsigned int uFaceID) {__debugbreak();} | |
80 void RenderD3D11::DrawOutdoorSkyD3D() {__debugbreak();} | |
81 void RenderD3D11::DrawOutdoorSkyPolygon(unsigned int uNumVertices, struct Polygon *pSkyPolygon, IDirect3DTexture2 *pTexture) {__debugbreak();} | |
82 void RenderD3D11::DrawIndoorSkyPolygon(signed int uNumVertices, struct Polygon *pSkyPolygon, IDirect3DTexture2 *pTexture) {__debugbreak();} | |
83 void RenderD3D11::PrepareDecorationsRenderList_ODM() {__debugbreak();} | |
84 void RenderD3D11::DrawSpriteObjects_ODM() {__debugbreak();} | |
85 void RenderD3D11::RenderTerrainD3D() {__debugbreak();} | |
86 void RenderD3D11::ChangeBetweenWinFullscreenModes() {__debugbreak();} | |
87 bool RenderD3D11::AreRenderSurfacesOk() {__debugbreak(); return 0;} | |
88 void RenderD3D11::SaveScreenshot(const char *pFilename, unsigned int width, unsigned int height) {__debugbreak();} | |
89 void RenderD3D11::PackScreenshot(unsigned int width, unsigned int height, void *out_data, unsigned int data_size, unsigned int *screenshot_size) {__debugbreak();} | |
90 void RenderD3D11::SavePCXScreenshot() {__debugbreak();} | |
91 int RenderD3D11::_46À6ÀÑ_GetActorsInViewport(int pDepth) {__debugbreak(); return 0;} | |
92 void RenderD3D11::BeginLightmaps() {__debugbreak();} | |
93 void RenderD3D11::EndLightmaps() {__debugbreak();} | |
94 void RenderD3D11::BeginLightmaps2() {__debugbreak();} | |
95 void RenderD3D11::EndLightmaps2() {__debugbreak();} | |
96 bool RenderD3D11::DrawLightmap(struct Lightmap *pLightmap, struct Vec3_float_ *pColorMult, float z_bias) {__debugbreak(); return 0;} | |
97 void RenderD3D11::BeginDecals() {__debugbreak();} | |
98 void RenderD3D11::EndDecals() {__debugbreak();} | |
99 void RenderD3D11::DrawDecal(struct Decal *pDecal, float z_bias) {__debugbreak();} | |
100 void RenderD3D11::do_draw_debug_line_d3d(const RenderVertexD3D3 *pLineBegin, signed int sDiffuseBegin, const RenderVertexD3D3 *pLineEnd, signed int sDiffuseEnd, float z_stuff) {__debugbreak();} | |
101 void RenderD3D11::DrawLines(const RenderVertexD3D3 *vertices, unsigned int num_vertices) {__debugbreak();} | |
102 void RenderD3D11::DrawSpecialEffectsQuad(const RenderVertexD3D3 *vertices, IDirect3DTexture2 *texture) {__debugbreak();} | |
103 void RenderD3D11::am_Blt_Copy(RECT *pSrcRect, POINT *pTargetXY, int a3) {__debugbreak();} | |
104 void RenderD3D11::am_Blt_Chroma(RECT *pSrcRect, POINT *pTargetPoint, int a3, int blend_mode) {__debugbreak();} | |
105 | |
106 void RenderD3D11::Sub01() {__debugbreak();} | |
107 | |
108 | |
109 | |
110 | |
111 | |
112 void RenderD3D11::PresentBlackScreen() | |
113 { | |
114 ClearTarget(0xFF000000); | |
115 ErrorD3D(pSwapChain->Present(0, 0)); | |
116 } | |
117 | |
118 void RenderD3D11::BeginScene() {} | |
119 void RenderD3D11::EndScene() {} | |
120 | |
121 void RenderD3D11::ClearTarget(unsigned int uColor) | |
122 { | |
123 float clear_color[] = | |
124 { | |
125 ((uColor & 0x00FF0000) >> 16) / 255.0f, | |
126 ((uColor & 0x0000FF00) >> 8) / 255.0f, | |
127 ((uColor & 0x000000FF) >> 0) / 255.0f, | |
128 ((uColor & 0xFF000000) >> 24) / 255.0f | |
129 }; | |
130 d3dc->ClearRenderTargetView(primary_srv, clear_color); | |
131 } | |
132 | |
133 | |
134 void RenderD3D11::DrawTextureRGB(unsigned int uOutX, unsigned int uOutY, RGBTexture *a4) | |
135 { | |
136 __debugbreak(); | |
137 } | |
138 | |
139 bool RenderD3D11::IsGammaSupported() | |
140 { | |
141 return false; | |
142 } | |
143 | |
144 struct | |
145 { | |
146 unsigned char restore_resolution; | |
147 unsigned char _saved_screen_bpp; | |
148 unsigned short _saved_screen_width; | |
149 unsigned short _saved_screen_height; | |
150 } on_exit; | |
151 | |
152 void ChangeResolution(int new_width, int new_height, int new_bpp) | |
153 { | |
154 if (!on_exit.restore_resolution) | |
155 { | |
156 on_exit.restore_resolution = true; | |
157 | |
158 auto hdc = GetDC(nullptr); | |
159 { | |
160 on_exit._saved_screen_width = GetDeviceCaps(hdc, HORZRES); | |
161 on_exit._saved_screen_height = GetDeviceCaps(hdc, VERTRES); | |
162 on_exit._saved_screen_bpp = GetDeviceCaps(hdc, BITSPIXEL); | |
163 } | |
164 ReleaseDC(nullptr, hdc); | |
165 } | |
166 | |
167 DEVMODEA dm; | |
168 dm.dmSize = sizeof(dm); | |
169 dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; | |
170 dm.dmBitsPerPel = new_bpp; | |
171 dm.dmPelsWidth = new_width; | |
172 dm.dmPelsHeight = new_height; | |
173 | |
174 if (ChangeDisplaySettingsA(&dm, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) | |
175 Error("ChangeDisplaySettingsA"); | |
176 } | |
177 | |
178 __declspec(noreturn) void ExitApp() | |
179 { | |
180 if (on_exit.restore_resolution) | |
181 ChangeResolution(on_exit._saved_screen_width, on_exit._saved_screen_height, on_exit._saved_screen_bpp); | |
182 | |
183 ExitProcess(0); | |
184 } | |
185 | |
186 | |
187 | |
188 bool RenderD3D11::SwitchToWindow() | |
189 { | |
190 if (on_exit.restore_resolution) | |
191 { | |
192 on_exit.restore_resolution = false; | |
193 ChangeResolution(on_exit._saved_screen_width, on_exit._saved_screen_height, on_exit._saved_screen_bpp); | |
194 } | |
195 return true; | |
196 } | |
197 | |
198 | |
199 | |
200 | |
201 bool RenderD3D11::Initialize(OSWindow *window) | |
202 { | |
203 this->window = window; | |
204 | |
205 auto d3d_lib = LoadLibraryW(L"d3d11.dll"); | |
206 if (!d3d_lib) | |
207 return Error("d3d11.dll is missing"), false; | |
208 | |
209 | |
210 DXGI_SWAP_CHAIN_DESC swapChainDesc; | |
211 memset(&swapChainDesc, 0, sizeof(swapChainDesc)); | |
212 swapChainDesc.BufferDesc.Width = window->GetWidth(); | |
213 swapChainDesc.BufferDesc.Height = window->GetHeight(); | |
214 //swapChainDesc.BufferDesc.RefreshRate.Numerator = 0; | |
215 //swapChainDesc.BufferDesc.RefreshRate.Denominator = 0; | |
216 swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; | |
217 //swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; | |
218 //swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; | |
219 swapChainDesc.SampleDesc.Count = 1; | |
220 //swapChainDesc.SampleDesc.Quality = 0; | |
221 swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; | |
222 swapChainDesc.BufferCount = 2; | |
223 swapChainDesc.OutputWindow = window->GetApiHandle(); | |
224 swapChainDesc.Windowed = true; | |
225 //swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; | |
226 //swapChainDesc.Flags = 0; | |
227 | |
228 | |
229 D3D_FEATURE_LEVEL requested_feature_level = D3D_FEATURE_LEVEL_11_0, | |
230 received_feature_level; | |
231 | |
232 unsigned int device_flags = 0;//D3D11_CREATE_DEVICE_DISABLE_GPU_TIMEOUT; | |
233 #ifndef NODEBUG | |
234 device_flags |= 0/*D3D11_CREATE_DEVICE_DEBUG | D3D11_CREATE_DEVICE_DEBUGGABLE*/; | |
235 #endif | |
236 | |
237 HRESULT (__stdcall *dll_D3D11CreateDeviceAndSwapChain)(IDXGIAdapter* pAdapter, D3D_DRIVER_TYPE DriverType, HMODULE Software, UINT Flags, CONST D3D_FEATURE_LEVEL* pFeatureLevels, UINT FeatureLevels, UINT SDKVersion, CONST DXGI_SWAP_CHAIN_DESC* pSwapChainDesc, IDXGISwapChain** ppSwapChain, ID3D11Device** ppDevice, D3D_FEATURE_LEVEL* pFeatureLevel, ID3D11DeviceContext** ppImmediateContext); | |
238 dll_D3D11CreateDeviceAndSwapChain = (decltype(dll_D3D11CreateDeviceAndSwapChain))GetProcAddress(d3d_lib, "D3D11CreateDeviceAndSwapChain"); | |
239 ErrorD3D(dll_D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, device_flags, nullptr, 0, D3D11_SDK_VERSION, &swapChainDesc, &pSwapChain, &d3dd, &received_feature_level, &d3dc)); | |
240 | |
241 if (received_feature_level < D3D_FEATURE_LEVEL_10_0) | |
242 { | |
243 MessageBoxA(nullptr, "Received Direct3D 9 or lower", "", 0); | |
244 __debugbreak(); | |
245 } | |
246 /*if (fullscreen) | |
247 { | |
248 extern void ChangeResolution(int new_dith, int new_height, int new_bpp); | |
249 ChangeResolution(target_window->GetWidth(), target_window->GetHeight(), 32); | |
250 | |
251 target_window->SetPosition(0, 0); | |
252 target_window->SetTopmost(true); | |
253 } | |
254 ErrorD3D(pSwapChain->SetFullscreenState(fullscreen, nullptr));*/ | |
255 | |
256 | |
257 ID3D11Texture2D *pSwapChainSurface; | |
258 { | |
259 ErrorD3D(pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void **)&pSwapChainSurface)); | |
260 ErrorD3D(d3dd->CreateRenderTargetView(pSwapChainSurface, nullptr, &primary_srv)); | |
261 } | |
262 pSwapChainSurface->Release(); | |
263 | |
264 | |
265 D3D11_TEXTURE2D_DESC z_desc; | |
266 memset(&z_desc, 0, sizeof(z_desc)); | |
267 z_desc.Width = window->GetWidth(); | |
268 z_desc.Height = window->GetHeight(); | |
269 z_desc.MipLevels = 1; | |
270 z_desc.ArraySize = 1; | |
271 z_desc.Format = DXGI_FORMAT_D32_FLOAT; | |
272 z_desc.SampleDesc.Count = 1; | |
273 //z_desc.SampleDesc.Quality = 0; | |
274 //z_desc.Usage = D3D11_USAGE_DEFAULT; | |
275 z_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL; | |
276 //z_desc.CPUAccessFlags = 0; | |
277 //z_desc.MiscFlags = 0; | |
278 | |
279 ID3D11Texture2D *depth_surface; | |
280 ErrorD3D(d3dd->CreateTexture2D(&z_desc, nullptr, &depth_surface)); | |
281 | |
282 D3D11_DEPTH_STENCIL_VIEW_DESC depth_srv_desc; | |
283 memset(&depth_srv_desc, 0, sizeof(depth_srv_desc)); | |
284 depth_srv_desc.Format = DXGI_FORMAT_D32_FLOAT; | |
285 depth_srv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; | |
286 //depth_srv_desc.Texture2D.MipSlice = 0; | |
287 ErrorD3D(d3dd->CreateDepthStencilView(depth_surface, &depth_srv_desc, &depth_srv)); | |
288 | |
289 d3dc->OMSetRenderTargets(1, &primary_srv, depth_srv); | |
290 d3dc->ClearDepthStencilView(depth_srv, D3D11_CLEAR_DEPTH, 1.0f, 0); | |
291 | |
292 | |
293 | |
294 D3D11_RASTERIZER_DESC d3drs_desc; | |
295 memset(&d3drs_desc, 0, sizeof(d3drs_desc)); | |
296 d3drs_desc.FillMode = D3D11_FILL_SOLID; | |
297 d3drs_desc.CullMode = D3D11_CULL_NONE; | |
298 //d3drs_desc.FrontCounterClockwise = false; | |
299 //d3drs_desc.DepthBias = 0; | |
300 //d3drs_desc.DepthBiasClamp = 0.0f; | |
301 //d3drs_desc.SlopeScaledDepthBias = 0.0f; | |
302 //d3drs_desc.DepthClipEnable = true; | |
303 //d3drs_desc.ScissorEnable = false; | |
304 //d3drs_desc.MultisampleEnable = false; | |
305 //d3drs_desc.AntialiasedLineEnable = false; | |
306 | |
307 ID3D11RasterizerState *d3drs; | |
308 ErrorD3D(d3dd->CreateRasterizerState(&d3drs_desc, &d3drs)); | |
309 d3dc->RSSetState(d3drs); | |
310 d3drs->Release(); | |
311 | |
312 | |
313 | |
314 D3D11_VIEWPORT viewport; | |
315 memset(&viewport, 0, sizeof(viewport)); | |
316 viewport.TopLeftX = game_viewport_x; | |
317 viewport.TopLeftY = game_viewport_y; | |
318 viewport.Width = game_viewport_width; | |
319 viewport.Height = game_viewport_height; | |
320 //viewport.MinDepth = 0; | |
321 viewport.MaxDepth = 1; | |
322 d3dc->RSSetViewports(1, &viewport); | |
323 | |
324 return true; | |
325 } |