mirror of
https://github.com/AxioDL/boo.git
synced 2025-12-16 08:27:10 +00:00
Use UTF-8 exclusively internally; update logvisor
This commit is contained in:
@@ -37,15 +37,15 @@ static bool FindBestD3DCompile() {
|
||||
namespace boo {
|
||||
static logvisor::Module Log("boo::ApplicationUWP");
|
||||
|
||||
std::shared_ptr<IWindow> _WindowUWPNew(SystemStringView title, Boo3DAppContextUWP& d3dCtx);
|
||||
std::shared_ptr<IWindow> _WindowUWPNew(std::string_view title, Boo3DAppContextUWP& d3dCtx);
|
||||
|
||||
class ApplicationUWP final : public IApplication {
|
||||
friend ref class AppView;
|
||||
IApplicationCallback& m_callback;
|
||||
const SystemString m_uniqueName;
|
||||
const SystemString m_friendlyName;
|
||||
const SystemString m_pname;
|
||||
const std::vector<SystemString> m_args;
|
||||
const std::string m_uniqueName;
|
||||
const std::string m_friendlyName;
|
||||
const std::string m_pname;
|
||||
const std::vector<std::string> m_args;
|
||||
std::shared_ptr<IWindow> m_window;
|
||||
bool m_singleInstance;
|
||||
bool m_issuedWindow = false;
|
||||
@@ -55,8 +55,8 @@ class ApplicationUWP final : public IApplication {
|
||||
void _deletedWindow(IWindow* window) override {}
|
||||
|
||||
public:
|
||||
ApplicationUWP(IApplicationCallback& callback, SystemStringView uniqueName, SystemStringView friendlyName,
|
||||
SystemStringView pname, const std::vector<SystemString>& args, bool singleInstance)
|
||||
ApplicationUWP(IApplicationCallback& callback, std::string_view uniqueName, std::string_view friendlyName,
|
||||
std::string_view pname, const std::vector<std::string>& args, bool singleInstance)
|
||||
: m_callback(callback)
|
||||
, m_uniqueName(uniqueName)
|
||||
, m_friendlyName(friendlyName)
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
CreateDXGIFactory1PROC MyCreateDXGIFactory1 = CreateDXGIFactory1;
|
||||
|
||||
bool no12 = true;
|
||||
for (const SystemString& arg : args)
|
||||
for (const std::string& arg : args)
|
||||
if (!arg.compare(L"--d3d12"))
|
||||
no12 = false;
|
||||
|
||||
@@ -190,7 +190,7 @@ public:
|
||||
/* Spawn client thread */
|
||||
int clientReturn = 0;
|
||||
m_clientThread = std::thread([&]() {
|
||||
std::string thrName = WCSTMBS(getFriendlyName().data()) + " Client Thread";
|
||||
std::string thrName = std::string(getFriendlyName()) + " Client Thread";
|
||||
logvisor::RegisterThreadName(thrName.c_str());
|
||||
clientReturn = m_callback.appMain(this);
|
||||
});
|
||||
@@ -206,15 +206,15 @@ public:
|
||||
m_clientThread.join();
|
||||
}
|
||||
|
||||
SystemStringView getUniqueName() const override { return m_uniqueName; }
|
||||
std::string_view getUniqueName() const override { return m_uniqueName; }
|
||||
|
||||
SystemStringView getFriendlyName() const override { return m_friendlyName; }
|
||||
std::string_view getFriendlyName() const override { return m_friendlyName; }
|
||||
|
||||
SystemStringView getProcessName() const override { return m_pname; }
|
||||
std::string_view getProcessName() const override { return m_pname; }
|
||||
|
||||
const std::vector<SystemString>& getArgs() const override { return m_args; }
|
||||
const std::vector<std::string>& getArgs() const override { return m_args; }
|
||||
|
||||
std::shared_ptr<IWindow> newWindow(SystemStringView title, uint32_t sampleCount) override {
|
||||
std::shared_ptr<IWindow> newWindow(std::string_view title, uint32_t sampleCount) override {
|
||||
if (!m_issuedWindow) {
|
||||
m_issuedWindow = true;
|
||||
return m_window;
|
||||
@@ -229,8 +229,8 @@ IApplication* APP = nullptr;
|
||||
ref class AppView sealed : public IFrameworkView {
|
||||
ApplicationUWP m_app;
|
||||
|
||||
internal : AppView(IApplicationCallback& callback, SystemStringView uniqueName, SystemStringView friendlyName,
|
||||
SystemStringView pname, const std::vector<SystemString>& args, bool singleInstance)
|
||||
internal : AppView(IApplicationCallback& callback, std::string_view uniqueName, std::string_view friendlyName,
|
||||
std::string_view pname, const std::vector<std::string>& args, bool singleInstance)
|
||||
: m_app(callback, uniqueName, friendlyName, pname, args, singleInstance) {
|
||||
APP = &m_app;
|
||||
}
|
||||
|
||||
@@ -77,14 +77,14 @@ namespace boo {
|
||||
static logvisor::Module Log("boo::ApplicationWin32");
|
||||
Win32Cursors WIN32_CURSORS;
|
||||
|
||||
std::shared_ptr<IWindow> _WindowWin32New(SystemStringView title, Boo3DAppContextWin32& d3dCtx);
|
||||
std::shared_ptr<IWindow> _WindowWin32New(std::string_view title, Boo3DAppContextWin32& d3dCtx);
|
||||
|
||||
class ApplicationWin32 final : public IApplication {
|
||||
IApplicationCallback& m_callback;
|
||||
const SystemString m_uniqueName;
|
||||
const SystemString m_friendlyName;
|
||||
const SystemString m_pname;
|
||||
const std::vector<SystemString> m_args;
|
||||
const std::string m_uniqueName;
|
||||
const std::string m_friendlyName;
|
||||
const std::string m_pname;
|
||||
const std::vector<std::string> m_args;
|
||||
std::unordered_map<HWND, std::weak_ptr<IWindow>> m_allWindows;
|
||||
|
||||
Boo3DAppContextWin32 m_3dCtx;
|
||||
@@ -95,8 +95,8 @@ class ApplicationWin32 final : public IApplication {
|
||||
void _deletedWindow(IWindow* window) override { m_allWindows.erase(HWND(window->getPlatformHandle())); }
|
||||
|
||||
public:
|
||||
ApplicationWin32(IApplicationCallback& callback, SystemStringView uniqueName, SystemStringView friendlyName,
|
||||
SystemStringView pname, const std::vector<SystemString>& args, std::string_view gfxApi,
|
||||
ApplicationWin32(IApplicationCallback& callback, std::string_view uniqueName, std::string_view friendlyName,
|
||||
std::string_view pname, const std::vector<std::string>& args, std::string_view gfxApi,
|
||||
uint32_t samples, uint32_t anisotropy, bool deepColor, bool singleInstance)
|
||||
: m_callback(callback), m_uniqueName(uniqueName), m_friendlyName(friendlyName), m_pname(pname), m_args(args) {
|
||||
m_3dCtx.m_ctx11.m_sampleCount = samples;
|
||||
@@ -142,17 +142,17 @@ public:
|
||||
noD3d = true;
|
||||
#endif
|
||||
}
|
||||
for (const SystemString& arg : args) {
|
||||
for (const std::string& arg : args) {
|
||||
#if BOO_HAS_VULKAN
|
||||
if (!arg.compare(L"--d3d11")) {
|
||||
if (!arg.compare("--d3d11")) {
|
||||
useVulkan = false;
|
||||
noD3d = false;
|
||||
}
|
||||
if (!arg.compare(L"--vulkan")) {
|
||||
if (!arg.compare("--vulkan")) {
|
||||
noD3d = true;
|
||||
useVulkan = true;
|
||||
}
|
||||
if (!arg.compare(L"--gl")) {
|
||||
if (!arg.compare("--gl")) {
|
||||
noD3d = true;
|
||||
useVulkan = false;
|
||||
}
|
||||
@@ -173,7 +173,7 @@ public:
|
||||
/* Check device support for vulkan */
|
||||
if (g_VulkanContext.m_instance == VK_NULL_HANDLE) {
|
||||
auto appName = getUniqueName();
|
||||
if (g_VulkanContext.initVulkan(WCSTMBS(appName.data()).c_str(), m_getVkProc)) {
|
||||
if (g_VulkanContext.initVulkan(appName.data(), m_getVkProc)) {
|
||||
if (g_VulkanContext.enumerateDevices()) {
|
||||
/* Obtain DXGI Factory */
|
||||
HRESULT hr = MyCreateDXGIFactory1(__uuidof(IDXGIFactory1), &m_3dCtx.m_vulkanDxFactory);
|
||||
@@ -375,7 +375,7 @@ public:
|
||||
/* Spawn client thread */
|
||||
int clientReturn = 0;
|
||||
std::thread clientThread([&]() {
|
||||
std::string thrName = WCSTMBS(getFriendlyName().data()) + " Client Thread";
|
||||
std::string thrName = std::string(getFriendlyName()) + " Client Thread";
|
||||
logvisor::RegisterThreadName(thrName.c_str());
|
||||
CoInitializeEx(nullptr, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE);
|
||||
clientReturn = m_callback.appMain(this);
|
||||
@@ -391,7 +391,7 @@ public:
|
||||
case WM_USER: {
|
||||
/* New-window message (coalesced onto main thread) */
|
||||
std::lock_guard<std::mutex> lk(g_nwmt);
|
||||
SystemStringView* title = reinterpret_cast<SystemStringView*>(msg.wParam);
|
||||
std::string_view* title = reinterpret_cast<std::string_view*>(msg.wParam);
|
||||
m_mwret = newWindow(*title);
|
||||
g_nwcv.notify_one();
|
||||
continue;
|
||||
@@ -441,16 +441,16 @@ public:
|
||||
w->_cleanup();
|
||||
}
|
||||
|
||||
SystemStringView getUniqueName() const override { return m_uniqueName; }
|
||||
std::string_view getUniqueName() const override { return m_uniqueName; }
|
||||
|
||||
SystemStringView getFriendlyName() const override { return m_friendlyName; }
|
||||
std::string_view getFriendlyName() const override { return m_friendlyName; }
|
||||
|
||||
SystemStringView getProcessName() const override { return m_pname; }
|
||||
std::string_view getProcessName() const override { return m_pname; }
|
||||
|
||||
const std::vector<SystemString>& getArgs() const override { return m_args; }
|
||||
const std::vector<std::string>& getArgs() const override { return m_args; }
|
||||
|
||||
std::shared_ptr<IWindow> m_mwret;
|
||||
std::shared_ptr<IWindow> newWindow(SystemStringView title) override {
|
||||
std::shared_ptr<IWindow> newWindow(std::string_view title) override {
|
||||
if (GetCurrentThreadId() != g_mainThreadId) {
|
||||
std::unique_lock<std::mutex> lk(g_nwmt);
|
||||
if (!PostThreadMessageW(g_mainThreadId, WM_USER, WPARAM(&title), 0))
|
||||
@@ -469,11 +469,11 @@ public:
|
||||
};
|
||||
|
||||
IApplication* APP = nullptr;
|
||||
int ApplicationRun(IApplication::EPlatformType platform, IApplicationCallback& cb, SystemStringView uniqueName,
|
||||
SystemStringView friendlyName, SystemStringView pname, const std::vector<SystemString>& args,
|
||||
int ApplicationRun(IApplication::EPlatformType platform, IApplicationCallback& cb, std::string_view uniqueName,
|
||||
std::string_view friendlyName, std::string_view pname, const std::vector<std::string>& args,
|
||||
std::string_view gfxApi, uint32_t samples, uint32_t anisotropy, bool deepColor,
|
||||
bool singleInstance) {
|
||||
std::string thrName = WCSTMBS(friendlyName.data()) + " Main Thread";
|
||||
std::string thrName = std::string(friendlyName) + " Main Thread";
|
||||
logvisor::RegisterThreadName(thrName.c_str());
|
||||
if (APP)
|
||||
return 1;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace boo {
|
||||
class IWindow;
|
||||
}
|
||||
} // namespace boo
|
||||
|
||||
#if _WIN32_WINNT_WIN10
|
||||
#include <dxgi1_4.h>
|
||||
@@ -115,17 +115,3 @@ struct Boo3DAppContext {
|
||||
win.m_needsResize = true;
|
||||
}
|
||||
};
|
||||
|
||||
inline std::string WCSTMBS(const wchar_t* wstr) {
|
||||
int sizeNeeded = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, nullptr, 0, nullptr, nullptr) - 1;
|
||||
std::string strTo(sizeNeeded, 0);
|
||||
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, &strTo[0], sizeNeeded, nullptr, nullptr);
|
||||
return strTo;
|
||||
}
|
||||
|
||||
inline std::wstring MBSTWCS(const char* str) {
|
||||
int sizeNeeded = MultiByteToWideChar(CP_UTF8, 0, str, -1, nullptr, 0) - 1;
|
||||
std::wstring strTo(sizeNeeded, 0);
|
||||
MultiByteToWideChar(CP_UTF8, 0, str, -1, &strTo[0], sizeNeeded);
|
||||
return strTo;
|
||||
}
|
||||
|
||||
@@ -279,7 +279,7 @@ public:
|
||||
};
|
||||
EventReceiver ^ m_eventReceiver;
|
||||
|
||||
WindowUWP(SystemStringView title, Boo3DAppContextUWP& b3dCtx)
|
||||
WindowUWP(std::string_view title, Boo3DAppContextUWP& b3dCtx)
|
||||
: m_coreWindow(CoreWindow::GetForCurrentThread()), m_eventReceiver(ref new EventReceiver(*this)) {
|
||||
IGraphicsContext::EGraphicsAPI api = IGraphicsContext::EGraphicsAPI::D3D11;
|
||||
#if _WIN32_WINNT_WIN10
|
||||
@@ -317,9 +317,9 @@ public:
|
||||
|
||||
void hideWindow() override {}
|
||||
|
||||
SystemString getTitle() override { return SystemString(m_appView->Title->Data()); }
|
||||
std::string getTitle() override { return std::string(m_appView->Title->Data()); }
|
||||
|
||||
void setTitle(SystemStringView title) override { m_appView->Title = ref new Platform::String(title.data()); }
|
||||
void setTitle(std::string_view title) override { m_appView->Title = ref new Platform::String(title.data()); }
|
||||
|
||||
void setCursor(EMouseCursor cursor) override {}
|
||||
|
||||
@@ -493,7 +493,7 @@ public:
|
||||
IGraphicsDataFactory* getLoadContextDataFactory() override { return m_gfxCtx->getLoadContextDataFactory(); }
|
||||
};
|
||||
|
||||
std::shared_ptr<IWindow> _WindowUWPNew(SystemStringView title, Boo3DAppContextUWP& d3dCtx) {
|
||||
std::shared_ptr<IWindow> _WindowUWPNew(std::string_view title, Boo3DAppContextUWP& d3dCtx) {
|
||||
return std::make_shared<WindowUWP>(title, d3dCtx);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#endif
|
||||
|
||||
#include <logvisor/logvisor.hpp>
|
||||
#include <nowide/stackstring.hpp>
|
||||
|
||||
static const int ContextAttribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 3,
|
||||
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
||||
@@ -863,7 +864,7 @@ class WindowWin32 : public IWindow {
|
||||
}
|
||||
|
||||
public:
|
||||
WindowWin32(SystemStringView title, Boo3DAppContextWin32& b3dCtx) {
|
||||
WindowWin32(std::string_view title, Boo3DAppContextWin32& b3dCtx) {
|
||||
const POINT ptZero = {0, 0};
|
||||
HMONITOR monitor = MonitorFromPoint(ptZero, MONITOR_DEFAULTTOPRIMARY);
|
||||
MONITORINFO monInfo = {};
|
||||
@@ -874,7 +875,8 @@ public:
|
||||
RECT r = {x, y, x + w, y + h};
|
||||
AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW, FALSE);
|
||||
|
||||
m_hwnd = CreateWindowW(L"BooWindow", title.data(), WS_OVERLAPPEDWINDOW, r.left, r.top, r.right - r.left,
|
||||
const nowide::wstackstring wtitle(title);
|
||||
m_hwnd = CreateWindowW(L"BooWindow", wtitle.get(), WS_OVERLAPPEDWINDOW, r.left, r.top, r.right - r.left,
|
||||
r.bottom - r.top, nullptr, nullptr, nullptr, nullptr);
|
||||
m_imc = ImmGetContext(m_hwnd);
|
||||
|
||||
@@ -890,12 +892,12 @@ public:
|
||||
IGraphicsContext::EGraphicsAPI api = IGraphicsContext::EGraphicsAPI::D3D11;
|
||||
#if BOO_HAS_GL
|
||||
if (b3dCtx.m_ctxOgl.m_dxFactory) {
|
||||
m_gfxCtx.reset(new GraphicsContextWin32GL(IGraphicsContext::EGraphicsAPI::OpenGL3_3, this, m_hwnd, b3dCtx));
|
||||
m_gfxCtx = std::make_unique<GraphicsContextWin32GL>(IGraphicsContext::EGraphicsAPI::OpenGL3_3, this, m_hwnd, b3dCtx);
|
||||
m_openGL = true;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
m_gfxCtx.reset(new GraphicsContextWin32D3D(api, this, m_hwnd, b3dCtx));
|
||||
m_gfxCtx = std::make_unique<GraphicsContextWin32D3D>(api, this, m_hwnd, b3dCtx);
|
||||
}
|
||||
|
||||
void _cleanup() override { m_gfxCtx.reset(); }
|
||||
@@ -911,13 +913,16 @@ public:
|
||||
|
||||
void hideWindow() override { ShowWindow(m_hwnd, SW_HIDE); }
|
||||
|
||||
SystemString getTitle() override {
|
||||
std::string getTitle() override {
|
||||
wchar_t title[256];
|
||||
int c = GetWindowTextW(m_hwnd, title, 256);
|
||||
return SystemString(title, c);
|
||||
return nowide::narrow(title, c);
|
||||
}
|
||||
|
||||
void setTitle(SystemStringView title) override { SetWindowTextW(m_hwnd, title.data()); }
|
||||
void setTitle(std::string_view title) override {
|
||||
const nowide::wstackstring wtitle(title);
|
||||
SetWindowTextW(m_hwnd, wtitle.get());
|
||||
}
|
||||
|
||||
static void _setCursor(HCURSOR cur) { PostThreadMessageW(g_mainThreadId, WM_USER + 2, WPARAM(cur), 0); }
|
||||
|
||||
@@ -989,13 +994,14 @@ public:
|
||||
|
||||
float getVirtualPixelFactor() const override {
|
||||
#if _WIN32_WINNT_WINBLUE
|
||||
if (MyGetScaleFactorForMonitor) {
|
||||
DEVICE_SCALE_FACTOR Factor;
|
||||
if (MyGetScaleFactorForMonitor != nullptr) {
|
||||
DEVICE_SCALE_FACTOR Factor = DEVICE_SCALE_FACTOR_INVALID;
|
||||
HMONITOR mon = MonitorFromWindow(m_hwnd, MONITOR_DEFAULTTOPRIMARY);
|
||||
MyGetScaleFactorForMonitor(mon, &Factor);
|
||||
if (Factor == 0)
|
||||
if (Factor == 0) {
|
||||
return 1.f;
|
||||
return Factor / 100.f;
|
||||
}
|
||||
return static_cast<float>(Factor) / 100.f;
|
||||
}
|
||||
#endif
|
||||
return 1.f;
|
||||
@@ -1368,7 +1374,7 @@ public:
|
||||
IGraphicsDataFactory* getLoadContextDataFactory() override { return m_gfxCtx->getLoadContextDataFactory(); }
|
||||
};
|
||||
|
||||
std::shared_ptr<IWindow> _WindowWin32New(SystemStringView title, Boo3DAppContextWin32& d3dCtx) {
|
||||
std::shared_ptr<IWindow> _WindowWin32New(std::string_view title, Boo3DAppContextWin32& d3dCtx) {
|
||||
return std::make_shared<WindowWin32>(title, d3dCtx);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user