2416
|
1 /*#define _CRTDBG_MAP_ALLOC
|
2415
|
2 #include <stdlib.h>
|
|
3 #include <crtdbg.h>
|
|
4
|
2410
|
5 #define _CRT_SECURE_NO_WARNINGS
|
2402
|
6 #define WIN32_LEAN_AND_MEAN
|
|
7
|
|
8 #include "DirectX11.h"
|
2410
|
9 #include "RenderStruct.h"
|
2402
|
10
|
|
11 HRESULT D3D11::InitDevice()
|
|
12 {
|
|
13 HRESULT hr = S_OK;
|
|
14 RECT rc;
|
|
15 GetClientRect( g_hWnd, &rc );
|
|
16 UINT width = rc.right - rc.left; //
|
|
17 UINT height = rc.bottom - rc.top; //
|
|
18 UINT createDeviceFlags = 0;
|
|
19 D3D_DRIVER_TYPE driverTypes[] =
|
|
20 {
|
|
21 D3D_DRIVER_TYPE_HARDWARE,
|
|
22 D3D_DRIVER_TYPE_WARP,
|
|
23 D3D_DRIVER_TYPE_REFERENCE,
|
|
24 };
|
|
25 UINT numDriverTypes = ARRAYSIZE( driverTypes );
|
|
26
|
|
27 // DirectX
|
|
28 D3D_FEATURE_LEVEL featureLevels[] =
|
|
29 {
|
|
30 D3D_FEATURE_LEVEL_11_0,
|
|
31 D3D_FEATURE_LEVEL_10_1,
|
|
32 D3D_FEATURE_LEVEL_10_0,
|
|
33 };
|
|
34 UINT numFeatureLevels = ARRAYSIZE( featureLevels );
|
|
35
|
|
36 // DirectX. ,
|
|
37 // .
|
|
38 DXGI_SWAP_CHAIN_DESC sd; // , (Swap Chain)
|
|
39 ZeroMemory( &sd, sizeof( sd ) ); //
|
|
40 sd.BufferCount = 1; //
|
|
41 sd.BufferDesc.Width = width; //
|
|
42 sd.BufferDesc.Height = height; //
|
|
43 sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; //
|
|
44 sd.BufferDesc.RefreshRate.Numerator = 75; //
|
|
45 sd.BufferDesc.RefreshRate.Denominator = 1;
|
|
46 sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; // -
|
|
47 sd.OutputWindow = g_hWnd; //
|
|
48 sd.SampleDesc.Count = 1;
|
|
49 sd.SampleDesc.Quality = 0;
|
|
50 sd.Windowed = TRUE; //
|
|
51
|
|
52 for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ )
|
|
53 {
|
|
54 g_driverType = driverTypes[driverTypeIndex];
|
|
55 hr = D3D11CreateDeviceAndSwapChain ( NULL, g_driverType, NULL, createDeviceFlags, featureLevels, numFeatureLevels, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext );
|
|
56 if (SUCCEEDED(hr)) // ,
|
|
57 break;
|
|
58 }
|
|
59 if (FAILED(hr)) return hr;
|
|
60
|
|
61 // . , SDK
|
|
62 // RenderTargetOutput - , RenderTargetView - .
|
2410
|
63 pBackBuffer = NULL;
|
2402
|
64 hr = g_pSwapChain->GetBuffer( 0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer );
|
|
65 if (FAILED(hr)) return hr;
|
|
66
|
|
67 // g_pd3dDevice
|
|
68 hr = g_pd3dDevice->CreateRenderTargetView( pBackBuffer, NULL, &g_pRenderTargetView );
|
|
69 pBackBuffer->Release();
|
|
70 if (FAILED(hr)) return hr;
|
|
71
|
|
72 //
|
|
73 g_pImmediateContext->OMSetRenderTargets( 1, &g_pRenderTargetView, NULL );
|
|
74
|
|
75 //
|
|
76 D3D11_VIEWPORT vp;
|
|
77 vp.Width = (FLOAT)width;
|
|
78 vp.Height = (FLOAT)height;
|
|
79 vp.MinDepth = 0.0f;
|
|
80 vp.MaxDepth = 1.0f;
|
|
81 vp.TopLeftX = 0;
|
|
82 vp.TopLeftY = 0;
|
|
83
|
|
84 //
|
|
85 g_pImmediateContext->RSSetViewports (1, &vp);
|
|
86
|
|
87 return S_OK;
|
|
88 }
|
|
89
|
|
90 //--------------------------------------------------------------------------------------
|
|
91 //
|
|
92 //--------------------------------------------------------------------------------------
|
|
93 void D3D11::CleanupDevice()
|
|
94 {
|
|
95 // , .
|
|
96 if( g_pImmediateContext ) g_pImmediateContext->ClearState();
|
|
97
|
|
98 // , , .
|
|
99 if( g_pRenderTargetView ) g_pRenderTargetView->Release();
|
|
100
|
|
101 if( g_pSwapChain ) g_pSwapChain->Release();
|
|
102
|
|
103 if( g_pImmediateContext ) g_pImmediateContext->Release();
|
|
104
|
|
105 if( g_pd3dDevice ) g_pd3dDevice->Release();
|
|
106 }
|
|
107
|
|
108 void Render()
|
|
109 {
|
|
110
|
2416
|
111 }*/ |