forked from vixorien/D3D11Starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DXCore.h
100 lines (82 loc) · 3.07 KB
/
DXCore.h
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
#pragma once
#include <Windows.h>
#include <d3d11.h>
#include <string>
#include <wrl/client.h> // Used for ComPtr - a smart pointer for COM objects
#include "ImGui/imgui.h"
#include "ImGui/imgui_impl_dx11.h"
#include "ImGui/imgui_impl_win32.h"
// We can include the correct library files here
// instead of in Visual Studio settings if we want
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "dxgi.lib")
class DXCore
{
public:
DXCore(
HINSTANCE hInstance, // The application's handle
const wchar_t* titleBarText,// Text for the window's title bar
unsigned int windowWidth, // Width of the window's client area
unsigned int windowHeight, // Height of the window's client area
bool vsync, // Sync the framerate to the monitor?
bool debugTitleBarStats); // Show extra stats (fps) in title bar?
~DXCore();
// Static requirements for OS-level message processing
static DXCore* DXCoreInstance;
static LRESULT CALLBACK WindowProc(
HWND hWnd, // Window handle
UINT uMsg, // Message
WPARAM wParam, // Message's first parameter
LPARAM lParam // Message's second parameter
);
// Internal method for message handling
LRESULT ProcessMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
// Initialization and game-loop related methods
HRESULT InitWindow();
HRESULT InitDirect3D();
HRESULT Run();
void Quit();
virtual void OnResize();
// Pure virtual methods for setup and game functionality
virtual void Init() = 0;
virtual void Update(float deltaTime, float totalTime) = 0;
virtual void Draw(float deltaTime, float totalTime) = 0;
protected:
HINSTANCE hInstance; // The handle to the application
HWND hWnd; // The handle to the window itself
std::wstring titleBarText; // Custom text in window's title bar
bool titleBarStats; // Show extra stats in title bar?
// Size of the window's client area
unsigned int windowWidth;
unsigned int windowHeight;
// Does our window currently have focus?
// Helpful if we want to pause while not the active window
bool hasFocus;
// Should our framerate sync to the vertical refresh
// of the monitor (true) or run as fast as possible (false)?
bool vsync;
bool deviceSupportsTearing;
BOOL isFullscreen; // Due to alt+enter key combination (must be BOOL typedef)
// DirectX related objects and variables
D3D_FEATURE_LEVEL dxFeatureLevel;
Microsoft::WRL::ComPtr<IDXGISwapChain> swapChain;
Microsoft::WRL::ComPtr<ID3D11Device> device;
Microsoft::WRL::ComPtr<ID3D11DeviceContext> context;
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> backBufferRTV;
Microsoft::WRL::ComPtr<ID3D11DepthStencilView> depthBufferDSV;
// Helper function for allocating a console window
void CreateConsoleWindow(int bufferLines, int bufferColumns, int windowLines, int windowColumns);
private:
// Timing related data
double perfCounterSeconds;
float totalTime;
float deltaTime;
__int64 startTime;
__int64 currentTime;
__int64 previousTime;
// FPS calculation
int fpsFrameCount;
float fpsTimeElapsed;
void UpdateTimer(); // Updates the timer for this frame
void UpdateTitleBarStats(); // Puts debug info in the title bar
};