You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We need to include the following headers, here's what each of these headers includes:
130
146
131
147
-`d3d11.h`: The core of D3D11, it contains all the ID3D11XXX types and most of the enums we will be using with D3D11
132
-
-`dxgi.h`: The core of DXGI, it contains all the IDXGIXXX types and additional enums that are required for DXGI structures
148
+
-`dxgi1_3.h`: The core of DXGI, it contains all the IDXGIXXX types and additional enums that are required for DXGI structures
133
149
-`d3dcompiler.h`: Contains all the functions necessary to compiler our HLSL shaders into bytecode that will be fed into the GPU
134
150
-`DirectXMath.h`: DirectX's own math library, it contains all the types and math functions we will be using throughout the series
135
151
-`wrl.h`: Is used for `Microsoft::WRL::ComPtr<T>`, to manage COM resources automatically.
@@ -142,14 +158,7 @@ We need to include the following headers, here's what each of these headers incl
142
158
#pragma comment(lib, "dxguid.lib")
143
159
```
144
160
145
-
Of course just including the headers isn't enough, we must also link against D3D11 & friends to be able to actually use the stuff declared in the headers, put these `#pragma comment(lib, "PATH_TO_LIB")` in `HelloD3D11.cpp` right below the includes to link these libraries.
146
-
147
-
```cpp
148
-
template <typename T>
149
-
using ComPtr = Microsoft::WRL::ComPtr<T>;
150
-
```
151
-
152
-
Since the namespace name for ComPtr<T> is quite long, we are making a type alias like this.
161
+
Of course just including the headers isn't enough, we must also link against D3D11 & friends to be able to actually use the stuff declared in the headers, put these `#pragma comment(lib, "PATH_TO_LIB")` in `HelloD3D11Application.cpp` right below the includes to link these libraries.
153
162
154
163
```cpp
155
164
ComPtr<IDXGIFactory2> _dxgiFactory = nullptr;
@@ -181,9 +190,7 @@ if (!Application::Initialize())
181
190
return false;
182
191
}
183
192
184
-
if (FAILED(CreateDXGIFactory2(
185
-
0,
186
-
IID_PPV_ARGS(&_dxgiFactory))))
193
+
if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&_dxgiFactory))))
187
194
{
188
195
std::cout << "DXGI: Unable to create DXGIFactory\n";
189
196
return false;
@@ -196,10 +203,9 @@ The first part calls the parent class, where `GLFW` is initialized and setup.
Which means that typing `IID_PPV_ARGS(&_dxgiFactory)` it is expanded by the compiler into `__uuidof(**(&_dxgiFactory)), IID_PPV_ARGS_Helper(_dxgiFactory)`. This functionally means that for functions that have a parameter setup as `REFIID` and functionally after a `[out] void**` parameter, this macro will expand the `IID_PPV_ARGS(ppType)` expression into these parameters for ease of use — this can be seen with the used `CreateDXGIFactory2` method where the second last and last parameter are a `REFIID` and `void**`:
206
+
Which means that typing `IID_PPV_ARGS(&_dxgiFactory)` it is expanded by the compiler into `__uuidof(**(&_dxgiFactory)), IID_PPV_ARGS_Helper(_dxgiFactory)`. This functionally means that for functions that have a parameter setup as `REFIID` and functionally after a `[out] void**` parameter, this macro will expand the `IID_PPV_ARGS(ppType)` expression into these parameters for ease of use — this can be seen with the used `CreateDXGIFactory1` method where the parameters are a `REFIID` and `void**`:
200
207
```cpp
201
-
HRESULT CreateDXGIFactory2(
202
-
UINT Flags,
208
+
HRESULT CreateDXGIFactory1(
203
209
REFIID riid,
204
210
[out] void **ppFactory
205
211
);
@@ -220,27 +226,26 @@ What the parts of the `IID_PPV_ARGS(ppType)` macro are:
[`CreateDXGIFactory2`](https://docs.microsoft.com/en-us/windows/win32/api/dxgi1_3/nf-dxgi1_3-createdxgifactory2) is the entry point to create a factory for us, a `IDXGIFactory2` to be precise.
229
+
[`CreateDXGIFactory1`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-createdxgifactory1) is the entry point to create a factory for us, a `IDXGIFactory1` to be precise.
224
230
There are various implementations of it, depending on what version you aim for, you get additional functionality.
225
231
226
-
DXGI 1.0 up to 1.6 More information can be found [here](https://docs.microsoft.com/en-us/windows/win32/api/_direct3ddxgi/) We will stick with `IDXGIFactory2` for now.
232
+
DXGI 1.0 up to 1.6 More information can be found [here](https://docs.microsoft.com/en-us/windows/win32/api/_direct3ddxgi/) We will stick with `IDXGIFactory1` for now.
@@ -275,7 +281,7 @@ if (FAILED(_dxgiFactory->CreateSwapChainForHwnd(
275
281
nullptr,
276
282
&_swapChain)))
277
283
{
278
-
std::cout << "DXGI: Failed to create SwapChain\n";
284
+
std::cout << "DXGI: Failed to create swapchain\n";
279
285
return false;
280
286
}
281
287
```
@@ -284,9 +290,9 @@ After we successfully create device and device context, the next step is to crea
284
290
285
291
The majority of values should make some sense without explanation, like width and height, and whether we want it to support a windowed window or not.
286
292
287
-
`BufferUsage` tells the swapchain's buffers their usage, something we render to, and can present. The format here is in BGRA order, like the device creation flag we specified earlier, if you remember.
293
+
`BufferUsage` tells the swapchain's buffers their usage, something we render to, and can present.
288
294
289
-
`Scaling` tells DXGI to scale the buffer's contents to fit the presentation's target size.
295
+
`Scaling` tells DXGI how to scale the buffer's contents to fit the presentation's target size.
290
296
291
297
`BufferCount` is 2, because we want double buffering. Double buffering is an age-old technique to avoid presenting an image that is being used by the GPU, instead we work on the "back buffer", while the GPU is happy presenting the "front buffer", then, as soon as we are done with the back buffer, we swap front and back, and begin working on the former front buffer present that one and render to the other one again in the meantime. That process is supposed to reduce flicker or tearing.
0 commit comments