-
Notifications
You must be signed in to change notification settings - Fork 16
/
DXSample.h
83 lines (67 loc) · 2.74 KB
/
DXSample.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
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
#pragma once
#include "DXSampleHelper.h"
#include "Win32Application.h"
class DXSample
{
public:
DXSample(UINT width, UINT height, std::wstring name);
virtual ~DXSample();
virtual void OnInit() = 0;
virtual void OnUpdate() = 0;
virtual void OnRender() = 0;
virtual void OnSizeChanged(UINT width, UINT height, bool minimized) = 0;
virtual void OnDestroy() = 0;
// Samples override the event handlers to handle specific messages.
virtual void OnKeyDown(UINT8 /*key*/) {}
virtual void OnKeyUp(UINT8 /*key*/) {}
virtual void OnWindowMoved(int /*x*/, int /*y*/) {}
virtual void OnMouseMove(UINT /*x*/, UINT /*y*/) {}
virtual void OnLeftButtonDown(UINT /*x*/, UINT /*y*/) {}
virtual void OnLeftButtonUp(UINT /*x*/, UINT /*y*/) {}
virtual void OnDisplayChanged() {}
// Accessors.
UINT GetWidth() const { return m_width; }
UINT GetHeight() const { return m_height; }
const WCHAR* GetTitle() const { return m_title.c_str(); }
bool GetTearingSupport() const { return m_tearingSupport; }
RECT GetWindowsBounds() const { return m_windowBounds; }
virtual IDXGISwapChain* GetSwapchain() { return nullptr; }
void ParseCommandLineArgs(_In_reads_(argc) WCHAR* argv[], int argc);
void UpdateForSizeChange(UINT clientWidth, UINT clientHeight);
void SetWindowBounds(int left, int top, int right, int bottom);
std::wstring GetAssetFullPath(LPCWSTR assetName);
protected:
void GetHardwareAdapter(
_In_ IDXGIFactory2* pFactory,
_Outptr_result_maybenull_ IDXGIAdapter1** ppAdapter,
bool requestHighPerformanceAdapter = false);
void SetCustomWindowText(LPCWSTR text);
void CheckTearingSupport();
// Viewport dimensions.
UINT m_width;
UINT m_height;
float m_aspectRatio;
// Window bounds
RECT m_windowBounds;
// Whether or not tearing is available for fullscreen borderless windowed mode.
bool m_tearingSupport;
// Adapter info.
bool m_useWarpDevice;
// Override to be able to start without Dx11on12 UI for PIX. PIX doesn't support 11 on 12.
bool m_enableUI;
private:
// Root assets path.
std::wstring m_assetsPath;
// Window title.
std::wstring m_title;
};