-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
160 lines (128 loc) · 4.11 KB
/
Main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include "Render.h"
#include "Generator.h"
#include "shellapi.h"
#include "stdlib.h"
#include "imgui.h"
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
Render* render = reinterpret_cast<Render*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
if (ImGui_ImplWin32_WndProcHandler(hWnd, message, wParam, lParam))
return true;
switch (message)
{
case WM_CREATE:
{
LPCREATESTRUCT pCreateStruct = reinterpret_cast<LPCREATESTRUCT>(lParam);
SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pCreateStruct->lpCreateParams));
}
return 0;
case WM_PAINT:
if (render)
{
Draw(render);
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
{
const UINT width = 1280;
const UINT height = 720;
char* generatorFileName = nullptr;
char* generatorFileNameBin = nullptr;
int generatorLod = 0;
bool useWarp = false;
bool useWorkGraph = false;
int numArgs = 0;
LPWSTR* args = CommandLineToArgvW(lpCmdLine, &numArgs);
if (args)
{
int ia = 0;
while (ia < numArgs)
{
if (wcscmp(args[ia], L"-generate") == 0)
{
ia += 1;
if (ia >= numArgs)
return -1;
int numBytes = wcstombs(nullptr, args[ia], 0) + 1;
generatorFileName = new char[numBytes];
numBytes = wcstombs(generatorFileName, args[ia], numBytes);
}
else if (wcscmp(args[ia], L"-bin") == 0)
{
ia += 1;
if (ia >= numArgs)
return -1;
int numBytes = wcstombs(nullptr, args[ia], 0) + 1;
generatorFileNameBin = new char[numBytes];
wcstombs(generatorFileNameBin, args[ia], numBytes);
}
else if (wcscmp(args[ia], L"-lod") == 0)
{
ia += 1;
if (ia >= numArgs)
return -1;
generatorLod = _wtoi(args[ia]);
}
else if (wcscmp(args[ia], L"-warp") == 0)
{
useWarp = true;
}
else if (wcscmp(args[ia], L"-workGraph") == 0)
{
useWorkGraph = true;
}
ia += 1;
}
LocalFree(args);
}
WNDCLASSEX windowClass = { 0 };
windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.style = CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc = WindowProc;
windowClass.hInstance = hInstance;
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
windowClass.lpszClassName = L"DXSampleClass";
RegisterClassEx(&windowClass);
RECT windowRect = { 0, 0, width, height };
AdjustWindowRect(&windowRect, WS_OVERLAPPEDWINDOW, FALSE);
if (generatorFileName)
Generate(generatorFileName, generatorFileNameBin, generatorLod);
Render* render = CreateRender(width, height);
HWND hwnd = CreateWindow(
windowClass.lpszClassName,
L"MeshShader",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
windowRect.right - windowRect.left,
windowRect.bottom - windowRect.top,
nullptr,
nullptr,
hInstance,
render);
Initialize(render, hwnd, useWarp);
SetWorkGraph(render, useWorkGraph);
ShowWindow(hwnd, nCmdShow);
MSG msg = {};
while (msg.message != WM_QUIT)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
Destroy(render);
if (generatorFileName)
delete[] generatorFileName;
if (generatorFileNameBin)
delete[] generatorFileNameBin;
return static_cast<char>(msg.wParam);
}