annotate DirectX11.cpp @ 2459:e5c88c2b02ab

Audio_GetFirstHardwareDigitalDriver
author Ritor1
date Wed, 30 Jul 2014 11:19:53 +0600
parents 8b04ba723324
children
rev   line source
2416
8b04ba723324 misstake in LoadSound
Ritor1
parents: 2415
diff changeset
1 /*#define _CRTDBG_MAP_ALLOC
2415
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2410
diff changeset
2 #include <stdlib.h>
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2410
diff changeset
3 #include <crtdbg.h>
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2410
diff changeset
4
2410
2d3c3d1dff0c added RenderStruct.h
Ritor1
parents: 2402
diff changeset
5 #define _CRT_SECURE_NO_WARNINGS
2402
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
6 #define WIN32_LEAN_AND_MEAN
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
7
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
8 #include "DirectX11.h"
2410
2d3c3d1dff0c added RenderStruct.h
Ritor1
parents: 2402
diff changeset
9 #include "RenderStruct.h"
2402
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
10
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
11 HRESULT D3D11::InitDevice()
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
12 {
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
13 HRESULT hr = S_OK;
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
14 RECT rc;
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
15 GetClientRect( g_hWnd, &rc );
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
16 UINT width = rc.right - rc.left; // получаем ширину
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
17 UINT height = rc.bottom - rc.top; // и высоту окна
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
18 UINT createDeviceFlags = 0;
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
19 D3D_DRIVER_TYPE driverTypes[] =
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
20 {
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
21 D3D_DRIVER_TYPE_HARDWARE,
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
22 D3D_DRIVER_TYPE_WARP,
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
23 D3D_DRIVER_TYPE_REFERENCE,
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
24 };
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
25 UINT numDriverTypes = ARRAYSIZE( driverTypes );
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
26
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
27 // Тут мы создаем список поддерживаемых версий DirectX
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
28 D3D_FEATURE_LEVEL featureLevels[] =
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
29 {
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
30 D3D_FEATURE_LEVEL_11_0,
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
31 D3D_FEATURE_LEVEL_10_1,
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
32 D3D_FEATURE_LEVEL_10_0,
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
33 };
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
34 UINT numFeatureLevels = ARRAYSIZE( featureLevels );
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
35
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
36 // Сейчас мы создадим устройства DirectX. Для начала заполним структуру,
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
37 // которая описывает свойства переднего буфера и привязывает его к нашему окну.
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
38 DXGI_SWAP_CHAIN_DESC sd; // Структура, описывающая цепь связи (Swap Chain)
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
39 ZeroMemory( &sd, sizeof( sd ) ); // очищаем ее
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
40 sd.BufferCount = 1; // у нас один задний буфер
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
41 sd.BufferDesc.Width = width; // ширина буфера
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
42 sd.BufferDesc.Height = height; // высота буфера
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
43 sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // формат пикселя в буфере
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
44 sd.BufferDesc.RefreshRate.Numerator = 75; // частота обновления экрана
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
45 sd.BufferDesc.RefreshRate.Denominator = 1;
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
46 sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; // назначение буфера - задний буфер
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
47 sd.OutputWindow = g_hWnd; // привязываем к нашему окну
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
48 sd.SampleDesc.Count = 1;
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
49 sd.SampleDesc.Quality = 0;
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
50 sd.Windowed = TRUE; // не полноэкранный режим
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
51
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
52 for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ )
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
53 {
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
54 g_driverType = driverTypes[driverTypeIndex];
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
55 hr = D3D11CreateDeviceAndSwapChain ( NULL, g_driverType, NULL, createDeviceFlags, featureLevels, numFeatureLevels, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext );
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
56 if (SUCCEEDED(hr)) // Если устройства созданы успешно, то выходим из цикла
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
57 break;
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
58 }
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
59 if (FAILED(hr)) return hr;
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
60
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
61 // Теперь создаем задний буфер. Обратите внимание, в SDK
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
62 // RenderTargetOutput - это передний буфер, а RenderTargetView - задний.
2410
2d3c3d1dff0c added RenderStruct.h
Ritor1
parents: 2402
diff changeset
63 pBackBuffer = NULL;
2402
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
64 hr = g_pSwapChain->GetBuffer( 0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer );
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
65 if (FAILED(hr)) return hr;
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
66
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
67 // интерфейс g_pd3dDevice будет использоваться для создания остальных объектов
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
68 hr = g_pd3dDevice->CreateRenderTargetView( pBackBuffer, NULL, &g_pRenderTargetView );
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
69 pBackBuffer->Release();
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
70 if (FAILED(hr)) return hr;
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
71
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
72 // Подключаем объект заднего буфера к контексту устройства
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
73 g_pImmediateContext->OMSetRenderTargets( 1, &g_pRenderTargetView, NULL );
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
74
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
75 // Настройка вьюпорта
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
76 D3D11_VIEWPORT vp;
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
77 vp.Width = (FLOAT)width;
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
78 vp.Height = (FLOAT)height;
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
79 vp.MinDepth = 0.0f;
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
80 vp.MaxDepth = 1.0f;
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
81 vp.TopLeftX = 0;
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
82 vp.TopLeftY = 0;
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
83
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
84 // Подключаем вьюпорт к контексту устройства
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
85 g_pImmediateContext->RSSetViewports (1, &vp);
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
86
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
87 return S_OK;
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
88 }
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
89
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
90 //--------------------------------------------------------------------------------------
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
91 // Удалить все созданные объекты
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
92 //--------------------------------------------------------------------------------------
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
93 void D3D11::CleanupDevice()
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
94 {
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
95 // Сначала отключим контекст устройства, потом отпустим объекты.
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
96 if( g_pImmediateContext ) g_pImmediateContext->ClearState();
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
97
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
98 // удалеям объекты в порядке, обратном тому, в котором создавали.
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
99 if( g_pRenderTargetView ) g_pRenderTargetView->Release();
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
100
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
101 if( g_pSwapChain ) g_pSwapChain->Release();
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
102
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
103 if( g_pImmediateContext ) g_pImmediateContext->Release();
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
104
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
105 if( g_pd3dDevice ) g_pd3dDevice->Release();
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
106 }
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
107
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
108 void Render()
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
109 {
8cee51ce4382 included directx 11
Ritor1
parents:
diff changeset
110
2416
8b04ba723324 misstake in LoadSound
Ritor1
parents: 2415
diff changeset
111 }*/