forked from SaschaWillems/Vulkan
-
Notifications
You must be signed in to change notification settings - Fork 234
/
MVKExample.cpp
135 lines (117 loc) · 3.92 KB
/
MVKExample.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
/*
* MVKExample.cpp
*
* Copyright (c) 2016-2017 The Brenwill Workshop Ltd.
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/
#include "MVKExample.h"
#include "examples.h"
void MVKExample::renderFrame() {
_vulkanExample->renderFrame();
}
void MVKExample::displayLinkOutputCb() { // SRS - expose VulkanExampleBase::displayLinkOutputCb() to DemoViewController
_vulkanExample->displayLinkOutputCb();
}
void MVKExample::keyPressed(uint32_t keyChar) { // SRS - handle keyboard key presses only (e.g. Pause, Space, etc)
switch (keyChar)
{
case KEY_P:
_vulkanExample->paused = !_vulkanExample->paused;
break;
case KEY_1: // SRS - support keyboards with no function keys
case KEY_F1:
_vulkanExample->UIOverlay.visible = !_vulkanExample->UIOverlay.visible;
_vulkanExample->UIOverlay.updated = true;
break;
default:
_vulkanExample->keyPressed(keyChar);
break;
}
}
void MVKExample::keyDown(uint32_t keyChar) { // SRS - handle physical keyboard key down/up actions and presses
switch (keyChar)
{
case KEY_W:
case KEY_Z: // for French AZERTY keyboards
_vulkanExample->camera.keys.up = true;
break;
case KEY_S:
_vulkanExample->camera.keys.down = true;
break;
case KEY_A:
case KEY_Q: // for French AZERTY keyboards
_vulkanExample->camera.keys.left = true;
break;
case KEY_D:
_vulkanExample->camera.keys.right = true;
break;
default:
MVKExample::keyPressed(keyChar);
break;
}
}
void MVKExample::keyUp(uint32_t keyChar) {
switch (keyChar)
{
case KEY_W:
case KEY_Z: // for French AZERTY keyboards
_vulkanExample->camera.keys.up = false;
break;
case KEY_S:
_vulkanExample->camera.keys.down = false;
break;
case KEY_A:
case KEY_Q: // for French AZERTY keyboards
_vulkanExample->camera.keys.left = false;
break;
case KEY_D:
_vulkanExample->camera.keys.right = false;
break;
default:
break;
}
}
void MVKExample::mouseDown(double x, double y) {
_vulkanExample->mousePos = glm::vec2(x, y);
_vulkanExample->mouseButtons.left = true;
}
void MVKExample::mouseUp() {
_vulkanExample->mouseButtons.left = false;
}
void MVKExample::rightMouseDown(double x, double y) {
_vulkanExample->mousePos = glm::vec2(x, y);
_vulkanExample->mouseButtons.right = true;
}
void MVKExample::rightMouseUp() {
_vulkanExample->mouseButtons.right = false;
}
void MVKExample::otherMouseDown(double x, double y) {
_vulkanExample->mousePos = glm::vec2(x, y);
_vulkanExample->mouseButtons.middle = true;
}
void MVKExample::otherMouseUp() {
_vulkanExample->mouseButtons.middle = false;
}
void MVKExample::mouseDragged(double x, double y) {
_vulkanExample->mouseDragged(x, y);
}
void MVKExample::scrollWheel(short wheelDelta) {
_vulkanExample->camera.translate(glm::vec3(0.0f, 0.0f, wheelDelta * 0.05f * _vulkanExample->camera.movementSpeed));
_vulkanExample->viewUpdated = true;
}
void MVKExample::fullScreen(bool fullscreen) {
_vulkanExample->settings.fullscreen = fullscreen;
}
MVKExample::MVKExample(void* view, double scaleUI) {
_vulkanExample = new VulkanExample();
_vulkanExample->initVulkan();
_vulkanExample->setupWindow(view);
_vulkanExample->settings.vsync = true; // SRS - set vsync flag since this iOS/macOS example app uses displayLink vsync rendering
_vulkanExample->UIOverlay.scale = scaleUI; // SRS - set UIOverlay scale to maintain relative proportions/readability on retina displays
_vulkanExample->prepare();
_vulkanExample->renderLoop(); // SRS - this inits destWidth/destHeight/lastTimestamp/tPrevEnd, then falls through and returns
}
MVKExample::~MVKExample() {
vkDeviceWaitIdle(_vulkanExample->vulkanDevice->logicalDevice);
delete(_vulkanExample);
}