diff options
Diffstat (limited to '3rdparty/bgfx/examples/common/entry')
-rw-r--r-- | 3rdparty/bgfx/examples/common/entry/entry.cpp | 3 | ||||
-rw-r--r-- | 3rdparty/bgfx/examples/common/entry/entry_glfw.cpp | 77 | ||||
-rw-r--r-- | 3rdparty/bgfx/examples/common/entry/entry_p.h | 4 | ||||
-rw-r--r-- | 3rdparty/bgfx/examples/common/entry/entry_sdl.cpp | 92 | ||||
-rw-r--r-- | 3rdparty/bgfx/examples/common/entry/entry_windows.cpp | 8 |
5 files changed, 62 insertions, 122 deletions
diff --git a/3rdparty/bgfx/examples/common/entry/entry.cpp b/3rdparty/bgfx/examples/common/entry/entry.cpp index 07621f3cd25..dc3e97488ea 100644 --- a/3rdparty/bgfx/examples/common/entry/entry.cpp +++ b/3rdparty/bgfx/examples/common/entry/entry.cpp @@ -767,6 +767,7 @@ restart: handle = size->m_handle; _width = size->m_width; _height = size->m_height; + BX_TRACE("Window resize event: %d: %dx%d", handle, _width, _height); needReset = true; } @@ -800,6 +801,7 @@ restart: && needReset) { _reset = s_reset; + BX_TRACE("bgfx::reset(%d, %d, 0x%x)", _width, _height, _reset) bgfx::reset(_width, _height, _reset); inputSetMouseResolution(uint16_t(_width), uint16_t(_height) ); } @@ -979,6 +981,7 @@ restart: if (needReset) { _reset = s_reset; + BX_TRACE("bgfx::reset(%d, %d, 0x%x)", s_window[0].m_width, s_window[0].m_height, _reset) bgfx::reset(s_window[0].m_width, s_window[0].m_height, _reset); inputSetMouseResolution(uint16_t(s_window[0].m_width), uint16_t(s_window[0].m_height) ); } diff --git a/3rdparty/bgfx/examples/common/entry/entry_glfw.cpp b/3rdparty/bgfx/examples/common/entry/entry_glfw.cpp index d27745d1390..4c699f23a5e 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_glfw.cpp +++ b/3rdparty/bgfx/examples/common/entry/entry_glfw.cpp @@ -15,13 +15,9 @@ #endif // GLFW_VERSION_MINOR < 2 #if BX_PLATFORM_LINUX || BX_PLATFORM_BSD -# if ENTRY_CONFIG_USE_WAYLAND -# include <wayland-egl.h> -# define GLFW_EXPOSE_NATIVE_WAYLAND -# else -# define GLFW_EXPOSE_NATIVE_X11 -# define GLFW_EXPOSE_NATIVE_GLX -# endif +# define GLFW_EXPOSE_NATIVE_WAYLAND +# define GLFW_EXPOSE_NATIVE_X11 +# define GLFW_EXPOSE_NATIVE_GLX #elif BX_PLATFORM_OSX # define GLFW_EXPOSE_NATIVE_COCOA # define GLFW_EXPOSE_NATIVE_NSGL @@ -45,22 +41,14 @@ namespace entry static void* glfwNativeWindowHandle(GLFWwindow* _window) { # if BX_PLATFORM_LINUX || BX_PLATFORM_BSD -# if ENTRY_CONFIG_USE_WAYLAND - wl_egl_window *win_impl = (wl_egl_window*)glfwGetWindowUserPointer(_window); - if(!win_impl) + if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND) + { + return glfwGetWaylandWindow(_window); + } + else { - int width, height; - glfwGetWindowSize(_window, &width, &height); - struct wl_surface* surface = (struct wl_surface*)glfwGetWaylandWindow(_window); - if(!surface) - return nullptr; - win_impl = wl_egl_window_create(surface, width, height); - glfwSetWindowUserPointer(_window, (void*)(uintptr_t)win_impl); + return (void*)(uintptr_t)glfwGetX11Window(_window); } - return (void*)(uintptr_t)win_impl; -# else - return (void*)(uintptr_t)glfwGetX11Window(_window); -# endif # elif BX_PLATFORM_OSX return glfwGetCocoaWindow(_window); # elif BX_PLATFORM_WINDOWS @@ -68,23 +56,6 @@ namespace entry # endif // BX_PLATFORM_ } - static void glfwDestroyWindowImpl(GLFWwindow *_window) - { - if(!_window) - return; -# if BX_PLATFORM_LINUX || BX_PLATFORM_BSD -# if ENTRY_CONFIG_USE_WAYLAND - wl_egl_window *win_impl = (wl_egl_window*)glfwGetWindowUserPointer(_window); - if(win_impl) - { - glfwSetWindowUserPointer(_window, nullptr); - wl_egl_window_destroy(win_impl); - } -# endif -# endif - glfwDestroyWindow(_window); - } - static uint8_t translateKeyModifiers(int _glfw) { uint8_t modifiers = 0; @@ -525,7 +496,7 @@ namespace entry { GLFWwindow* window = m_window[msg->m_handle.idx]; m_eventQueue.postWindowEvent(msg->m_handle); - glfwDestroyWindowImpl(window); + glfwDestroyWindow(window); m_window[msg->m_handle.idx] = NULL; } } @@ -617,7 +588,7 @@ namespace entry m_eventQueue.postExitEvent(); m_thread.shutdown(); - glfwDestroyWindowImpl(m_window[0]); + glfwDestroyWindow(m_window[0]); glfwTerminate(); return m_thread.getExitCode(); @@ -865,11 +836,14 @@ namespace entry void* getNativeDisplayHandle() { # if BX_PLATFORM_LINUX || BX_PLATFORM_BSD -# if ENTRY_CONFIG_USE_WAYLAND - return glfwGetWaylandDisplay(); -# else - return glfwGetX11Display(); -# endif // ENTRY_CONFIG_USE_WAYLAND + if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND) + { + return glfwGetWaylandDisplay(); + } + else + { + return glfwGetX11Display(); + } # else return NULL; # endif // BX_PLATFORM_* @@ -878,11 +852,14 @@ namespace entry bgfx::NativeWindowHandleType::Enum getNativeWindowHandleType(WindowHandle _handle) { # if BX_PLATFORM_LINUX || BX_PLATFORM_BSD -# if ENTRY_CONFIG_USE_WAYLAND - return bgfx::NativeWindowHandleType::Wayland; -# else - return bgfx::NativeWindowHandleType::Default; -# endif // ENTRY_CONFIG_USE_WAYLAND + if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND) + { + return bgfx::NativeWindowHandleType::Wayland; + } + else + { + return bgfx::NativeWindowHandleType::Default; + } # else return bgfx::NativeWindowHandleType::Default; # endif // BX_PLATFORM_* diff --git a/3rdparty/bgfx/examples/common/entry/entry_p.h b/3rdparty/bgfx/examples/common/entry/entry_p.h index 59307c2f040..3c01e3459c8 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_p.h +++ b/3rdparty/bgfx/examples/common/entry/entry_p.h @@ -25,10 +25,6 @@ # define ENTRY_CONFIG_USE_GLFW 0 #endif // ENTRY_CONFIG_USE_GLFW -#ifndef ENTRY_CONFIG_USE_WAYLAND -# define ENTRY_CONFIG_USE_WAYLAND 0 -#endif // ENTRY_CONFIG_USE_WAYLAND - #if !defined(ENTRY_CONFIG_USE_NATIVE) \ && !ENTRY_CONFIG_USE_NOOP \ && !ENTRY_CONFIG_USE_SDL \ diff --git a/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp b/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp index 5a862c0ca05..bbcdb069257 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp +++ b/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp @@ -8,9 +8,6 @@ #if ENTRY_CONFIG_USE_SDL #if BX_PLATFORM_LINUX || BX_PLATFORM_BSD -# if ENTRY_CONFIG_USE_WAYLAND -# include <wayland-egl.h> -# endif #elif BX_PLATFORM_WINDOWS # define SDL_MAIN_HANDLED #endif @@ -49,25 +46,14 @@ namespace entry } # if BX_PLATFORM_LINUX || BX_PLATFORM_BSD -# if ENTRY_CONFIG_USE_WAYLAND - if (wmi.subsystem == SDL_SYSWM_WAYLAND) - { - wl_egl_window *win_impl = (wl_egl_window*)SDL_GetWindowData(_window, "wl_egl_window"); - if(!win_impl) - { - int width, height; - SDL_GetWindowSize(_window, &width, &height); - struct wl_surface* surface = wmi.info.wl.surface; - if(!surface) - return nullptr; - win_impl = wl_egl_window_create(surface, width, height); - SDL_SetWindowData(_window, "wl_egl_window", win_impl); - } - return (void*)(uintptr_t)win_impl; - } - else -# endif // ENTRY_CONFIG_USE_WAYLAND - return (void*)wmi.info.x11.window; + if (wmi.subsystem == SDL_SYSWM_WAYLAND) + { + return (void*)wmi.info.wl.surface; + } + else + { + return (void*)wmi.info.x11.window; + } # elif BX_PLATFORM_OSX || BX_PLATFORM_IOS return wmi.info.cocoa.window; # elif BX_PLATFORM_WINDOWS @@ -77,23 +63,6 @@ namespace entry # endif // BX_PLATFORM_ } - static void sdlDestroyWindow(SDL_Window* _window) - { - if(!_window) - return; -# if BX_PLATFORM_LINUX || BX_PLATFORM_BSD -# if ENTRY_CONFIG_USE_WAYLAND - wl_egl_window *win_impl = (wl_egl_window*)SDL_GetWindowData(_window, "wl_egl_window"); - if(win_impl) - { - SDL_SetWindowData(_window, "wl_egl_window", nullptr); - wl_egl_window_destroy(win_impl); - } -# endif -# endif - SDL_DestroyWindow(_window); - } - static uint8_t translateKeyModifiers(uint16_t _sdl) { uint8_t modifiers = 0; @@ -493,7 +462,7 @@ namespace entry // Force window resolution... WindowHandle defaultWindow = { 0 }; - setWindowSize(defaultWindow, m_width, m_height, true); + entry::setWindowSize(defaultWindow, m_width, m_height); SDL_EventState(SDL_DROPFILE, SDL_ENABLE); @@ -671,7 +640,15 @@ namespace entry case SDL_WINDOWEVENT_SIZE_CHANGED: { WindowHandle handle = findHandle(wev.windowID); - setWindowSize(handle, wev.data1, wev.data2); + uint32_t width = wev.data1; + uint32_t height = wev.data2; + if (width != m_width + || height != m_height) + { + m_width = width; + m_height = height; + m_eventQueue.postSizeEvent(handle, m_width, m_height); + } } break; @@ -865,7 +842,7 @@ namespace entry if (isValid(handle) ) { m_eventQueue.postWindowEvent(handle); - sdlDestroyWindow(m_window[handle.idx]); + SDL_DestroyWindow(m_window[handle.idx]); m_window[handle.idx] = NULL; } } @@ -916,7 +893,7 @@ namespace entry Msg* msg = (Msg*)uev.data2; if (isValid(handle) ) { - setWindowSize(handle, msg->m_width, msg->m_height); + SDL_SetWindowSize(m_window[handle.idx], msg->m_width, msg->m_height); } delete msg; } @@ -959,7 +936,7 @@ namespace entry while (bgfx::RenderFrame::NoContext != bgfx::renderFrame() ) {}; m_thread.shutdown(); - sdlDestroyWindow(m_window[0]); + SDL_DestroyWindow(m_window[0]); SDL_Quit(); return m_thread.getExitCode(); @@ -988,20 +965,6 @@ namespace entry return invalid; } - void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height, bool _force = false) - { - if (_width != m_width - || _height != m_height - || _force) - { - m_width = _width; - m_height = _height; - - SDL_SetWindowSize(m_window[_handle.idx], m_width, m_height); - m_eventQueue.postSizeEvent(_handle, m_width, m_height); - } - } - GamepadHandle findGamepad(SDL_JoystickID _jid) { for (uint32_t ii = 0, num = m_gamepadAlloc.getNumHandles(); ii < num; ++ii) @@ -1102,6 +1065,7 @@ namespace entry void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height) { + // Function to set the window size programmatically from the examples/tools. Msg* msg = new Msg; msg->m_width = _width; msg->m_height = _height; @@ -1149,12 +1113,10 @@ namespace entry return NULL; } # if BX_PLATFORM_LINUX || BX_PLATFORM_BSD -# if ENTRY_CONFIG_USE_WAYLAND - if (wmi.subsystem == SDL_SYSWM_WAYLAND) - return wmi.info.wl.display; - else -# endif // ENTRY_CONFIG_USE_WAYLAND - return wmi.info.x11.display; + if (wmi.subsystem == SDL_SYSWM_WAYLAND) + return wmi.info.wl.display; + else + return wmi.info.x11.display; # else return NULL; # endif // BX_PLATFORM_* @@ -1169,11 +1131,9 @@ namespace entry return bgfx::NativeWindowHandleType::Default; } # if BX_PLATFORM_LINUX || BX_PLATFORM_BSD -# if ENTRY_CONFIG_USE_WAYLAND if (wmi.subsystem == SDL_SYSWM_WAYLAND) return bgfx::NativeWindowHandleType::Wayland; else -# endif // ENTRY_CONFIG_USE_WAYLAND return bgfx::NativeWindowHandleType::Default; # else return bgfx::NativeWindowHandleType::Default; diff --git a/3rdparty/bgfx/examples/common/entry/entry_windows.cpp b/3rdparty/bgfx/examples/common/entry/entry_windows.cpp index 754039a6db7..e731977737e 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_windows.cpp +++ b/3rdparty/bgfx/examples/common/entry/entry_windows.cpp @@ -851,14 +851,18 @@ namespace entry if (utf16[0] >= 0xD800 && utf16[0] <= 0xDBFF) { m_surrogate = utf16[0]; - } else { + } + else + { int utf16_len; if (utf16[0] >= 0xDC00 && utf16[0] <= 0xDFFF) { utf16[1] = utf16[0]; utf16[0] = m_surrogate; m_surrogate = 0; utf16_len = 2; - } else { + } + else + { utf16_len = 1; } |