Skip to content

Commit 56706c8

Browse files
authored
Add .clang-format (#10)
* Add .clang-format * Apply formatting
1 parent 636903e commit 56706c8

File tree

102 files changed

+1320
-1230
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+1320
-1230
lines changed

.clang-format

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
Language: Cpp
3+
BasedOnStyle: Microsoft
4+
Standard: c++17
5+
6+
AccessModifierOffset: -4
7+
AlignAfterOpenBracket: Align
8+
AlignArrayOfStructures: Right
9+
AlignOperands: AlignAfterOperator
10+
AllowAllArgumentsOnNextLine: false
11+
AllowAllParametersOfDeclarationOnNextLine: false
12+
AllowShortFunctionsOnASingleLine: Empty
13+
BinPackArguments: false
14+
BinPackParameters: false
15+
BraceWrapping:
16+
AfterClass: true
17+
AfterEnum: true
18+
AfterFunction: true
19+
AfterNamespace: true
20+
AfterStruct: true
21+
AfterUnion: true
22+
BreakBeforeBinaryOperators: All
23+
BreakBeforeBraces: Custom
24+
BreakConstructorInitializers: BeforeColon
25+
Cpp11BracedListStyle: false
26+
ColumnLimit: 0
27+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
28+
ContinuationIndentWidth: 4
29+
IndentWidth: 4
30+
InsertTrailingCommas: Wrapped
31+
PointerAlignment: Left
32+
SpaceAfterTemplateKeyword: true
33+
SpaceBeforeParens: ControlStatements
34+
SpacesInLineCommentPrefix:
35+
Minimum: 1
36+
Maximum: 4
37+
SortIncludes: true
38+
TabWidth: 8
39+
UseTab: Never

src/Cpp/1-getting-started/1-1-1-HelloWindow/Main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
int main(int argc, char* argv[])
44
{
5-
HelloWindowApplication app{"LearnD3D11 - Hello Window"};
5+
HelloWindowApplication app{ "LearnD3D11 - Hello Window" };
66
app.Run();
77
}

src/Cpp/1-getting-started/1-1-2-HelloD3D11-Raw/Main.cpp

+26-26
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ bool CreateSwapchainResources()
2929
{
3030
ComPtr<ID3D11Texture2D> backBuffer = nullptr;
3131
if (FAILED(g_SwapChain->GetBuffer(
32-
0,
33-
IID_PPV_ARGS(&backBuffer))))
32+
0,
33+
IID_PPV_ARGS(&backBuffer))))
3434
{
3535
std::cout << "D3D11: Failed to get Back Buffer from the SwapChain\n";
3636
return false;
3737
}
3838

