-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathUtils.cpp
More file actions
65 lines (50 loc) · 1.42 KB
/
Copy pathUtils.cpp
File metadata and controls
65 lines (50 loc) · 1.42 KB
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
#include "Utils.hpp"
void Utils::SetWorkingDirectoryToExe()
{
wchar_t path[MAX_PATH];
DWORD n = GetModuleFileNameW(nullptr, path, MAX_PATH);
if (n == 0 || n >= MAX_PATH)
return;
wchar_t* slash = wcsrchr(path, L'\\');
if (!slash)
slash = wcsrchr(path, L'/');
if (!slash)
return;
*slash = L'\0';
SetCurrentDirectoryW(path);
}
void Utils::StartTimer()
{
LARGE_INTEGER frequencyCount;
QueryPerformanceFrequency(&frequencyCount);
g_countsPerSecond = double(frequencyCount.QuadPart);
QueryPerformanceCounter(&frequencyCount);
g_counterStart = frequencyCount.QuadPart;
}
double Utils::GetTime()
{
LARGE_INTEGER currentTime;
QueryPerformanceCounter(¤tTime);
return double(currentTime.QuadPart - g_counterStart) / g_countsPerSecond;
}
double Utils::GetFrameTime()
{
LARGE_INTEGER currentTime;
__int64 tickCount;
QueryPerformanceCounter(¤tTime);
tickCount = currentTime.QuadPart - g_frameTimeOld;
g_frameTimeOld = currentTime.QuadPart;
if (tickCount < 0.0f)
tickCount = 0.0f;
return float(tickCount) / g_countsPerSecond;
}
HRESULT Utils::CompileShaderFromFile(LPCWSTR szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3DBlob** ppBlobOut)
{
HRESULT hr;
DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
hr = D3DCompileFromFile(szFileName, NULL, NULL, szEntryPoint, szShaderModel,
dwShaderFlags, 0, ppBlobOut, NULL);
if (FAILED(hr))
printf("Error: cannot compile shader\n");
return hr;
}