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>
39#if __has_include("../src/imgui.h")
40#include "../src/imgui.h"
41#include "../src/imgui_impl_glfw_gl3.h"
43#include "DebugGUI/imgui.h"
44#include "DebugGUI/imgui_impl_glfw_gl3.h"
46#include <DebugGUI/DebugGUI.h>
59int32_t GPUDisplayFrontendGlfw::GetKey(int32_t
key)
61 if (
key == GLFW_KEY_KP_SUBTRACT) {
64 if (
key == GLFW_KEY_KP_ADD) {
67 if (
key == GLFW_KEY_LEFT_SHIFT ||
key == GLFW_KEY_RIGHT_SHIFT) {
70 if (
key == GLFW_KEY_LEFT_ALT) {
73 if (
key == GLFW_KEY_RIGHT_ALT) {
76 if (
key == GLFW_KEY_LEFT_CONTROL) {
79 if (
key == GLFW_KEY_RIGHT_CONTROL) {
82 if (
key == GLFW_KEY_UP) {
85 if (
key == GLFW_KEY_DOWN) {
88 if (
key == GLFW_KEY_LEFT) {
91 if (
key == GLFW_KEY_RIGHT) {
94 if (
key == GLFW_KEY_PAGE_UP) {
97 if (
key == GLFW_KEY_PAGE_DOWN) {
100 if (
key == GLFW_KEY_ESCAPE) {
103 if (
key == GLFW_KEY_SPACE) {
106 if (
key == GLFW_KEY_HOME) {
109 if (
key == GLFW_KEY_END) {
112 if (
key == GLFW_KEY_INSERT) {
115 if (
key == GLFW_KEY_ENTER) {
118 if (
key == GLFW_KEY_F1) {
121 if (
key == GLFW_KEY_F2) {
124 if (
key == GLFW_KEY_F3) {
127 if (
key == GLFW_KEY_F4) {
130 if (
key == GLFW_KEY_F5) {
133 if (
key == GLFW_KEY_F6) {
136 if (
key == GLFW_KEY_F7) {
139 if (
key == GLFW_KEY_F8) {
142 if (
key == GLFW_KEY_F9) {
145 if (
key == GLFW_KEY_F10) {
148 if (
key == GLFW_KEY_F11) {
151 if (
key == GLFW_KEY_F12) {
157void GPUDisplayFrontendGlfw::GetKey(int32_t
key, int32_t scancode, int32_t mods, int32_t& keyOut, int32_t& keyPressOut)
159 int32_t specialKey = GetKey(
key);
160 const char*
str = glfwGetKeyName(
key, scancode);
161 char localeKey =
str ?
str[0] : 0;
162 if ((mods & GLFW_MOD_SHIFT) && localeKey >=
'a' && localeKey <=
'z') {
163 localeKey +=
'A' -
'a';
168 keyOut = keyPressOut = specialKey;
170 keyOut = keyPressOut = (
uint8_t)localeKey;
171 if (keyPressOut >=
'a' && keyPressOut <=
'z') {
172 keyPressOut +=
'A' -
'a';
177void GPUDisplayFrontendGlfw::error_callback(int32_t error,
const char* description) { fprintf(stderr,
"Error: %s\n", description); }
179void GPUDisplayFrontendGlfw::key_callback(GLFWwindow* window, int32_t
key, int32_t scancode, int32_t action, int32_t mods)
181 int32_t handleKey = 0, keyPress = 0;
182 GetKey(
key, scancode, mods, handleKey, keyPress);
183 if (handleKey < 32) {
184 if (action == GLFW_PRESS) {
185 me->mKeys[keyPress] =
true;
186 me->mKeysShift[keyPress] = mods & GLFW_MOD_SHIFT;
187 me->HandleKey(handleKey);
188 }
else if (action == GLFW_RELEASE) {
189 me->mKeys[keyPress] =
false;
190 me->mKeysShift[keyPress] =
false;
192 }
else if (handleKey < 256) {
193 if (action == GLFW_PRESS) {
194 me->mLastKeyDown = handleKey;
195 }
else if (action == GLFW_RELEASE) {
196 keyPress = (
uint8_t)
me->mKeyDownMap[handleKey];
197 me->mKeys[keyPress] =
false;
198 me->mKeysShift[keyPress] =
false;
203void GPUDisplayFrontendGlfw::char_callback(GLFWwindow* window, uint32_t codepoint)
206 if (codepoint < 256) {
208 if (keyPress >=
'a' && keyPress <=
'z') {
209 keyPress +=
'A' -
'a';
211 me->mKeyDownMap[
me->mLastKeyDown] = keyPress;
212 me->mKeys[keyPress] =
true;
214 me->HandleKey(codepoint);
218void GPUDisplayFrontendGlfw::mouseButton_callback(GLFWwindow* window, int32_t button, int32_t action, int32_t mods)
220 if (action == GLFW_PRESS) {
223 }
else if (button == 1) {
224 me->mMouseDnR =
true;
226 me->mMouseDnX =
me->mMouseMvX;
227 me->mMouseDnY =
me->mMouseMvY;
228 }
else if (action == GLFW_RELEASE) {
230 me->mMouseDn =
false;
231 }
else if (button == 1) {
232 me->mMouseDnR =
false;
237void GPUDisplayFrontendGlfw::scroll_callback(GLFWwindow* window,
double x,
double y) {
me->mMouseWheel +=
y * 100; }
239void GPUDisplayFrontendGlfw::cursorPos_callback(GLFWwindow* window,
double x,
double y)
245void GPUDisplayFrontendGlfw::resize_callback(GLFWwindow* window, int32_t
width, int32_t
height) {
me->ResizeScene(
width,
height); }
248void GPUDisplayFrontendGlfw::DisplayLoop()
250 ImGui::SetNextWindowPos(ImVec2(0, 0));
251 ImGui::SetNextWindowSize(ImVec2(
me->mDisplayWidth,
me->mDisplayHeight));
252 ImGui::SetNextWindowBgAlpha(0.f);
253 ImGui::Begin(
"Console",
nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
259int32_t GPUDisplayFrontendGlfw::FrontendMain()
264 fprintf(stderr,
"Error initializing glfw\n");
267 glfwSetErrorCallback(error_callback);
269 glfwWindowHint(GLFW_MAXIMIZED, 1);
271 glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
276 glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, 0);
277 glfwWindowHint(GLFW_OPENGL_PROFILE,
mBackend->
CoreProfile() ? GLFW_OPENGL_CORE_PROFILE : GLFW_OPENGL_COMPAT_PROFILE);
284 fprintf(stderr,
"Error creating glfw window\n");
289 glfwMakeContextCurrent(mWindow);
292 glfwSetKeyCallback(mWindow, key_callback);
293 glfwSetCharCallback(mWindow, char_callback);
294 glfwSetMouseButtonCallback(mWindow, mouseButton_callback);
295 glfwSetScrollCallback(mWindow, scroll_callback);
296 glfwSetCursorPosCallback(mWindow, cursorPos_callback);
297 glfwSetWindowSizeCallback(mWindow, resize_callback);
302 pthread_mutex_lock(&mSemLockExit);
304 pthread_mutex_unlock(&mSemLockExit);
307 fprintf(stderr,
"Error initializing GL extension wrapper\n");
311#if defined(GPUCA_O2_LIB) && !defined(GPUCA_DISPLAY_GL3W)
313 fprintf(stderr,
"Error initializing gl3w (2)\n");
328 fprintf(stderr,
"Error in GLFW display initialization\n");
334 ImGui_ImplGlfwGL3_Init(mWindow,
false);
335 while (o2::framework::pollGUI(mWindow, DisplayLoop)) {
340 while (!glfwWindowShouldClose(mWindow)) {
343 fprintf(stderr,
"Error drawing GL scene\n");
347 glfwSwapBuffers(mWindow);
355 pthread_mutex_lock(&mSemLockExit);
358 ImGui_ImplGlfwGL3_Shutdown();
361 glfwDestroyWindow(mWindow);
363 mGlfwRunning =
false;
364 pthread_mutex_unlock(&mSemLockExit);
371 pthread_mutex_lock(&mSemLockExit);
373 glfwSetWindowShouldClose(mWindow,
true);
375 pthread_mutex_unlock(&mSemLockExit);
376 while (mGlfwRunning) {
386 y = ImGui::GetWindowHeight() -
y;
389 ImGui::SetCursorPos(ImVec2(
x,
y));
390 ImGui::TextColored(ImVec4(
r,
g,
b,
a),
"%s", s);
397 GPUInfo(
"Setting Full Screen %d", (int32_t)set);
399 glfwGetWindowPos(mWindow, &mWindowX, &mWindowY);
400 glfwGetWindowSize(mWindow, &mWindowWidth, &mWindowHeight);
401 GLFWmonitor* primary = glfwGetPrimaryMonitor();
402 const GLFWvidmode*
mode = glfwGetVideoMode(primary);
403 glfwSetWindowMonitor(mWindow, primary, 0, 0,
mode->width,
mode->height,
mode->refreshRate);
405 glfwSetWindowMonitor(mWindow,
nullptr, mWindowX, mWindowY, mWindowWidth, mWindowHeight, GLFW_DONT_CARE);
412 glfwMaximizeWindow(mWindow);
414 glfwRestoreWindow(mWindow);
424 GPUError(
"Coult not Create GL Thread...");
446#ifdef GPUCA_BUILD_EVENT_DISPLAY_VULKAN
447 return glfwCreateWindowSurface(*(VkInstance*)instance, mWindow,
nullptr, (VkSurfaceKHR*)surface) != VK_SUCCESS;
455 uint32_t glfwExtensionCount = 0;
456#ifdef GPUCA_BUILD_EVENT_DISPLAY_VULKAN
457 p = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
459 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 StartDisplay() override
int32_t & drawTextFontSize()
static constexpr int32_t KEY_F9
const char * mFrontendName
static constexpr int32_t KEY_F2
static void * FrontendThreadWrapper(void *)
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