3939
if (FAILED(g_Device->CreateRenderTargetView(
40-
backBuffer.Get(),
41-
nullptr,
42-
&g_RenderTarget)))
40+
backBuffer.Get(),
41+
nullptr,
42+
&g_RenderTarget)))
4343
{
4444
std::cout << "D3D11: Failed to create RTV from Back Buffer\n";
4545
return false;
@@ -65,11 +65,11 @@ void HandleResize(
6565

6666
DestroySwapchainResources();
6767
if (FAILED(g_SwapChain->ResizeBuffers(
68-
0,
69-
width,
70-
height,
71-
DXGI_FORMAT::DXGI_FORMAT_B8G8R8A8_UNORM,
72-
0)))
68+
0,
69+
width,
70+
height,
71+
DXGI_FORMAT::DXGI_FORMAT_B8G8R8A8_UNORM,
72+
0)))
7373
{
7474
std::cout << "D3D11: Failed to recreate SwapChain buffers\n";
7575
return;
@@ -123,16 +123,16 @@ int main()
123123
constexpr D3D_FEATURE_LEVEL deviceFeatureLevel = D3D_FEATURE_LEVEL::D3D_FEATURE_LEVEL_11_0;
124124

125125
if (FAILED(D3D11CreateDevice(
126-
nullptr,
127-
D3D_DRIVER_TYPE::D3D_DRIVER_TYPE_HARDWARE,
128-
nullptr,
129-
0,
130-
&deviceFeatureLevel,
131-
1,
132-
D3D11_SDK_VERSION,
133-
&g_Device,
134-
nullptr,
135-
&g_DeviceContext)))
126+
nullptr,
127+
D3D_DRIVER_TYPE::D3D_DRIVER_TYPE_HARDWARE,
128+
nullptr,
129+
0,
130+
&deviceFeatureLevel,
131+
1,
132+
D3D11_SDK_VERSION,
133+
&g_Device,
134+
nullptr,
135+
&g_DeviceContext)))
136136
{
137137
std::cout << "D3D11: Failed to create device and device context\n";
138138
return false;
@@ -154,12 +154,12 @@ int main()
154154
swapChainFullscreenDescriptor.Windowed = true;
155155

156156
if (FAILED(g_DxgiFactory->CreateSwapChainForHwnd(
157-
g_Device.Get(),
158-
glfwGetWin32Window(window),
159-
&swapChainDescriptor,
160-
&swapChainFullscreenDescriptor,
161-
nullptr,
162-
&g_SwapChain)))
157+
g_Device.Get(),
158+
glfwGetWin32Window(window),
159+
&swapChainDescriptor,
160+
&swapChainFullscreenDescriptor,
161+
nullptr,
162+
&g_SwapChain)))
163163
{
164164
std::cout << "DXGI: Failed to create swapchain\n";
165165
return false;

src/Cpp/1-getting-started/1-1-2-HelloD3D11/HelloD3D11Application.cpp

+27-28
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#define GLFW_EXPOSE_NATIVE_WIN32
55
#include <GLFW/glfw3native.h>
66

7-
#include <d3dcompiler.h>
87
#include <DirectXMath.h>
8+
#include <d3dcompiler.h>
99

1010
#include <iostream>
1111

@@ -48,16 +48,16 @@ bool HelloD3D11Application::Initialize()
4848
constexpr D3D_FEATURE_LEVEL deviceFeatureLevel = D3D_FEATURE_LEVEL::D3D_FEATURE_LEVEL_11_0;
4949

5050
if (FAILED(D3D11CreateDevice(
51-
nullptr,
52-
D3D_DRIVER_TYPE::D3D_DRIVER_TYPE_HARDWARE,
53-
nullptr,
54-
0,
55-
&deviceFeatureLevel,
56-
1,
57-
D3D11_SDK_VERSION,
58-
&_device,
59-
nullptr,
60-
&_deviceContext)))
51+
nullptr,
52+
D3D_DRIVER_TYPE::D3D_DRIVER_TYPE_HARDWARE,
53+
nullptr,
54+
0,
55+
&deviceFeatureLevel,
56+
1,
57+
D3D11_SDK_VERSION,
58+
&_device,
59+
nullptr,
60+
&_deviceContext)))
6161
{
6262
std::cout << "D3D11: Failed to create device and device Context\n";
6363
return false;
@@ -79,12 +79,12 @@ bool HelloD3D11Application::Initialize()
7979
swapChainFullscreenDescriptor.Windowed = true;
8080

8181
if (FAILED(_dxgiFactory->CreateSwapChainForHwnd(
82-
_device.Get(),
83-
glfwGetWin32Window(GetWindow()),
84-
&swapChainDescriptor,
85-
&swapChainFullscreenDescriptor,
86-
nullptr,
87-
&_swapChain)))
82+
_device.Get(),
83+
glfwGetWin32Window(GetWindow()),
84+
&swapChainDescriptor,
85+
&swapChainFullscreenDescriptor,
86+
nullptr,
87+
&_swapChain)))
8888
{
8989
std::cout << "DXGI: Failed to create swapchain\n";
9090
return false;
@@ -103,22 +103,21 @@ bool HelloD3D11Application::Load()
103103
return true;
104104
}
105105

