diff options
author | 2019-10-13 13:50:38 +0200 | |
---|---|---|
committer | 2019-10-13 07:50:38 -0400 | |
commit | 0837e7451a84f95c29dbdb9bd6b8b931fee1635d (patch) | |
tree | 626bcbd250a7fbebdf5958a288d2f438d4f9fb5a /3rdparty/bgfx/examples/common/entry | |
parent | c913ccb59d713ce0b91135520719ac5385e54358 (diff) |
WIP: sync bgfx, bx and bimg with latest upstream (#5723)
* Sync with bgfx upstream revision b91d0b6
* Sync with bx upstream revision d60912b
* Sync with bimg upstream revision bd81f60
* Add astc-codec decoder
* Rename VertexDecl to VertexLayout
* Rename UniformType enum Int1 to Sampler.
* Add NVN stub
* Fix unused-const-variable error on macOS
* Drop redundant explicit language parameters
buildoptions_cpp are only applied to c++ files and buildoptions_objcpp are only
applied to objective c++ files. As such, hardcoding -x offers no benefit while
preventing overrides (such as one needed by 3rdparty/bgfx/src/renderer_vk.cpp on
macOS) from working.
* Re-introduce -x c++ in places where C code is compiled as C++ to prevent clang from throwing a warning
* Build bgfx as Objective-C++ on macOS
It is needed due to included headers
* Enable Direct3D12 and Vulkan bgfx rendering backends
* Enable building of spirv shaders
* Properly escape /c in cmd call
* Comment out dx12 bgfx renderer
* Honor VERBOSE setting during shaders build
* Only invert hlsl shader XYZ_TO_sRGB matrix for opengl
* Add spirv shaders
* OpenGL ES needs transposed matrix too
* Metal needs transposed matrix as well
Diffstat (limited to '3rdparty/bgfx/examples/common/entry')
21 files changed, 739 insertions, 228 deletions
diff --git a/3rdparty/bgfx/examples/common/entry/cmd.cpp b/3rdparty/bgfx/examples/common/entry/cmd.cpp index 4c68be9b51c..ae30eec6c93 100644 --- a/3rdparty/bgfx/examples/common/entry/cmd.cpp +++ b/3rdparty/bgfx/examples/common/entry/cmd.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 Branimir Karadzic. All rights reserved. + * Copyright 2010-2019 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ diff --git a/3rdparty/bgfx/examples/common/entry/cmd.h b/3rdparty/bgfx/examples/common/entry/cmd.h index 27523d153c0..df3483ba88d 100644 --- a/3rdparty/bgfx/examples/common/entry/cmd.h +++ b/3rdparty/bgfx/examples/common/entry/cmd.h @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 Branimir Karadzic. All rights reserved. + * Copyright 2010-2019 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ diff --git a/3rdparty/bgfx/examples/common/entry/dbg.h b/3rdparty/bgfx/examples/common/entry/dbg.h index 2a50e7a5813..86c3f59e03e 100644 --- a/3rdparty/bgfx/examples/common/entry/dbg.h +++ b/3rdparty/bgfx/examples/common/entry/dbg.h @@ -1,5 +1,5 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. + * Copyright 2011-2019 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ diff --git a/3rdparty/bgfx/examples/common/entry/dialog.cpp b/3rdparty/bgfx/examples/common/entry/dialog.cpp new file mode 100644 index 00000000000..a651df7f03a --- /dev/null +++ b/3rdparty/bgfx/examples/common/entry/dialog.cpp @@ -0,0 +1,234 @@ +/* + * Copyright 2010-2019 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + */ + +#include <bx/allocator.h> +#include <bx/filepath.h> +#include <bx/string.h> +#include <bx/readerwriter.h> +#include <bx/process.h> + +#include "dialog.h" + +#if BX_PLATFORM_WINDOWS +typedef uintptr_t (__stdcall *LPOFNHOOKPROC)(void*, uint32_t, uintptr_t, uint64_t); + +struct OPENFILENAMEA +{ + uint32_t structSize; + void* hwndOwner; + void* hinstance; + const char* filter; + const char* customFilter; + uint32_t maxCustomFilter; + uint32_t filterIndex; + const char* file; + uint32_t maxFile; + const char* fileTitle; + uint32_t maxFileTitle; + const char* initialDir; + const char* title; + uint32_t flags; + uint16_t fileOffset; + uint16_t fileExtension; + const char* defExt; + uintptr_t customData; + LPOFNHOOKPROC hook; + const char* templateName; + void* reserved0; + uint32_t reserved1; + uint32_t flagsEx; +}; + +extern "C" bool __stdcall GetOpenFileNameA(OPENFILENAMEA* _ofn); +extern "C" void* __stdcall GetModuleHandleA(const char* _moduleName); +extern "C" uint32_t __stdcall GetModuleFileNameA(void* _module, char* _outFilePath, uint32_t _size); +extern "C" void* __stdcall ShellExecuteA(void* _hwnd, void* _operation, void* _file, void* _parameters, void* _directory, int32_t _showCmd); + +#endif // BX_PLATFORM_WINDOWS + +void openUrl(const bx::StringView& _url) +{ + char tmp[4096]; + +#if BX_PLATFORM_WINDOWS +# define OPEN "" +#elif BX_PLATFORM_OSX +# define OPEN "open " +#else +# define OPEN "xdg-open " +#endif // BX_PLATFORM_OSX + + bx::snprintf(tmp, BX_COUNTOF(tmp), OPEN "%.*s", _url.getLength(), _url.getPtr() ); + +#undef OPEN + +#if BX_PLATFORM_WINDOWS + void* result = ShellExecuteA(NULL, NULL, tmp, NULL, NULL, false); + BX_UNUSED(result); +#elif !BX_PLATFORM_IOS + int32_t result = system(tmp); + BX_UNUSED(result); +#endif // BX_PLATFORM_* +} + +class Split +{ +public: + Split(const bx::StringView& _str, char _ch) + : m_str(_str) + , m_token(_str.getPtr(), bx::strFind(_str, _ch).getPtr() ) + , m_ch(_ch) + { + } + + bx::StringView next() + { + bx::StringView result = m_token; + m_token = bx::strTrim( + bx::StringView(m_token.getTerm()+1, bx::strFind(bx::StringView(m_token.getTerm()+1, m_str.getTerm() ), m_ch).getPtr() ) + , " \t\n" + ); + return result; + } + + bool isDone() const + { + return m_token.isEmpty(); + } + +private: + const bx::StringView& m_str; + bx::StringView m_token; + char m_ch; +}; + +#if !BX_PLATFORM_OSX +bool openFileSelectionDialog( + bx::FilePath& _inOutFilePath + , FileSelectionDialogType::Enum _type + , const bx::StringView& _title + , const bx::StringView& _filter + ) +{ +#if BX_PLATFORM_LINUX + char tmp[4096]; + bx::StaticMemoryBlockWriter writer(tmp, sizeof(tmp) ); + + bx::Error err; + bx::write(&writer, &err + , "--file-selection%s --title \"%.*s\" --filename \"%s\"" + , FileSelectionDialogType::Save == _type ? " --save" : "" + , _title.getLength() + , _title.getPtr() + , _inOutFilePath.getCPtr() + ); + + for (bx::LineReader lr(_filter); !lr.isDone();) + { + const bx::StringView line = lr.next(); + + bx::write(&writer, &err + , " --file-filter \"%.*s\"" + , line.getLength() + , line.getPtr() + ); + } + + bx::write(&writer, '\0', &err); + + if (err.isOk() ) + { + bx::ProcessReader pr; + + if (bx::open(&pr, "zenity", tmp, &err) ) + { + char buffer[1024]; + int32_t total = bx::read(&pr, buffer, sizeof(buffer), &err); + bx::close(&pr); + + if (0 == pr.getExitCode() ) + { + _inOutFilePath.set(bx::strRTrim(bx::StringView(buffer, total), "\n\r") ); + return true; + } + } + } +#elif BX_PLATFORM_WINDOWS + BX_UNUSED(_type); + + char out[bx::kMaxFilePath] = { '\0' }; + + OPENFILENAMEA ofn; + bx::memSet(&ofn, 0, sizeof(ofn) ); + ofn.structSize = sizeof(OPENFILENAMEA); + ofn.initialDir = _inOutFilePath.getCPtr(); + ofn.file = out; + ofn.maxFile = sizeof(out); + ofn.flags = 0 + | /* OFN_EXPLORER */ 0x00080000 + | /* OFN_FILEMUSTEXIST */ 0x00001000 + | /* OFN_DONTADDTORECENT */ 0x02000000 + ; + + char tmp[4096]; + bx::StaticMemoryBlockWriter writer(tmp, sizeof(tmp) ); + + bx::Error err; + + ofn.title = tmp; + bx::write(&writer, &err, "%.*s", _title.getLength(), _title.getPtr() ); + bx::write(&writer, '\0', &err); + + ofn.filter = tmp + uint32_t(bx::seek(&writer) ); + + for (bx::LineReader lr(_filter); !lr.isDone() && err.isOk();) + { + const bx::StringView line = lr.next(); + const bx::StringView sep = bx::strFind(line, '|'); + + if (!sep.isEmpty() ) + { + bx::write(&writer, bx::strTrim(bx::StringView(line.getPtr(), sep.getPtr() ), " "), &err); + bx::write(&writer, '\0', &err); + + bool first = true; + + for (Split split(bx::strTrim(bx::StringView(sep.getPtr()+1, line.getTerm() ), " "), ' '); !split.isDone() && err.isOk();) + { + const bx::StringView token = split.next(); + if (!first) + { + bx::write(&writer, ';', &err); + } + + first = false; + bx::write(&writer, token, &err); + } + + bx::write(&writer, '\0', &err); + } + else + { + bx::write(&writer, line, &err); + bx::write(&writer, '\0', &err); + bx::write(&writer, '\0', &err); + } + } + + bx::write(&writer, '\0', &err); + + if (err.isOk() + && GetOpenFileNameA(&ofn) ) + { + _inOutFilePath.set(ofn.file); + return true; + } +#else + BX_UNUSED(_inOutFilePath, _type, _title, _filter); +#endif // BX_PLATFORM_LINUX + + return false; +} +#endif // !BX_PLATFORM_OSX diff --git a/3rdparty/bgfx/examples/common/entry/dialog.h b/3rdparty/bgfx/examples/common/entry/dialog.h new file mode 100644 index 00000000000..4a75951ac45 --- /dev/null +++ b/3rdparty/bgfx/examples/common/entry/dialog.h @@ -0,0 +1,33 @@ +/* + * Copyright 2010-2019 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + */ + +#ifndef DIALOG_H_HEADER_GUARD +#define DIALOG_H_HEADER_GUARD + +namespace bx { class FilePath; class StringView; } + +struct FileSelectionDialogType +{ + enum Enum + { + Open, + Save, + + Count + }; +}; + +/// +bool openFileSelectionDialog( + bx::FilePath& _inOutFilePath + , FileSelectionDialogType::Enum _type + , const bx::StringView& _title + , const bx::StringView& _filter = "All Files | *" + ); + +/// +void openUrl(const bx::StringView& _url); + +#endif // DIALOG_H_HEADER_GUARD diff --git a/3rdparty/bgfx/examples/common/entry/dialog_darwin.mm b/3rdparty/bgfx/examples/common/entry/dialog_darwin.mm new file mode 100644 index 00000000000..97e60e5fce6 --- /dev/null +++ b/3rdparty/bgfx/examples/common/entry/dialog_darwin.mm @@ -0,0 +1,135 @@ +/* + * Copyright 2019-2019 Attila Kocsis. All rights reserved. + * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + */ + +#include "entry_p.h" +#if BX_PLATFORM_OSX + +#include <bx/allocator.h> +#include <bx/filepath.h> +#include <bx/string.h> +#include <bx/readerwriter.h> +#include <bx/process.h> +#include <bx/semaphore.h> + +#import <AppKit/AppKit.h> + +#include "dialog.h" + +class Split +{ +public: + Split(const bx::StringView& _str, char _ch) + : m_str(_str) + , m_token(_str.getPtr(), bx::strFind(_str, _ch).getPtr() ) + , m_ch(_ch) + { + } + + bx::StringView next() + { + bx::StringView result = m_token; + m_token = bx::strTrim( + bx::StringView(m_token.getTerm()+1 + , bx::strFind(bx::StringView(m_token.getTerm()+1, m_str.getTerm() ), m_ch).getPtr() ) + , " \t\n" + ); + return result; + } + + bool isDone() const + { + return m_token.isEmpty(); + } + +private: + const bx::StringView& m_str; + bx::StringView m_token; + char m_ch; +}; + + +bool openFileSelectionDialog( + bx::FilePath& _inOutFilePath + , FileSelectionDialogType::Enum _type + , const bx::StringView& _title + , const bx::StringView& _filter + ) +{ + NSMutableArray* fileTypes = [NSMutableArray arrayWithCapacity:10]; + bx::Error err; + + for (bx::LineReader lr(_filter); !lr.isDone() && err.isOk();) + { + const bx::StringView line = lr.next(); + const bx::StringView sep = bx::strFind(line, '|'); + + if (!sep.isEmpty() ) + { + for (Split split(bx::strTrim(bx::StringView(sep.getPtr()+1, line.getTerm() ), " "), ' '); !split.isDone() && err.isOk();) + { + const bx::StringView token = split.next(); + + if ( token.getLength() >= 3 && token.getPtr()[0] == '*' + && token.getPtr()[1] == '.' && bx::isAlphaNum(token.getPtr()[2]) ) + { + NSString* extension = [[NSString alloc] initWithBytes:token.getPtr()+2 length:token.getLength()-2 encoding:NSASCIIStringEncoding]; + [fileTypes addObject: extension]; + } + } + } + } + + __block NSString* fileName = nil; + bx::Semaphore semaphore; + bx::Semaphore* psemaphore = &semaphore; + + CFRunLoopPerformBlock([[NSRunLoop mainRunLoop] getCFRunLoop], + kCFRunLoopCommonModes, + ^{ + NSSavePanel* panel = nil; + + if ( FileSelectionDialogType::Open == _type) + { + NSOpenPanel* openPanel = [NSOpenPanel openPanel]; + openPanel.canChooseFiles = TRUE; + openPanel.allowsMultipleSelection = FALSE; + openPanel.canChooseDirectories = FALSE; + panel = openPanel; + } + else + { + panel = [NSSavePanel savePanel]; + } + + panel.message = [[NSString alloc] initWithBytes:_title.getPtr() length:_title.getLength() encoding:NSASCIIStringEncoding]; + panel.directoryURL = [NSURL URLWithString:@(_inOutFilePath.getCPtr())]; + panel.allowedFileTypes = fileTypes; + + if ([panel runModal] == NSModalResponseOK) + { + NSURL* url = [panel URL]; + if (nil != url) + { + fileName = [url path]; + [fileName retain]; + } + } + [panel close]; + psemaphore->post(); + }); + + semaphore.wait(); + + if ( fileName != nil ) + { + _inOutFilePath.set([fileName UTF8String]); + [fileName release]; + return true; + } + + return false; +} + +#endif diff --git a/3rdparty/bgfx/examples/common/entry/entry.cpp b/3rdparty/bgfx/examples/common/entry/entry.cpp index 44c9dfd604b..98b1a40577e 100644 --- a/3rdparty/bgfx/examples/common/entry/entry.cpp +++ b/3rdparty/bgfx/examples/common/entry/entry.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. + * Copyright 2011-2019 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ @@ -46,7 +46,7 @@ namespace entry virtual bool open(const bx::FilePath& _filePath, bx::Error* _err) override { String filePath(s_currentDir); - filePath.append(_filePath.get() ); + filePath.append(_filePath); return super::open(filePath.getPtr(), _err); } }; @@ -59,7 +59,7 @@ namespace entry virtual bool open(const bx::FilePath& _filePath, bool _append, bx::Error* _err) override { String filePath(s_currentDir); - filePath.append(_filePath.get() ); + filePath.append(_filePath); return super::open(filePath.getPtr(), _append, _err); } }; @@ -446,10 +446,11 @@ BX_PRAGMA_DIAGNOSTIC_POP(); return bx::kExitFailure; } - AppI::AppI(const char* _name, const char* _description) + AppI::AppI(const char* _name, const char* _description, const char* _url) { m_name = _name; m_description = _description; + m_url = _url; m_next = s_apps; s_apps = this; @@ -490,6 +491,11 @@ BX_PRAGMA_DIAGNOSTIC_POP(); return m_description; } + const char* AppI::getUrl() const + { + return m_url; + } + AppI* AppI::getNext() { return m_next; @@ -752,7 +758,7 @@ restart: case Event::DropFile: { const DropFileEvent* drop = static_cast<const DropFileEvent*>(ev); - DBG("%s", drop->m_filePath.get() ); + DBG("%s", drop->m_filePath.getCPtr() ); } break; diff --git a/3rdparty/bgfx/examples/common/entry/entry.h b/3rdparty/bgfx/examples/common/entry/entry.h index 75cbeb26ca3..e5c9a7fd071 100644 --- a/3rdparty/bgfx/examples/common/entry/entry.h +++ b/3rdparty/bgfx/examples/common/entry/entry.h @@ -1,5 +1,5 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. + * Copyright 2011-2019 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ @@ -24,15 +24,15 @@ extern "C" int _main_(int _argc, char** _argv); #endif // ENTRY_CONFIG_IMPLEMENT_MAIN #if ENTRY_CONFIG_IMPLEMENT_MAIN -#define ENTRY_IMPLEMENT_MAIN(_app, _name, _description) \ +#define ENTRY_IMPLEMENT_MAIN(_app, ...) \ int _main_(int _argc, char** _argv) \ { \ - _app app(_name, _description); \ + _app app(__VA_ARGS__); \ return entry::runApp(&app, _argc, _argv); \ } #else -#define ENTRY_IMPLEMENT_MAIN(_app, _name, _description) \ - _app s_ ## _app ## App(_name, _description) +#define ENTRY_IMPLEMENT_MAIN(_app, ...) \ + _app s_ ## _app ## App(__VA_ARGS__) #endif // ENTRY_CONFIG_IMPLEMENT_MAIN namespace entry @@ -282,7 +282,7 @@ namespace entry { public: /// - AppI(const char* _name, const char* _description); + AppI(const char* _name, const char* _description, const char* _url = "https://bkaradzic.github.io/bgfx/index.html"); /// virtual ~AppI() = 0; @@ -303,6 +303,9 @@ namespace entry const char* getDescription() const; /// + const char* getUrl() const; + + /// AppI* getNext(); AppI* m_next; @@ -310,6 +313,7 @@ namespace entry private: const char* m_name; const char* m_description; + const char* m_url; }; /// diff --git a/3rdparty/bgfx/examples/common/entry/entry_android.cpp b/3rdparty/bgfx/examples/common/entry/entry_android.cpp index 644ed4aca4c..f56d649b99d 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_android.cpp +++ b/3rdparty/bgfx/examples/common/entry/entry_android.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. + * Copyright 2011-2019 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ @@ -116,7 +116,7 @@ namespace entry return false; } - m_file = AAssetManager_open(m_assetManager, _filePath.get(), AASSET_MODE_RANDOM); + m_file = AAssetManager_open(m_assetManager, _filePath.getCPtr(), AASSET_MODE_RANDOM); if (NULL == m_file) { BX_ERROR_SET(_err, BX_ERROR_READERWRITER_OPEN, "FileReader: Failed to open file."); diff --git a/3rdparty/bgfx/examples/common/entry/entry_asmjs.cpp b/3rdparty/bgfx/examples/common/entry/entry_asmjs.cpp index 4434e41c9e6..52d25b21cab 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_asmjs.cpp +++ b/3rdparty/bgfx/examples/common/entry/entry_asmjs.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. + * Copyright 2011-2019 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ @@ -303,7 +303,6 @@ namespace entry EM_BOOL Context::focusCb(int eventType, const EmscriptenFocusEvent* event, void* userData) { - printf("focusCb %d", eventType); BX_UNUSED(event, userData); if (event) diff --git a/3rdparty/bgfx/examples/common/entry/entry_glfw.cpp b/3rdparty/bgfx/examples/common/entry/entry_glfw.cpp index 5e81dd9aece..c78ac057099 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_glfw.cpp +++ b/3rdparty/bgfx/examples/common/entry/entry_glfw.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. + * Copyright 2011-2019 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ @@ -15,8 +15,13 @@ #endif // GLFW_VERSION_MINOR < 2 #if BX_PLATFORM_LINUX || BX_PLATFORM_BSD -# define GLFW_EXPOSE_NATIVE_X11 -# define GLFW_EXPOSE_NATIVE_GLX +# 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 #elif BX_PLATFORM_OSX # define GLFW_EXPOSE_NATIVE_COCOA # define GLFW_EXPOSE_NATIVE_NSGL @@ -40,7 +45,22 @@ 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) + { + 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)win_impl; +# else return (void*)(uintptr_t)glfwGetX11Window(_window); +# endif # elif BX_PLATFORM_OSX return glfwGetCocoaWindow(_window); # elif BX_PLATFORM_WINDOWS @@ -48,11 +68,32 @@ 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 void glfwSetWindow(GLFWwindow* _window) { bgfx::PlatformData pd; # if BX_PLATFORM_LINUX || BX_PLATFORM_BSD +# if ENTRY_CONFIG_USE_WAYLAND + pd.ndt = glfwGetWaylandDisplay(); +# else pd.ndt = glfwGetX11Display(); + #endif # elif BX_PLATFORM_OSX pd.ndt = NULL; # elif BX_PLATFORM_WINDOWS @@ -506,7 +547,7 @@ namespace entry { GLFWwindow* window = m_windows[msg->m_handle.idx]; m_eventQueue.postWindowEvent(msg->m_handle); - glfwDestroyWindow(window); + glfwDestroyWindowImpl(window); m_windows[msg->m_handle.idx] = NULL; } } @@ -598,7 +639,7 @@ namespace entry m_eventQueue.postExitEvent(); m_thread.shutdown(); - glfwDestroyWindow(m_windows[0]); + glfwDestroyWindowImpl(m_windows[0]); glfwTerminate(); return m_thread.getExitCode(); diff --git a/3rdparty/bgfx/examples/common/entry/entry_ios.mm b/3rdparty/bgfx/examples/common/entry/entry_ios.mm index 569e99f51bd..06a90f7a3e7 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_ios.mm +++ b/3rdparty/bgfx/examples/common/entry/entry_ios.mm @@ -1,5 +1,5 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. + * Copyright 2011-2019 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ @@ -14,7 +14,7 @@ #if __IPHONE_8_0 && !TARGET_IPHONE_SIMULATOR // check if sdk/target supports metal # import <Metal/Metal.h> # import <QuartzCore/CAMetalLayer.h> -//# define HAS_METAL_SDK +# define HAS_METAL_SDK #endif #include <bgfx/platform.h> diff --git a/3rdparty/bgfx/examples/common/entry/entry_noop.cpp b/3rdparty/bgfx/examples/common/entry/entry_noop.cpp index a7157d77ef2..b95f55ed33f 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_noop.cpp +++ b/3rdparty/bgfx/examples/common/entry/entry_noop.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. + * Copyright 2011-2019 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ diff --git a/3rdparty/bgfx/examples/common/entry/entry_osx.mm b/3rdparty/bgfx/examples/common/entry/entry_osx.mm index 9bd53fb1362..7b5959a43bd 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_osx.mm +++ b/3rdparty/bgfx/examples/common/entry/entry_osx.mm @@ -1,5 +1,5 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. + * Copyright 2011-2019 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ @@ -30,7 +30,6 @@ @interface Window : NSObject<NSWindowDelegate> { - uint32_t windowCount; } + (Window*)sharedDelegate; @@ -86,21 +85,21 @@ namespace entry } MainThreadEntry* self = (MainThreadEntry*)_userData; - return main(self->m_argc, self->m_argv); + uint32_t result = main(self->m_argc, self->m_argv); + [NSApp terminate:nil]; + return result; } }; struct Context { Context() - : m_windowsCreated(0) - , m_scrollf(0.0f) + : m_scrollf(0.0f) , m_mx(0) , m_my(0) , m_scroll(0) , m_style(0) , m_exit(false) - , m_fullscreen(false) { s_translateKey[27] = Key::Esc; s_translateKey[uint8_t('\r')] = Key::Return; @@ -151,6 +150,11 @@ namespace entry s_translateKey[uint8_t(ch)] = s_translateKey[uint8_t(ch - ' ')] = Key::KeyA + (ch - 'a'); } + + for(int ii=0; ii<ENTRY_CONFIG_MAX_WINDOWS; ++ii) + { + m_window[ii] = NULL; + } } NSEvent* waitEvent() @@ -193,10 +197,14 @@ namespace entry uint8_t translateModifiers(int flags) { return 0 - | (0 != (flags & NSEventModifierFlagShift ) ) ? Modifier::LeftShift | Modifier::RightShift : 0 - | (0 != (flags & NSEventModifierFlagOption ) ) ? Modifier::LeftAlt | Modifier::RightAlt : 0 - | (0 != (flags & NSEventModifierFlagControl) ) ? Modifier::LeftCtrl | Modifier::RightCtrl : 0 - | (0 != (flags & NSEventModifierFlagCommand) ) ? Modifier::LeftMeta | Modifier::RightMeta : 0 + | (0 != (flags & NX_DEVICELSHIFTKEYMASK ) ) ? Modifier::LeftShift : 0 + | (0 != (flags & NX_DEVICERSHIFTKEYMASK ) ) ? Modifier::RightShift : 0 + | (0 != (flags & NX_DEVICELALTKEYMASK ) ) ? Modifier::LeftAlt : 0 + | (0 != (flags & NX_DEVICERALTKEYMASK ) ) ? Modifier::RightAlt : 0 + | (0 != (flags & NX_DEVICELCTLKEYMASK ) ) ? Modifier::LeftCtrl : 0 + | (0 != (flags & NX_DEVICERCTLKEYMASK ) ) ? Modifier::RightCtrl : 0 + | (0 != (flags & NX_DEVICELCMDKEYMASK) ) ? Modifier::LeftMeta : 0 + | (0 != (flags & NX_DEVICERCMDKEYMASK) ) ? Modifier::RightMeta : 0 ; } @@ -258,8 +266,18 @@ namespace entry { NSEventType eventType = [event type]; - NSWindow *window = [NSApp keyWindow]; - WindowHandle handle = handleFromWindow(window); + NSWindow *window = [event window]; + WindowHandle handle = {UINT16_MAX}; + if (nil != window) + { + handle = findHandle(window); + } + if (!isValid(handle)) + { + [NSApp sendEvent:event]; + [NSApp updateWindows]; + return true; + } switch (eventType) { @@ -367,7 +385,7 @@ namespace entry void windowDidResize(NSWindow *window) { - WindowHandle handle = handleFromWindow(window); + WindowHandle handle = findHandle(window); NSRect originalFrame = [window frame]; NSRect rect = [window contentRectForFrameRect: originalFrame]; uint32_t width = uint32_t(rect.size.width); @@ -381,14 +399,14 @@ namespace entry void windowDidBecomeKey(NSWindow *window) { - WindowHandle handle = handleFromWindow(window); + WindowHandle handle = findHandle(window); m_eventQueue.postSuspendEvent(handle, Suspend::WillResume); m_eventQueue.postSuspendEvent(handle, Suspend::DidResume); } void windowDidResignKey(NSWindow *window) { - WindowHandle handle = handleFromWindow(window); + WindowHandle handle = findHandle(window); m_eventQueue.postSuspendEvent(handle, Suspend::WillSuspend); m_eventQueue.postSuspendEvent(handle, Suspend::DidSuspend); } @@ -459,13 +477,13 @@ namespace entry while (!(m_exit = [dg applicationHasTerminated]) ) { - @autoreleasepool - { - bgfx::renderFrame(); - } + bgfx::renderFrame(); - while (dispatchEvent(peekEvent() ) ) + @autoreleasepool { + while (dispatchEvent(peekEvent() ) ) + { + } } } @@ -477,31 +495,28 @@ namespace entry return 0; } - bool isValid(WindowHandle _handle) - { - return m_windowAlloc.isValid(_handle.idx); - } - - WindowHandle handleFromWindow(NSWindow *window) + WindowHandle findHandle(NSWindow *_window) { - uint16_t windowIdx = 0; - for (uint16_t i = 0; i < m_windowsCreated; i++) + bx::MutexScope scope(m_lock); + for (uint16_t ii = 0, num = m_windowAlloc.getNumHandles(); ii < num; ++ii) { - if (window == m_window[i]) + uint16_t idx = m_windowAlloc.getHandleAt(ii); + if (_window == m_window[idx]) { - windowIdx = i; - break; + WindowHandle handle = { idx }; + return handle; } } - WindowHandle handle = { windowIdx }; - return handle; + + WindowHandle invalid = { UINT16_MAX }; + return invalid; } EventQueue m_eventQueue; + bx::Mutex m_lock; bx::HandleAllocT<ENTRY_CONFIG_MAX_WINDOWS> m_windowAlloc; NSWindow* m_window[ENTRY_CONFIG_MAX_WINDOWS]; - SInt32 m_windowsCreated; NSRect m_windowFrame; float m_scrollf; @@ -510,7 +525,6 @@ namespace entry int32_t m_scroll; int32_t m_style; bool m_exit; - bool m_fullscreen; }; static Context s_ctx; @@ -534,104 +548,111 @@ namespace entry { BX_UNUSED(_flags); - uint16_t handleIdx = IncrementAtomic(&s_ctx.m_windowsCreated); + bx::MutexScope scope(s_ctx.m_lock); + WindowHandle handle = { s_ctx.m_windowAlloc.alloc() }; - if (handleIdx >= ENTRY_CONFIG_MAX_WINDOWS) + if (UINT16_MAX != handle.idx) { - return { UINT16_MAX }; - } + void (^createWindowBlock)(void) = ^(void) { + NSRect rect = NSMakeRect(_x, _y, _width, _height); + NSWindow* window = [ + [NSWindow alloc] + initWithContentRect:rect + styleMask:s_ctx.m_style + backing:NSBackingStoreBuffered defer:NO + ]; + NSString* appName = [NSString stringWithUTF8String:_title]; + [window setTitle:appName]; + [window makeKeyAndOrderFront:window]; + [window setAcceptsMouseMovedEvents:YES]; + [window setBackgroundColor:[NSColor blackColor]]; + [[Window sharedDelegate] windowCreated:window]; + + s_ctx.m_window[handle.idx] = window; - WindowHandle handle = { handleIdx }; - - void (^createWindowBlock)(void) = ^(void) { - s_ctx.m_windowAlloc.alloc(); - NSRect rect = NSMakeRect(_x, _y, _width, _height); - NSWindow* window = [[NSWindow alloc] - initWithContentRect:rect - styleMask:s_ctx.m_style - backing:NSBackingStoreBuffered defer:NO - ]; - NSString* appName = [NSString stringWithUTF8String:_title]; - [window setTitle:appName]; - [window makeKeyAndOrderFront:window]; - [window setAcceptsMouseMovedEvents:YES]; - [window setBackgroundColor:[NSColor blackColor]]; - [[Window sharedDelegate] windowCreated:window]; - - s_ctx.m_window[handleIdx] = window; - - if(s_ctx.m_windowsCreated > 1) - { s_ctx.m_eventQueue.postSizeEvent(handle, _width, _height); s_ctx.m_eventQueue.postWindowEvent(handle, window); - } - }; + }; - if ([NSThread isMainThread]) - { - createWindowBlock(); - } - else - { - dispatch_async(dispatch_get_main_queue(), createWindowBlock); + if ([NSThread isMainThread]) + { + createWindowBlock(); + } + else + { + dispatch_async(dispatch_get_main_queue(), createWindowBlock); + } } return handle; } - void destroyWindow(WindowHandle _handle) + void destroyWindow(WindowHandle _handle, bool _closeWindow) { - if (s_ctx.isValid(_handle) ) + if (isValid(_handle)) { dispatch_async(dispatch_get_main_queue() - , ^{ - [s_ctx.m_window[_handle.idx] performClose: nil]; - }); + , ^(void){ + NSWindow *window = s_ctx.m_window[_handle.idx]; + if ( NULL != window) + { + s_ctx.m_eventQueue.postWindowEvent(_handle); + s_ctx.m_window[_handle.idx] = NULL; + if ( _closeWindow ) + { + [window close]; + } + + if (0 == _handle.idx) + { + [NSApp terminate:nil]; + } + } + }); + + bx::MutexScope scope(s_ctx.m_lock); + s_ctx.m_windowAlloc.free(_handle.idx); } } + void destroyWindow(WindowHandle _handle) + { + destroyWindow(_handle, true); + } + void setWindowPos(WindowHandle _handle, int32_t _x, int32_t _y) { - if (s_ctx.isValid(_handle) ) - { - NSWindow* window = s_ctx.m_window[_handle.idx]; - NSScreen* screen = [window screen]; + dispatch_async(dispatch_get_main_queue() + , ^{ + NSWindow* window = s_ctx.m_window[_handle.idx]; + NSScreen* screen = [window screen]; - NSRect screenRect = [screen frame]; - CGFloat menuBarHeight = [[[NSApplication sharedApplication] mainMenu] menuBarHeight]; + NSRect screenRect = [screen frame]; + CGFloat menuBarHeight = [[[NSApplication sharedApplication] mainMenu] menuBarHeight]; - NSPoint position = { float(_x), screenRect.size.height - menuBarHeight - float(_y) }; + NSPoint position = { float(_x), screenRect.size.height - menuBarHeight - float(_y) }; - dispatch_async(dispatch_get_main_queue() - , ^{ [window setFrameTopLeftPoint: position]; }); - } } void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height) { - if (s_ctx.isValid(_handle) ) - { - NSSize size = { float(_width), float(_height) }; - dispatch_async(dispatch_get_main_queue() + NSSize size = { float(_width), float(_height) }; + dispatch_async(dispatch_get_main_queue() , ^{ [s_ctx.m_window[_handle.idx] setContentSize: size]; }); - } } void setWindowTitle(WindowHandle _handle, const char* _title) { - if (s_ctx.isValid(_handle) ) - { - NSString* title = [[NSString alloc] initWithCString:_title encoding:1]; - dispatch_async(dispatch_get_main_queue() + NSString* title = [[NSString alloc] initWithCString:_title encoding:1]; + dispatch_async(dispatch_get_main_queue() , ^{ [s_ctx.m_window[_handle.idx] setTitle: title]; + [title release]; }); - [title release]; - } } void setWindowFlags(WindowHandle _handle, uint32_t _flags, bool _enabled) @@ -641,37 +662,11 @@ namespace entry void toggleFullscreen(WindowHandle _handle) { - if (s_ctx.isValid(_handle) ) - { - NSWindow* window = s_ctx.m_window[_handle.idx]; - NSScreen* screen = [window screen]; - NSRect screenRect = [screen frame]; - - if (!s_ctx.m_fullscreen) - { - s_ctx.m_style &= ~NSWindowStyleMaskTitled; - dispatch_async(dispatch_get_main_queue() - , ^{ - [NSMenu setMenuBarVisible: false]; - [window setStyleMask: s_ctx.m_style]; - [window setFrame:screenRect display:YES]; - }); - - s_ctx.m_fullscreen = true; - } - else - { - s_ctx.m_style |= NSWindowStyleMaskTitled; - dispatch_async(dispatch_get_main_queue() - , ^{ - [NSMenu setMenuBarVisible: true]; - [window setStyleMask: s_ctx.m_style]; - [window setFrame:s_ctx.m_windowFrame display:YES]; - }); - - s_ctx.m_fullscreen = false; - } - } + dispatch_async(dispatch_get_main_queue() + , ^{ + NSWindow* window = s_ctx.m_window[_handle.idx]; + [window toggleFullScreen:nil]; + }); } void setMouseLock(WindowHandle _handle, bool _lock) @@ -732,7 +727,6 @@ namespace entry return nil; } - self->windowCount = 0; return self; } @@ -741,31 +735,22 @@ namespace entry assert(window); [window setDelegate:self]; - - assert(self->windowCount < ~0u); - self->windowCount += 1; } - (void)windowWillClose:(NSNotification*)notification { BX_UNUSED(notification); + NSWindow *window = [notification object]; + + [window setDelegate:nil]; + + destroyWindow(entry::s_ctx.findHandle(window), false); } - (BOOL)windowShouldClose:(NSWindow*)window { assert(window); - - [window setDelegate:nil]; - - assert(self->windowCount); - self->windowCount -= 1; - - if (self->windowCount == 0) - { - [NSApp terminate:self]; - return false; - } - + BX_UNUSED(window); return true; } diff --git a/3rdparty/bgfx/examples/common/entry/entry_p.h b/3rdparty/bgfx/examples/common/entry/entry_p.h index 6776610b636..d1706d4dfe7 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_p.h +++ b/3rdparty/bgfx/examples/common/entry/entry_p.h @@ -1,5 +1,5 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. + * Copyright 2011-2019 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ @@ -25,6 +25,10 @@ # 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 d582b034e5e..96aa49149f4 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp +++ b/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. + * Copyright 2011-2019 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ @@ -7,9 +7,13 @@ #if ENTRY_CONFIG_USE_SDL -#if BX_PLATFORM_WINDOWS +#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 // BX_PLATFORM_WINDOWS +#endif #include <bx/os.h> @@ -34,6 +38,42 @@ BX_PRAGMA_DIAGNOSTIC_POP() namespace entry { + /// + static void* sdlNativeWindowHandle(SDL_Window* _window) + { + SDL_SysWMinfo wmi; + SDL_VERSION(&wmi.version); + if (!SDL_GetWindowWMInfo(_window, &wmi) ) + { + return NULL; + } + +# 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) + { + 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 + return (void*)wmi.info.x11.window; +# endif +# elif BX_PLATFORM_OSX + return wmi.info.cocoa.window; +# elif BX_PLATFORM_WINDOWS + return wmi.info.win.window; +# elif BX_PLATFORM_STEAMLINK + return wmi.info.vivante.window; +# endif // BX_PLATFORM_ + } + inline bool sdlSetWindow(SDL_Window* _window) { SDL_SysWMinfo wmi; @@ -45,18 +85,20 @@ namespace entry bgfx::PlatformData pd; # if BX_PLATFORM_LINUX || BX_PLATFORM_BSD +# if ENTRY_CONFIG_USE_WAYLAND + pd.ndt = wmi.info.wl.display; +# else pd.ndt = wmi.info.x11.display; - pd.nwh = (void*)(uintptr_t)wmi.info.x11.window; +# endif # elif BX_PLATFORM_OSX pd.ndt = NULL; - pd.nwh = wmi.info.cocoa.window; # elif BX_PLATFORM_WINDOWS pd.ndt = NULL; - pd.nwh = wmi.info.win.window; # elif BX_PLATFORM_STEAMLINK pd.ndt = wmi.info.vivante.display; - pd.nwh = wmi.info.vivante.window; # endif // BX_PLATFORM_ + pd.nwh = sdlNativeWindowHandle(_window); + pd.context = NULL; pd.backBuffer = NULL; pd.backBufferDS = NULL; @@ -65,6 +107,23 @@ namespace entry return true; } + 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; @@ -252,27 +311,6 @@ namespace entry static int32_t threadFunc(bx::Thread* _thread, void* _userData); }; - /// - static void* sdlNativeWindowHandle(SDL_Window* _window) - { - SDL_SysWMinfo wmi; - SDL_VERSION(&wmi.version); - if (!SDL_GetWindowWMInfo(_window, &wmi) ) - { - return NULL; - } - -# if BX_PLATFORM_LINUX || BX_PLATFORM_BSD - return (void*)wmi.info.x11.window; -# elif BX_PLATFORM_OSX - return wmi.info.cocoa.window; -# elif BX_PLATFORM_WINDOWS - return wmi.info.win.window; -# elif BX_PLATFORM_STEAMLINK - return wmi.info.vivante.window; -# endif // BX_PLATFORM_ - } - struct Msg { Msg() @@ -858,7 +896,7 @@ namespace entry if (isValid(handle) ) { m_eventQueue.postWindowEvent(handle); - SDL_DestroyWindow(m_window[handle.idx]); + sdlDestroyWindow(m_window[handle.idx]); m_window[handle.idx] = NULL; } } @@ -952,7 +990,7 @@ namespace entry while (bgfx::RenderFrame::NoContext != bgfx::renderFrame() ) {}; m_thread.shutdown(); - SDL_DestroyWindow(m_window[0]); + sdlDestroyWindow(m_window[0]); SDL_Quit(); return m_thread.getExitCode(); diff --git a/3rdparty/bgfx/examples/common/entry/entry_windows.cpp b/3rdparty/bgfx/examples/common/entry/entry_windows.cpp index 845c039b451..39be55abfc3 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_windows.cpp +++ b/3rdparty/bgfx/examples/common/entry/entry_windows.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. + * Copyright 2011-2019 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ @@ -18,6 +18,7 @@ #include <tinystl/allocator.h> #include <tinystl/string.h> +#include <tinystl/vector.h> #include <windows.h> #include <windowsx.h> @@ -33,6 +34,16 @@ namespace entry { + typedef tinystl::vector<WCHAR> WSTRING; + + inline WSTRING UTF8ToUTF16(const char *utf8_str) + { + int len = MultiByteToWideChar(CP_UTF8, 0, utf8_str, -1, NULL, 0); + WSTRING utf16(len); + MultiByteToWideChar(CP_UTF8, 0, utf8_str, -1, utf16.data(), len); + return utf16; + } + /// inline void winSetHwnd(::HWND _window) { @@ -359,6 +370,7 @@ namespace entry , m_init(false) , m_exit(false) { + m_surrogate = 0; bx::memSet(s_translateKey, 0, sizeof(s_translateKey) ); s_translateKey[VK_ESCAPE] = Key::Esc; s_translateKey[VK_RETURN] = Key::Return; @@ -456,7 +468,7 @@ namespace entry HINSTANCE instance = (HINSTANCE)GetModuleHandle(NULL); - WNDCLASSEXA wnd; + WNDCLASSEXW wnd; bx::memSet(&wnd, 0, sizeof(wnd) ); wnd.cbSize = sizeof(wnd); wnd.style = CS_HREDRAW | CS_VREDRAW; @@ -464,9 +476,9 @@ namespace entry wnd.hInstance = instance; wnd.hIcon = LoadIcon(NULL, IDI_APPLICATION); wnd.hCursor = LoadCursor(NULL, IDC_ARROW); - wnd.lpszClassName = "bgfx"; + wnd.lpszClassName = L"bgfx"; wnd.hIconSm = LoadIcon(NULL, IDI_APPLICATION); - RegisterClassExA(&wnd); + RegisterClassExW(&wnd); m_windowAlloc.alloc(); m_hwnd[0] = CreateWindowExA( @@ -521,10 +533,10 @@ namespace entry s_xinput.update(m_eventQueue); WaitForInputIdle(GetCurrentProcess(), 16); - while (0 != PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE) ) + while (0 != PeekMessageW(&msg, NULL, 0U, 0U, PM_REMOVE) ) { TranslateMessage(&msg); - DispatchMessage(&msg); + DispatchMessageW(&msg); } } @@ -548,8 +560,8 @@ namespace entry case WM_USER_WINDOW_CREATE: { Msg* msg = (Msg*)_lparam; - HWND hwnd = CreateWindowA("bgfx" - , msg->m_title.c_str() + HWND hwnd = CreateWindowW(L"bgfx" + , UTF8ToUTF16(msg->m_title.c_str()).data() , WS_OVERLAPPEDWINDOW|WS_VISIBLE , msg->m_x , msg->m_y @@ -590,7 +602,7 @@ namespace entry case WM_USER_WINDOW_SET_TITLE: { Msg* msg = (Msg*)_lparam; - SetWindowTextA(m_hwnd[_wparam], msg->m_title.c_str() ); + SetWindowTextW(m_hwnd[_wparam], UTF8ToUTF16(msg->m_title.c_str()).data() ); delete msg; } break; @@ -842,20 +854,36 @@ namespace entry case WM_CHAR: { + WCHAR utf16[2] = { (WCHAR)_wparam }; uint8_t utf8[4] = {}; - uint8_t len = (uint8_t)WideCharToMultiByte(CP_UTF8 - , 0 - , (LPCWSTR)&_wparam - , 1 - , (LPSTR)utf8 - , BX_COUNTOF(utf8) - , NULL - , NULL - ); - if (0 != len) - { - WindowHandle handle = findHandle(_hwnd); - m_eventQueue.postCharEvent(handle, len, utf8); + + if (utf16[0] >= 0xD800 && utf16[0] <= 0xDBFF) { + m_surrogate = utf16[0]; + } 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 { + utf16_len = 1; + } + + uint8_t len = (uint8_t)WideCharToMultiByte(CP_UTF8 + , 0 + , utf16 + , utf16_len + , (LPSTR)utf8 + , BX_COUNTOF(utf8) + , NULL + , NULL + ); + if (0 != len) + { + WindowHandle handle = findHandle(_hwnd); + m_eventQueue.postCharEvent(handle, len, utf8); + } } } break; @@ -864,8 +892,10 @@ namespace entry { HDROP drop = (HDROP)_wparam; char tmp[bx::kMaxFilePath]; - uint32_t result = DragQueryFileA(drop, 0, tmp, sizeof(tmp) ); + WCHAR utf16[bx::kMaxFilePath]; + uint32_t result = DragQueryFileW(drop, 0, utf16, bx::kMaxFilePath); BX_UNUSED(result); + WideCharToMultiByte(CP_UTF8, 0, utf16, -1, tmp, bx::kMaxFilePath, NULL, NULL); WindowHandle handle = findHandle(_hwnd); m_eventQueue.postDropFileEvent(handle, tmp); } @@ -876,7 +906,7 @@ namespace entry } } - return DefWindowProc(_hwnd, _id, _wparam, _lparam); + return DefWindowProcW(_hwnd, _id, _wparam, _lparam); } WindowHandle findHandle(HWND _hwnd) @@ -1015,6 +1045,7 @@ namespace entry static LRESULT CALLBACK wndProc(HWND _hwnd, UINT _id, WPARAM _wparam, LPARAM _lparam); EventQueue m_eventQueue; + WCHAR m_surrogate; bx::Mutex m_lock; bx::HandleAllocT<ENTRY_CONFIG_MAX_WINDOWS> m_windowAlloc; diff --git a/3rdparty/bgfx/examples/common/entry/entry_winrt.cx b/3rdparty/bgfx/examples/common/entry/entry_winrt.cx index 76270e99770..25ddb3b0b12 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_winrt.cx +++ b/3rdparty/bgfx/examples/common/entry/entry_winrt.cx @@ -11,6 +11,7 @@ #include <bx/thread.h> #include <bx/math.h> #include <Unknwn.h> +#include <cmath> using namespace Windows::ApplicationModel; using namespace Windows::ApplicationModel::Core; @@ -91,8 +92,8 @@ public: auto dpi = DisplayInformation::GetForCurrentView()->LogicalDpi; static const float dipsPerInch = 96.0f; g_eventQueue.postSizeEvent(g_defaultWindow - , lround(bx::floor(bounds.Width * dpi / dipsPerInch + 0.5f) ) - , lround(bx::floor(bounds.Height * dpi / dipsPerInch + 0.5f) ) + , std::lround(bx::floor(bounds.Width * dpi / dipsPerInch + 0.5f) ) + , std::lround(bx::floor(bounds.Height * dpi / dipsPerInch + 0.5f) ) ); #endif // BX_PLATFORM_WINRT diff --git a/3rdparty/bgfx/examples/common/entry/entry_x11.cpp b/3rdparty/bgfx/examples/common/entry/entry_x11.cpp index 6bfd3192caa..9ed9bc3448c 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_x11.cpp +++ b/3rdparty/bgfx/examples/common/entry/entry_x11.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. + * Copyright 2011-2019 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ diff --git a/3rdparty/bgfx/examples/common/entry/input.cpp b/3rdparty/bgfx/examples/common/entry/input.cpp index 5fdad9c0bb6..7d4704f346c 100644 --- a/3rdparty/bgfx/examples/common/entry/input.cpp +++ b/3rdparty/bgfx/examples/common/entry/input.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 Branimir Karadzic. All rights reserved. + * Copyright 2010-2019 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ diff --git a/3rdparty/bgfx/examples/common/entry/input.h b/3rdparty/bgfx/examples/common/entry/input.h index 6954f3daa19..5f5acdfeed1 100644 --- a/3rdparty/bgfx/examples/common/entry/input.h +++ b/3rdparty/bgfx/examples/common/entry/input.h @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 Branimir Karadzic. All rights reserved. + * Copyright 2010-2019 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ |