24#if defined(GPUCA_O2_LIB) && !defined(GPUCA_DISPLAY_GL3W)
28#ifdef GPUCA_BUILD_EVENT_DISPLAY_VULKAN
29#define GLFW_INCLUDE_VULKAN
31#include <GLFW/glfw3.h>
38#if __has_include("../src/imgui.h")
39#include "../src/imgui.h"
40#include "../src/imgui_impl_glfw_gl3.h"
42#include "DebugGUI/imgui.h"
43#include "DebugGUI/imgui_impl_glfw_gl3.h"
45#include <DebugGUI/DebugGUI.h>
58int32_t GPUDisplayFrontendGlfw::GetKey(int32_t
key)
60 if (
key == GLFW_KEY_KP_SUBTRACT) {
63 if (
key == GLFW_KEY_KP_ADD) {
66 if (
key == GLFW_KEY_LEFT_SHIFT ||
key == GLFW_KEY_RIGHT_SHIFT) {
69 if (
key == GLFW_KEY_LEFT_ALT) {
72 if (
key == GLFW_KEY_RIGHT_ALT) {
75 if (
key == GLFW_KEY_LEFT_CONTROL) {
78 if (
key == GLFW_KEY_RIGHT_CONTROL) {
81 if (
key == GLFW_KEY_UP) {
84 if (
key == GLFW_KEY_DOWN) {
87 if (
key == GLFW_KEY_LEFT) {
90 if (
key == GLFW_KEY_RIGHT) {
93 if (
key == GLFW_KEY_PAGE_UP) {
96 if (
key == GLFW_KEY_PAGE_DOWN) {
99 if (
key == GLFW_KEY_ESCAPE) {
102 if (
key == GLFW_KEY_SPACE) {
105 if (
key == GLFW_KEY_HOME) {
108 if (
key == GLFW_KEY_END) {
111 if (
key == GLFW_KEY_INSERT) {
114 if (
key == GLFW_KEY_ENTER) {
117 if (
key == GLFW_KEY_F1) {
120 if (
key == GLFW_KEY_F2) {
123 if (
key == GLFW_KEY_F3) {
126 if (
key == GLFW_KEY_F4) {
129 if (
key == GLFW_KEY_F5) {
132 if (
key == GLFW_KEY_F6) {
135 if (
key == GLFW_KEY_F7) {
138 if (
key == GLFW_KEY_F8) {
141 if (
key == GLFW_KEY_F9) {
144 if (
key == GLFW_KEY_F10) {
147 if (
key == GLFW_KEY_F11) {
150 if (
key == GLFW_KEY_F12) {
156void GPUDisplayFrontendGlfw::GetKey(int32_t
key, int32_t scancode, int32_t mods, int32_t& keyOut, int32_t& keyPressOut)
158 int32_t specialKey = GetKey(
key);
159 const char*
str = glfwGetKeyName(
key, scancode);
160 char localeKey =
str ?
str[0] : 0;
161 if ((mods & GLFW_MOD_SHIFT) && localeKey >=
'a' && localeKey <=
'z') {
162 localeKey +=
'A' -
'a';
167 keyOut = keyPressOut = specialKey;
169 keyOut = keyPressOut = (
uint8_t)localeKey;
170 if (keyPressOut >=
'a' && keyPressOut <=
'z') {
171 keyPressOut +=
'A' -
'a';
176void GPUDisplayFrontendGlfw::error_callback(int32_t error,
const char* description) { fprintf(stderr,
"Error: %s\n", description); }
178void GPUDisplayFrontendGlfw::key_callback(GLFWwindow* window, int32_t
key, int32_t scancode, int32_t action, int32_t mods)
180 int32_t handleKey = 0, keyPress = 0;
181 GetKey(
key, scancode, mods, handleKey, keyPress);
182 if (handleKey < 32) {
183 if (action == GLFW_PRESS) {
184 me->mKeys[keyPress] =
true;
185 me->mKeysShift[keyPress] = mods & GLFW_MOD_SHIFT;
186 me->HandleKey(handleKey);
187 }
else if (action == GLFW_RELEASE) {
188 me->mKeys[keyPress] =
false;
189 me->mKeysShift[keyPress] =
false;
191 }
else if (handleKey < 256) {
192 if (action == GLFW_PRESS) {
193 me->mLastKeyDown = handleKey;
194 }
else if (action == GLFW_RELEASE) {
195 keyPress = (
uint8_t)
me->mKeyDownMap[handleKey];
196 me->mKeys[keyPress] =
false;
197 me->mKeysShift[keyPress] =
false;
202void GPUDisplayFrontendGlfw::char_callback(GLFWwindow* window, uint32_t codepoint)
205 if (codepoint < 256) {
207 if (keyPress >=
'a' && keyPress <=
'z') {
208 keyPress +=
'A' -
'a';
210 me->mKeyDownMap[
me->mLastKeyDown] = keyPress;
211 me->mKeys[keyPress] =
true;
213 me->HandleKey(codepoint);
217void GPUDisplayFrontendGlfw::mouseButton_callback(GLFWwindow* window, int32_t button, int32_t action, int32_t mods)
219 if (action == GLFW_PRESS) {
222 }
else if (button == 1) {
223 me->mMouseDnR =
true;
225 me->mMouseDnX =
me->mMouseMvX;
226 me->mMouseDnY =
me->mMouseMvY;
227 }
else if (action == GLFW_RELEASE) {
229 me->mMouseDn =
false;
230 }
else if (button == 1) {
231 me->mMouseDnR =
false;
236void GPUDisplayFrontendGlfw::scroll_callback(GLFWwindow* window,
double x,
double y) {
me->mMouseWheel +=
y * 100; }
238void GPUDisplayFrontendGlfw::cursorPos_callback(GLFWwindow* window,
double x,
double y)
244void GPUDisplayFrontendGlfw::resize_callback(GLFWwindow* window, int32_t
width, int32_t
height) {
me->ResizeScene(
width,
height); }
247void GPUDisplayFrontendGlfw::DisplayLoop()
249 ImGui::SetNextWindowPos(ImVec2(0, 0));
250 ImGui::SetNextWindowSize(ImVec2(
me->mDisplayWidth,
me->mDisplayHeight));
251 ImGui::SetNextWindowBgAlpha(0.f);
252 ImGui::Begin(
"Console",
nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
258int32_t GPUDisplayFrontendGlfw::FrontendMain()
263 fprintf(stderr,
"Error initializing glfw\n");
266 glfwSetErrorCallback(error_callback);
268 glfwWindowHint(GLFW_MAXIMIZED, 1);
270 glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
275 glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, 0);
276 glfwWindowHint(GLFW_OPENGL_PROFILE,
mBackend->
CoreProfile() ? GLFW_OPENGL_CORE_PROFILE : GLFW_OPENGL_COMPAT_PROFILE);
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 glfwSetWindowSizeCallback(mWindow, resize_callback);
301 pthread_mutex_lock(&mSemLockExit);
303 pthread_mutex_unlock(&mSemLockExit);
306 fprintf(stderr,
"Error initializing GL extension wrapper\n");
310#if defined(GPUCA_O2_LIB) && !defined(GPUCA_DISPLAY_GL3W)
312 fprintf(stderr,
"Error initializing gl3w (2)\n");
327 fprintf(stderr,
"Error in GLFW display initialization\n");
333 ImGui_ImplGlfwGL3_Init(mWindow,
false);
334 while (o2::framework::pollGUI(mWindow, DisplayLoop)) {
339 while (!glfwWindowShouldClose(mWindow)) {
342 fprintf(stderr,
"Error drawing GL scene\n");
346 glfwSwapBuffers(mWindow);
354 pthread_mutex_lock(&mSemLockExit);
357 ImGui_ImplGlfwGL3_Shutdown();
360 glfwDestroyWindow(mWindow);
362 mGlfwRunning =
false;
363 pthread_mutex_unlock(&mSemLockExit);
370 pthread_mutex_lock(&mSemLockExit);
372 glfwSetWindowShouldClose(mWindow,
true);
374 pthread_mutex_unlock(&mSemLockExit);
375 while (mGlfwRunning) {
385 y = ImGui::GetWindowHeight() -
y;
388 ImGui::SetCursorPos(ImVec2(
x,
y));
389 ImGui::TextColored(ImVec4(
r,
g,
b,
a),
"%s", s);
396 GPUInfo(
"Setting Full Screen %d", (int32_t)set);
398 glfwGetWindowPos(mWindow, &mWindowX, &mWindowY);
399 glfwGetWindowSize(mWindow, &mWindowWidth, &mWindowHeight);
400 GLFWmonitor* primary = glfwGetPrimaryMonitor();
401 const GLFWvidmode*
mode = glfwGetVideoMode(primary);
402 glfwSetWindowMonitor(mWindow, primary, 0, 0,
mode->width,
mode->height,
mode->refreshRate);
404 glfwSetWindowMonitor(mWindow,
nullptr, mWindowX, mWindowY, mWindowWidth, mWindowHeight, GLFW_DONT_CARE);
411 glfwMaximizeWindow(mWindow);
413 glfwRestoreWindow(mWindow);
435#ifdef GPUCA_BUILD_EVENT_DISPLAY_VULKAN
436 return glfwCreateWindowSurface(*(VkInstance*)instance, mWindow,
nullptr, (VkSurfaceKHR*)surface) != VK_SUCCESS;
444 uint32_t glfwExtensionCount = 0;
445#ifdef GPUCA_BUILD_EVENT_DISPLAY_VULKAN
446 p = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
448 return glfwExtensionCount;
virtual bool CoreProfile()
virtual int32_t ExtInit()
void SetVSync(bool enable) 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 DisplayExit() override
void SwitchFullscreen(bool set) override
int32_t getVulkanSurface(void *instance, void *surface) override
bool EnableSendKey() override
int32_t & drawTextFontSize()
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
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)
GPUDisplayBackend * backend()
static constexpr int32_t KEY_UP
static constexpr int32_t KEY_DOWN
static constexpr int32_t KEY_F8
static constexpr int32_t INIT_HEIGHT
static constexpr int32_t KEY_RIGHT
static constexpr int32_t KEY_RCTRL
static constexpr int32_t KEY_ESCAPE
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
uint8_t itsSharedClusterMap uint8_t