106-
107106
bool HelloD3D11Application::CreateSwapchainResources()
108107
{
109108
ComPtr<ID3D11Texture2D> backBuffer = nullptr;
110109
if (FAILED(_swapChain->GetBuffer(
111-
0,
112-
IID_PPV_ARGS(&backBuffer))))
110+
0,
111+
IID_PPV_ARGS(&backBuffer))))
113112
{
114113
std::cout << "D3D11: Failed to get back buffer from the swapchain\n";
115114
return false;
116115
}
117116

118117
if (FAILED(_device->CreateRenderTargetView(
119-
backBuffer.Get(),
120-
nullptr,
121-
&_renderTarget)))
118+
backBuffer.Get(),
119+
nullptr,
120+
&_renderTarget)))
122121
{
123122
std::cout << "D3D11: Failed to create rendertarget view from back buffer\n";
124123
return false;
@@ -142,11 +141,11 @@ void HelloD3D11Application::OnResize(
142141
DestroySwapchainResources();
143142

144143
if (FAILED(_swapChain->ResizeBuffers(
145-
0,
146-
width,
147-
height,
148-
DXGI_FORMAT::DXGI_FORMAT_B8G8R8A8_UNORM,
149-
0)))
144+
0,
145+
width,
146+
height,
147+
DXGI_FORMAT::DXGI_FORMAT_B8G8R8A8_UNORM,
148+
0)))
150149
{
151150
std::cout << "D3D11: Failed to recreate swapchain buffers\n";
152151
return;

src/Cpp/1-getting-started/1-1-2-HelloD3D11/HelloD3D11Application.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3-
#include <dxgi1_3.h>
43
#include <d3d11.h>
4+
#include <dxgi1_3.h>
55
#include <wrl.h>
66

77
#include <Application.hpp>
@@ -10,6 +10,7 @@ class HelloD3D11Application final : public Application
1010
{
1111
template <typename T>
1212
using ComPtr = Microsoft::WRL::ComPtr<T>;
13+
1314
public:
1415
HelloD3D11Application(const std::string& title);
1516
~HelloD3D11Application() override;

src/Cpp/1-getting-started/1-1-2-HelloD3D11/Main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
int main()
44
{
5-
HelloD3D11Application app{"LearnD3D11 - Hello D3D11"};
5+
HelloD3D11Application app{ "LearnD3D11 - Hello D3D11" };
66
app.Run();
77
return 0;
88
}

src/Cpp/1-getting-started/1-1-3-HelloTriangle-Refactored/Definitions.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
#include <wrl/client.h>
44

55
namespace WRL = Microsoft::WRL;
6-

src/Cpp/1-getting-started/1-1-3-HelloTriangle-Refactored/HelloTriangleApplication.cpp

+36-37
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
#define GLFW_EXPOSE_NATIVE_WIN32
88
#include <GLFW/glfw3native.h>
99

10-
#include <dxgi1_2.h>
10+
#include <DirectXColors.h>
11+
#include <DirectXMath.h>
1112
#include <d3d11_2.h>
1213
#include <d3dcompiler.h>
13-
#include <DirectXMath.h>
14-
#include <DirectXColors.h>
14+
#include <dxgi1_2.h>
1515

1616
#include <iostream>
1717

@@ -58,16 +58,16 @@ bool HelloTriangleApplication::Initialize()
5858

5959
WRL::ComPtr<ID3D11DeviceContext> deviceContext;
6060
if (FAILED(D3D11CreateDevice(
61-
nullptr,
62-
D3D_DRIVER_TYPE::D3D_DRIVER_TYPE_HARDWARE,
63-
nullptr,
64-
0,
65-
&deviceFeatureLevel,
66-
1,
67-
D3D11_SDK_VERSION,
68-
&_device,
69-
nullptr,
70-
&deviceContext)))
61+
nullptr,
62+
D3D_DRIVER_TYPE::D3D_DRIVER_TYPE_HARDWARE,
63+
nullptr,
64+
0,
65+
&deviceFeatureLevel,
66+
1,
67+
D3D11_SDK_VERSION,
68+
&_device,
69+
nullptr,
70+
&deviceContext)))
7171
{
7272
std::cout << "D3D11: Failed to create Device and Device Context\n";
7373
return false;
@@ -91,12 +91,12 @@ bool HelloTriangleApplication::Initialize()
9191
swapChainFullscreenDescriptor.Windowed = true;
9292

9393
if (FAILED(_dxgiFactory->CreateSwapChainForHwnd(
94-
_device.Get(),
95-
glfwGetWin32Window(GetWindow()),
96-
&swapChainDescriptor,
97-
&swapChainFullscreenDescriptor,
98-
nullptr,
99-
&_swapChain)))
94+
_device.Get(),
95+
glfwGetWin32Window(GetWindow()),
96+
&swapChainDescriptor,
97+
&swapChainFullscreenDescriptor,
98+
nullptr,
99+
&_swapChain)))
100100
{
101101
std::cout << "DXGI: Failed to create SwapChain\n";
102102
return false;
@@ -127,11 +127,10 @@ bool HelloTriangleApplication::Load()
127127
static_cast<float>(GetWindowWidth()),
128128
static_cast<float>(GetWindowHeight()));
129129

