20#ifdef GPUCA_BUILD_EVENT_DISPLAY_VULKAN
21#define GLFW_INCLUDE_VULKAN
23#include <GLFW/glfw3.h>
39int32_t GPUDisplayFrontendGlfw::GetKey(int32_t
key)
41 if (
key == GLFW_KEY_KP_SUBTRACT) {
44 if (
key == GLFW_KEY_KP_ADD) {
47 if (
key == GLFW_KEY_LEFT_SHIFT ||
key == GLFW_KEY_RIGHT_SHIFT) {
50 if (
key == GLFW_KEY_LEFT_ALT) {
53 if (
key == GLFW_KEY_RIGHT_ALT) {
56 if (
key == GLFW_KEY_LEFT_CONTROL) {
59 if (
key == GLFW_KEY_RIGHT_CONTROL) {
62 if (
key == GLFW_KEY_UP) {
65 if (
key == GLFW_KEY_DOWN) {
68 if (
key == GLFW_KEY_LEFT) {
71 if (
key == GLFW_KEY_RIGHT) {
74 if (
key == GLFW_KEY_PAGE_UP) {
77 if (
key == GLFW_KEY_PAGE_DOWN) {
80 if (
key == GLFW_KEY_ESCAPE) {
83 if (
key == GLFW_KEY_SPACE) {
86 if (
key == GLFW_KEY_HOME) {
89 if (
key == GLFW_KEY_END) {
92 if (
key == GLFW_KEY_INSERT) {
95 if (
key == GLFW_KEY_ENTER) {
98 if (
key == GLFW_KEY_F1) {
101 if (
key == GLFW_KEY_F2) {
104 if (
key == GLFW_KEY_F3) {
107 if (
key == GLFW_KEY_F4) {
110 if (
key == GLFW_KEY_F5) {
113 if (
key == GLFW_KEY_F6) {
116 if (
key == GLFW_KEY_F7) {
119 if (
key == GLFW_KEY_F8) {
122 if (
key == GLFW_KEY_F9) {
125 if (
key == GLFW_KEY_F10) {
128 if (
key == GLFW_KEY_F11) {
131 if (
key == GLFW_KEY_F12) {
137void GPUDisplayFrontendGlfw::GetKey(int32_t
key, int32_t scancode, int32_t mods, int32_t& keyOut, int32_t& keyPressOut)
139 int32_t specialKey = GetKey(
key);
140 const char*
str = glfwGetKeyName(
key, scancode);
141 char localeKey =
str ?
str[0] : 0;
142 if ((mods & GLFW_MOD_SHIFT) && localeKey >=
'a' && localeKey <=
'z') {
143 localeKey +=
'A' -
'a';
148 keyOut = keyPressOut = specialKey;
150 keyOut = keyPressOut = (
uint8_t)localeKey;
151 if (keyPressOut >=
'a' && keyPressOut <=
'z') {
152 keyPressOut +=
'A' -
'a';
157void GPUDisplayFrontendGlfw::error_callback(int32_t
error,
const char*
description) { fprintf(stderr,
"Error: %s\n",
description); }
159void GPUDisplayFrontendGlfw::key_callback(GLFWwindow* window, int32_t
key, int32_t scancode, int32_t action, int32_t mods)
161 int32_t handleKey = 0, keyPress = 0;
162 GetKey(
key, scancode, mods, handleKey, keyPress);
163 if (handleKey < 32) {
164 if (action == GLFW_PRESS) {
165 me->mKeys[keyPress] =
true;
166 me->mKeysShift[keyPress] = mods & GLFW_MOD_SHIFT;
167 me->HandleKey(handleKey);
168 }
else if (action == GLFW_RELEASE) {
169 me->mKeys[keyPress] =
false;
170 me->mKeysShift[keyPress] =
false;
172 }
else if (handleKey < 256) {
173 if (action == GLFW_PRESS) {
174 me->mLastKeyDown = handleKey;
175 }
else if (action == GLFW_RELEASE) {
176 keyPress = (
uint8_t)
me->mKeyDownMap[handleKey];
177 me->mKeys[keyPress] =
false;
178 me->mKeysShift[keyPress] =
false;
183void GPUDisplayFrontendGlfw::char_callback(GLFWwindow* window, uint32_t codepoint)
186 if (codepoint < 256) {
188 if (keyPress >=
'a' && keyPress <=
'z') {
189 keyPress +=
'A' -
'a';
191 me->mKeyDownMap[
me->mLastKeyDown] = keyPress;
192 me->mKeys[keyPress] =
true;
194 me->HandleKey(codepoint);
198void GPUDisplayFrontendGlfw::mouseButton_callback(GLFWwindow* window, int32_t button, int32_t action, int32_t mods)
200 if (action == GLFW_PRESS) {
203 }
else if (button == 1) {
204 me->mMouseDnR =
true;
205 }
else if (button == GLFW_MOUSE_BUTTON_MIDDLE) {
206 me->mMouseDnM =
true;
208 me->mMouseDnX =
me->mMouseMvX;
209 me->mMouseDnY =
me->mMouseMvY;
210 }
else if (action == GLFW_RELEASE) {
212 me->mMouseDn =
false;
213 }
else if (button == 1) {
214 me->mMouseDnR =
false;
215 }
else if (button == GLFW_MOUSE_BUTTON_MIDDLE) {
216 me->mMouseDnM =
false;
221void GPUDisplayFrontendGlfw::scroll_callback(GLFWwindow* window,
double x,
double y) {
me->mMouseWheel +=
y * 100; }
223void GPUDisplayFrontendGlfw::cursorPos_callback(GLFWwindow* window,
double x,
double y)
225 me->mMouseMvX =
x *
me->mPixelRatio;
226 me->mMouseMvY =
y *
me->mPixelRatio;
229void GPUDisplayFrontendGlfw::resize_callback(GLFWwindow* window, int32_t
width, int32_t
height)
231 int32_t windowWidth, windowHeight;
232 glfwGetWindowSize(window, &windowWidth, &windowHeight);
233 me->mPixelRatio = windowWidth ? (double)
width / windowWidth : 1.;
237void GPUDisplayFrontendGlfw::focus_callback(GLFWwindow* window, int32_t focused)
244void GPUDisplayFrontendGlfw::contentScale_callback(GLFWwindow* window,
float xscale,
float yscale)
249void GPUDisplayFrontendGlfw::maximize_callback(GLFWwindow* window, int32_t maximized)
251 me->setWindowState(glfwGetWindowMonitor(window) !=
nullptr, maximized);
252 if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND) {
254 glfwGetWindowSize(window, &
me->mWindowedWidth, &
me->mWindowedHeight);
256 me->mRestoreWindowedSize =
true;
261int32_t GPUDisplayFrontendGlfw::FrontendMain()
266 fprintf(stderr,
"Error initializing glfw\n");
269 glfwSetErrorCallback(error_callback);
272 glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
277 glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, 0);
278 glfwWindowHint(GLFW_OPENGL_PROFILE,
mBackend->
CoreProfile() ? GLFW_OPENGL_CORE_PROFILE : GLFW_OPENGL_COMPAT_PROFILE);
280 glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE);
283 fprintf(stderr,
"Error creating glfw window\n");
288 glfwMakeContextCurrent(mWindow);
291 glfwSetKeyCallback(mWindow, key_callback);
292 glfwSetCharCallback(mWindow, char_callback);
293 glfwSetMouseButtonCallback(mWindow, mouseButton_callback);
294 glfwSetScrollCallback(mWindow, scroll_callback);
295 glfwSetCursorPosCallback(mWindow, cursorPos_callback);
296 glfwSetFramebufferSizeCallback(mWindow, resize_callback);
297 glfwSetWindowMaximizeCallback(mWindow, maximize_callback);
298 glfwSetWindowFocusCallback(mWindow, focus_callback);
299 float xscale, yscale;
300 glfwGetWindowContentScale(mWindow, &xscale, &yscale);
301 contentScale_callback(mWindow, xscale, yscale);
302 glfwSetWindowContentScaleCallback(mWindow, contentScale_callback);
303 const float limitScale = (glfwGetPlatform() == GLFW_PLATFORM_X11 || glfwGetPlatform() == GLFW_PLATFORM_WIN32) ? mScale : 1.f;
304 glfwSetWindowSizeLimits(mWindow,
MIN_WIDTH * limitScale,
MIN_HEIGHT * limitScale, GLFW_DONT_CARE, GLFW_DONT_CARE);
305 int32_t fbWidth, fbHeight, windowWidth, windowHeight;
306 glfwGetFramebufferSize(mWindow, &fbWidth, &fbHeight);
307 glfwGetWindowSize(mWindow, &windowWidth, &windowHeight);
308 mPixelRatio = windowWidth ? (double)fbWidth / windowWidth : 1.;
313 fprintf(stderr,
"Error initializing GL extension wrapper\n");
318 fprintf(stderr,
"Error in GLFW display initialization\n");
328 while (!glfwWindowShouldClose(mWindow)) {
331 fprintf(stderr,
"Error drawing GL scene\n");
336 glfwSwapBuffers(mWindow);
340 if (mRestoreWindowedSize) {
341 mRestoreWindowedSize =
false;
342 if (mWindowedWidth > 0 && mWindowedHeight > 0 && !glfwGetWindowAttrib(mWindow, GLFW_MAXIMIZED)) {
343 glfwSetWindowSize(mWindow, mWindowedWidth, mWindowedHeight);
352 glfwDestroyWindow(mWindow);
362 glfwSetWindowShouldClose(mWindow,
true);
371 GPUInfo(
"Setting Full Screen %d", (int32_t)set);
373 glfwGetWindowPos(mWindow, &mWindowX, &mWindowY);
374 glfwGetWindowSize(mWindow, &mWindowWidth, &mWindowHeight);
375 GLFWmonitor* primary = glfwGetPrimaryMonitor();
376 const GLFWvidmode*
mode = glfwGetVideoMode(primary);
377 glfwSetWindowMonitor(mWindow, primary, 0, 0,
mode->width,
mode->height,
mode->refreshRate);
379 glfwSetWindowMonitor(mWindow,
nullptr, mWindowX, mWindowY, mWindowWidth, mWindowHeight, GLFW_DONT_CARE);
386 glfwMaximizeWindow(mWindow);
388 glfwRestoreWindow(mWindow);
403 GLFWmonitor* monitor = glfwGetWindowMonitor(mWindow) ? glfwGetWindowMonitor(mWindow) : glfwGetPrimaryMonitor();
404 const GLFWvidmode*
mode = monitor ? glfwGetVideoMode(monitor) :
nullptr;
405 return mode ?
mode->refreshRate : 0.f;
415#ifdef GPUCA_BUILD_EVENT_DISPLAY_VULKAN
416 return glfwCreateWindowSurface(*(VkInstance*)instance, mWindow,
nullptr, (VkSurfaceKHR*)
surface) != VK_SUCCESS;
424 uint32_t glfwExtensionCount = 0;
425#ifdef GPUCA_BUILD_EVENT_DISPLAY_VULKAN
426 p = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
428 return glfwExtensionCount;
header::DataDescription description
char error[CURL_ERROR_SIZE]
const Acts::Surface * surface
virtual bool CoreProfile()
virtual int32_t ExtInit()
backendTypes backendType() const
void SetVSync(bool enable) override
void StopDisplayA() override
void getSize(int32_t &width, int32_t &height) override
void OpenGLPrint(const char *s, float x, float y, float r, float g, float b, float a, bool fromBotton=true) override
void ToggleMaximized(bool set) override
uint32_t getReqVulkanExtensions(const char **&p) override
void SwitchFullscreen(bool set) override
int32_t getVulkanSurface(void *instance, void *surface) override
float getRefreshRate() override
bool canSetVSync() override
void HandleExternalGUISignals()
static constexpr int32_t KEY_F9
const char * mFrontendName
static constexpr int32_t KEY_F2
static constexpr int32_t KEY_ALT
static constexpr int32_t KEY_F12
static constexpr int32_t KEY_F7
static constexpr int32_t KEY_END
static constexpr int32_t KEY_PAGEDOWN
static constexpr int32_t KEY_RALT
volatile int32_t mDisplayControl
static constexpr int32_t KEY_F10
static constexpr int32_t KEY_F4
static constexpr int32_t KEY_LEFT
std::mutex mExitStateMutex
static constexpr int32_t KEY_ENTER
static constexpr int32_t KEY_F6
static constexpr int32_t KEY_CTRL
static constexpr int32_t KEY_F1
static constexpr const char * DISPLAY_WINDOW_NAME
static constexpr int32_t INIT_WIDTH
static constexpr int32_t GL_MIN_VERSION_MAJOR
frontendTypes mFrontendType
static constexpr int32_t KEY_SHIFT
static constexpr int32_t KEY_F3
static constexpr int32_t KEY_INSERT
static constexpr int32_t KEY_F11
static constexpr int32_t KEY_SPACE
static constexpr int32_t KEY_F5
static constexpr int32_t KEY_PAGEUP
static constexpr int32_t KEY_HOME
GPUDisplayBackend * mBackend
static constexpr int32_t GL_MIN_VERSION_MINOR
int32_t InitDisplay(bool initFailure=false)
bool vsyncEnabled() const
GPUDisplayBackend * backend()
static constexpr int32_t KEY_UP
static constexpr int32_t KEY_DOWN
static constexpr int32_t KEY_F8
void applyInitialWindowState()
static constexpr int32_t MIN_WIDTH
static constexpr int32_t INIT_HEIGHT
static constexpr int32_t KEY_RIGHT
volatile bool mDisplayRunning
static constexpr int32_t KEY_RCTRL
static constexpr int32_t MIN_HEIGHT
static constexpr int32_t KEY_ESCAPE
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
uint8_t itsSharedClusterMap uint8_t