forked from SaschaWillems/Vulkan
/
glfw.cpp
66 lines (55 loc) · 2.16 KB
/
glfw.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
#include "glfw.hpp"
#if !defined(ANDROID)
#include <mutex>
namespace glfw {
bool Window::init() {
return GLFW_TRUE == glfwInit();
}
void Window::terminate() {
glfwTerminate();
}
#if defined(VULKAN_HPP)
std::vector<std::string> Window::getRequiredInstanceExtensions() {
std::vector<std::string> result;
uint32_t count = 0;
const char** names = glfwGetRequiredInstanceExtensions(&count);
if (names && count) {
for (uint32_t i = 0; i < count; ++i) {
result.emplace_back(names[i]);
}
}
return result;
}
vk::SurfaceKHR Window::createWindowSurface(GLFWwindow* window, const vk::Instance& instance, const vk::AllocationCallbacks* pAllocator) {
VkSurfaceKHR rawSurface;
vk::Result result =
static_cast<vk::Result>(glfwCreateWindowSurface((VkInstance)instance, window, reinterpret_cast<const VkAllocationCallbacks*>(pAllocator), &rawSurface));
return vk::createResultValue(result, rawSurface, "vk::CommandBuffer::begin");
}
#endif
void Window::KeyboardHandler(GLFWwindow* window, int key, int scancode, int action, int mods) {
Window* example = (Window*)glfwGetWindowUserPointer(window);
example->onKeyEvent(key, scancode, action, mods);
}
void Window::MouseButtonHandler(GLFWwindow* window, int button, int action, int mods) {
Window* example = (Window*)glfwGetWindowUserPointer(window);
example->onMouseButtonEvent(button, action, mods);
}
void Window::MouseMoveHandler(GLFWwindow* window, double posx, double posy) {
Window* example = (Window*)glfwGetWindowUserPointer(window);
example->onMouseMoved(glm::vec2(posx, posy));
}
void Window::MouseScrollHandler(GLFWwindow* window, double xoffset, double yoffset) {
Window* example = (Window*)glfwGetWindowUserPointer(window);
example->onMouseScrolled((float)yoffset);
}
void Window::CloseHandler(GLFWwindow* window) {
Window* example = (Window*)glfwGetWindowUserPointer(window);
example->onWindowClosed();
}
void Window::FramebufferSizeHandler(GLFWwindow* window, int width, int height) {
Window* example = (Window*)glfwGetWindowUserPointer(window);
example->onWindowResized(glm::uvec2(width, height));
}
} // namespace glfw
#endif