130-
constexpr VertexPositionColor vertices[] =
131-
{
132-
{ Position{ 0.0f, 0.5f, 0.0f }, Color{ 0.25f, 0.39f, 0.19f } },
133-
{ Position{ 0.5f, -0.5f, 0.0f }, Color{ 0.44f, 0.75f, 0.35f } },
134-
{ Position{ -0.5f, -0.5f, 0.0f }, Color{ 0.38f, 0.55f, 0.20f } },
130+
constexpr VertexPositionColor vertices[] = {
131+
{ Position{ 0.0f, 0.5f, 0.0f }, Color{ 0.25f, 0.39f, 0.19f }},
132+
{ Position{ 0.5f, -0.5f, 0.0f }, Color{ 0.44f, 0.75f, 0.35f }},
133+
{Position{ -0.5f, -0.5f, 0.0f }, Color{ 0.38f, 0.55f, 0.20f }},
135134
};
136135
D3D11_BUFFER_DESC bufferInfo = {};
137136
bufferInfo.ByteWidth = sizeof(vertices);
@@ -142,9 +141,9 @@ bool HelloTriangleApplication::Load()
142141
resourceData.pSysMem = vertices;
143142

144143
if (FAILED(_device->CreateBuffer(
145-
&bufferInfo,
146-
&resourceData,
147-
&_triangleVertices)))
144+
&bufferInfo,
145+
&resourceData,
146+
&_triangleVertices)))
148147
{
149148
std::cout << "D3D11: Failed to create triangle vertex buffer\n";
150149
return false;
@@ -157,17 +156,17 @@ bool HelloTriangleApplication::CreateSwapchainResources()
157156
{
158157
WRL::ComPtr<ID3D11Texture2D> backBuffer = nullptr;
159158
if (FAILED(_swapChain->GetBuffer(
160-
0,
161-
IID_PPV_ARGS(&backBuffer))))
159+
0,
160+
IID_PPV_ARGS(&backBuffer))))
162161
{
163162
std::cout << "D3D11: Failed to get Back Buffer from the SwapChain\n";
164163
return false;
165164
}
166165

167166
if (FAILED(_device->CreateRenderTargetView(
168-
backBuffer.Get(),
169-
nullptr,
170-
&_renderTarget)))
167+
backBuffer.Get(),
168+
nullptr,
169+
&_renderTarget)))
171170
{
172171
std::cout << "D3D11: Failed to create RTV from Back Buffer\n";
173172
return false;
@@ -191,11 +190,11 @@ void HelloTriangleApplication::OnResize(
191190
DestroySwapchainResources();
192191

193192
if (FAILED(_swapChain->ResizeBuffers(
194-
0,
195-
width,
196-
height,
197-
DXGI_FORMAT::DXGI_FORMAT_B8G8R8A8_UNORM,
198-
0)))
193+
0,
194+
width,
195+
height,
196+
DXGI_FORMAT::DXGI_FORMAT_B8G8R8A8_UNORM,
197+
0)))
199198
{
200199
std::cout << "D3D11: Failed to recreate SwapChain buffers\n";
201200
return;

0 commit comments

Comments
 (0)