mirror of
https://github.com/AxioDL/boo.git
synced 2025-12-16 00:17:06 +00:00
UWP support
This commit is contained in:
@@ -25,30 +25,9 @@ pD3DCreateBlob D3DCreateBlobPROC = nullptr;
|
||||
|
||||
static bool FindBestD3DCompile()
|
||||
{
|
||||
HMODULE d3dCompilelib = LoadLibraryW(L"D3DCompiler_47.dll");
|
||||
if (!d3dCompilelib)
|
||||
{
|
||||
d3dCompilelib = LoadLibraryW(L"D3DCompiler_46.dll");
|
||||
if (!d3dCompilelib)
|
||||
{
|
||||
d3dCompilelib = LoadLibraryW(L"D3DCompiler_45.dll");
|
||||
if (!d3dCompilelib)
|
||||
{
|
||||
d3dCompilelib = LoadLibraryW(L"D3DCompiler_44.dll");
|
||||
if (!d3dCompilelib)
|
||||
{
|
||||
d3dCompilelib = LoadLibraryW(L"D3DCompiler_43.dll");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (d3dCompilelib)
|
||||
{
|
||||
D3DCompilePROC = (pD3DCompile)GetProcAddress(d3dCompilelib, "D3DCompile");
|
||||
D3DCreateBlobPROC = (pD3DCreateBlob)GetProcAddress(d3dCompilelib, "D3DCreateBlob");
|
||||
return D3DCompilePROC != nullptr && D3DCreateBlobPROC != nullptr;
|
||||
}
|
||||
return false;
|
||||
D3DCompilePROC = D3DCompile;
|
||||
D3DCreateBlobPROC = D3DCreateBlob;
|
||||
return D3DCompilePROC != nullptr && D3DCreateBlobPROC != nullptr;
|
||||
}
|
||||
|
||||
namespace boo
|
||||
@@ -91,14 +70,8 @@ public:
|
||||
m_args(args),
|
||||
m_singleInstance(singleInstance)
|
||||
{
|
||||
HMODULE dxgilib = LoadLibraryW(L"dxgi.dll");
|
||||
if (!dxgilib)
|
||||
Log.report(logvisor::Fatal, "unable to load dxgi.dll");
|
||||
|
||||
typedef HRESULT(WINAPI*CreateDXGIFactory1PROC)(REFIID riid, _COM_Outptr_ void **ppFactory);
|
||||
CreateDXGIFactory1PROC MyCreateDXGIFactory1 = (CreateDXGIFactory1PROC)GetProcAddress(dxgilib, "CreateDXGIFactory1");
|
||||
if (!MyCreateDXGIFactory1)
|
||||
Log.report(logvisor::Fatal, "unable to find CreateDXGIFactory1 in DXGI.dll\n");
|
||||
CreateDXGIFactory1PROC MyCreateDXGIFactory1 = CreateDXGIFactory1;
|
||||
|
||||
bool no12 = false;
|
||||
for (const SystemString& arg : args)
|
||||
@@ -106,30 +79,15 @@ public:
|
||||
no12 = true;
|
||||
|
||||
#if _WIN32_WINNT_WIN10
|
||||
HMODULE d3d12lib = LoadLibraryW(L"D3D12.dll");
|
||||
if (!no12 && d3d12lib)
|
||||
if (!no12)
|
||||
{
|
||||
#if _DEBUG
|
||||
{
|
||||
PFN_D3D12_GET_DEBUG_INTERFACE MyD3D12GetDebugInterface =
|
||||
(PFN_D3D12_GET_DEBUG_INTERFACE)GetProcAddress(d3d12lib, "D3D12GetDebugInterface");
|
||||
ComPtr<ID3D12Debug> debugController;
|
||||
if (SUCCEEDED(MyD3D12GetDebugInterface(IID_PPV_ARGS(&debugController))))
|
||||
{
|
||||
debugController->EnableDebugLayer();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (!FindBestD3DCompile())
|
||||
Log.report(logvisor::Fatal, "unable to find D3DCompile_[43-47].dll");
|
||||
|
||||
D3D12SerializeRootSignaturePROC =
|
||||
(PFN_D3D12_SERIALIZE_ROOT_SIGNATURE)GetProcAddress(d3d12lib, "D3D12SerializeRootSignature");
|
||||
D3D12SerializeRootSignaturePROC = D3D12SerializeRootSignature;
|
||||
|
||||
/* Create device */
|
||||
PFN_D3D12_CREATE_DEVICE MyD3D12CreateDevice = (PFN_D3D12_CREATE_DEVICE)GetProcAddress(d3d12lib, "D3D12CreateDevice");
|
||||
if (!MyD3D12CreateDevice)
|
||||
Log.report(logvisor::Fatal, "unable to find D3D12CreateDevice in D3D12.dll");
|
||||
PFN_D3D12_CREATE_DEVICE MyD3D12CreateDevice = D3D12CreateDevice;
|
||||
|
||||
/* Obtain DXGI Factory */
|
||||
HRESULT hr = MyCreateDXGIFactory1(__uuidof(IDXGIFactory2), &m_3dCtx.m_ctx12.m_dxFactory);
|
||||
@@ -191,16 +149,12 @@ public:
|
||||
}
|
||||
}
|
||||
#endif
|
||||
HMODULE d3d11lib = LoadLibraryW(L"D3D11.dll");
|
||||
if (d3d11lib)
|
||||
{
|
||||
if (!FindBestD3DCompile())
|
||||
Log.report(logvisor::Fatal, "unable to find D3DCompile_[43-47].dll");
|
||||
|
||||
/* Create device proc */
|
||||
PFN_D3D11_CREATE_DEVICE MyD3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE)GetProcAddress(d3d11lib, "D3D11CreateDevice");
|
||||
if (!MyD3D11CreateDevice)
|
||||
Log.report(logvisor::Fatal, "unable to find D3D11CreateDevice in D3D11.dll");
|
||||
PFN_D3D11_CREATE_DEVICE MyD3D11CreateDevice = D3D11CreateDevice;
|
||||
|
||||
/* Create device */
|
||||
D3D_FEATURE_LEVEL level = D3D_FEATURE_LEVEL_11_0;
|
||||
@@ -215,9 +169,6 @@ public:
|
||||
FAILED(tempCtx.As<ID3D11DeviceContext1>(&m_3dCtx.m_ctx11.m_devCtx)) || !m_3dCtx.m_ctx11.m_devCtx ||
|
||||
FAILED(m_3dCtx.m_ctx11.m_dev.As<IDXGIDevice2>(&device)) || !device)
|
||||
{
|
||||
MessageBoxW(nullptr, L"Windows 7 users should install 'Platform Update for Windows 7':\n"
|
||||
L"https://www.microsoft.com/en-us/download/details.aspx?id=36805",
|
||||
L"IDXGIDevice2 interface error", MB_OK | MB_ICONERROR);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -256,7 +207,7 @@ public:
|
||||
int clientReturn = 0;
|
||||
std::thread clientThread([&]()
|
||||
{
|
||||
std::string thrName = WCSTMBS(getFriendlyName().c_str()) + " Client Thread";
|
||||
std::string thrName = WCSTMBS(getFriendlyName().data()) + " Client Thread";
|
||||
logvisor::RegisterThreadName(thrName.c_str());
|
||||
clientReturn = m_callback.appMain(this);
|
||||
});
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
|
||||
#include "WinCommon.hpp"
|
||||
|
||||
using namespace Windows::ApplicationModel::Core;
|
||||
|
||||
struct Boo3DAppContextUWP : Boo3DAppContext
|
||||
{
|
||||
bool isFullscreen(const boo::IWindow* window)
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
extern DWORD g_mainThreadId;
|
||||
|
||||
#if _WIN32_WINNT_WINBLUE
|
||||
#if _WIN32_WINNT_WINBLUE && !WINDOWS_STORE
|
||||
#include <ShellScalingApi.h>
|
||||
typedef HRESULT (WINAPI* PFN_SetProcessDpiAwareness)( _In_ PROCESS_DPI_AWARENESS );
|
||||
typedef HRESULT (WINAPI* PFN_GetScaleFactorForMonitor)( _In_ HMONITOR, _Out_ DEVICE_SCALE_FACTOR *);
|
||||
@@ -187,12 +187,14 @@ struct Boo3DAppContextWin32 : Boo3DAppContext
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !WINDOWS_STORE
|
||||
OGLContext::Window& win = m_ctxOgl.m_windows[window];
|
||||
if (fs && win.m_fs)
|
||||
return false;
|
||||
else if (!fs && !win.m_fs)
|
||||
return false;
|
||||
SetFullscreen(win, fs);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -8,7 +8,10 @@
|
||||
#include "boo/audiodev/IAudioVoiceEngine.hpp"
|
||||
|
||||
using namespace Windows::UI::Core;
|
||||
using namespace Windows::UI::ViewManagement;
|
||||
using namespace Windows::System;
|
||||
using namespace Windows::Graphics::Display;
|
||||
using namespace Windows::Foundation;
|
||||
|
||||
namespace boo
|
||||
{
|
||||
@@ -178,67 +181,59 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
static void genFrameDefault(MONITORINFO* screen, int& xOut, int& yOut, int& wOut, int& hOut)
|
||||
{
|
||||
float width = screen->rcMonitor.right * 2.0 / 3.0;
|
||||
float height = screen->rcMonitor.bottom * 2.0 / 3.0;
|
||||
xOut = (screen->rcMonitor.right - width) / 2.0;
|
||||
yOut = (screen->rcMonitor.bottom - height) / 2.0;
|
||||
wOut = width;
|
||||
hOut = height;
|
||||
}
|
||||
|
||||
static uint32_t translateKeysym(VirtualKey sym, ESpecialKey& specialSym, EModifierKey& modifierSym)
|
||||
static uint32_t translateKeysym(CoreWindow^ window, VirtualKey sym,
|
||||
ESpecialKey& specialSym, EModifierKey& modifierSym)
|
||||
{
|
||||
specialSym = ESpecialKey::None;
|
||||
modifierSym = EModifierKey::None;
|
||||
if (sym >= VirtualKey_F1 && sym <= VirtualKey_F12)
|
||||
specialSym = ESpecialKey(uint32_t(ESpecialKey::F1) + sym - VirtualKey_F1);
|
||||
else if (sym == VirtualKey_Escape)
|
||||
if (sym >= VirtualKey::F1 && sym <= VirtualKey::F12)
|
||||
specialSym = ESpecialKey(uint32_t(ESpecialKey::F1) + uint32_t(sym - VirtualKey::F1));
|
||||
else if (sym == VirtualKey::Escape)
|
||||
specialSym = ESpecialKey::Esc;
|
||||
else if (sym == VirtualKey_Enter)
|
||||
else if (sym == VirtualKey::Enter)
|
||||
specialSym = ESpecialKey::Enter;
|
||||
else if (sym == VirtualKey_Back)
|
||||
else if (sym == VirtualKey::Back)
|
||||
specialSym = ESpecialKey::Backspace;
|
||||
else if (sym == VirtualKey_Insert)
|
||||
else if (sym == VirtualKey::Insert)
|
||||
specialSym = ESpecialKey::Insert;
|
||||
else if (sym == VirtualKey_Delete)
|
||||
else if (sym == VirtualKey::Delete)
|
||||
specialSym = ESpecialKey::Delete;
|
||||
else if (sym == VirtualKey_Home)
|
||||
else if (sym == VirtualKey::Home)
|
||||
specialSym = ESpecialKey::Home;
|
||||
else if (sym == VirtualKey_End)
|
||||
else if (sym == VirtualKey::End)
|
||||
specialSym = ESpecialKey::End;
|
||||
else if (sym == VirtualKey_PageUp)
|
||||
else if (sym == VirtualKey::PageUp)
|
||||
specialSym = ESpecialKey::PgUp;
|
||||
else if (sym == VirtualKey_PageDown)
|
||||
else if (sym == VirtualKey::PageDown)
|
||||
specialSym = ESpecialKey::PgDown;
|
||||
else if (sym == VirtualKey_Left)
|
||||
else if (sym == VirtualKey::Left)
|
||||
specialSym = ESpecialKey::Left;
|
||||
else if (sym == VirtualKey_Right)
|
||||
else if (sym == VirtualKey::Right)
|
||||
specialSym = ESpecialKey::Right;
|
||||
else if (sym == VirtualKey_Up)
|
||||
else if (sym == VirtualKey::Up)
|
||||
specialSym = ESpecialKey::Up;
|
||||
else if (sym == VirtualKey_Down)
|
||||
else if (sym == VirtualKey::Down)
|
||||
specialSym = ESpecialKey::Down;
|
||||
else if (sym == VirtualKey_Shift)
|
||||
else if (sym == VirtualKey::Shift)
|
||||
modifierSym = EModifierKey::Shift;
|
||||
else if (sym == VirtualKey_Control)
|
||||
else if (sym == VirtualKey::Control)
|
||||
modifierSym = EModifierKey::Ctrl;
|
||||
else if (sym == VirtualKey_Menu)
|
||||
else if (sym == VirtualKey::Menu)
|
||||
modifierSym = EModifierKey::Alt;
|
||||
else if (sym >= VirtualKey_A && sym <= VirtualKey_Z)
|
||||
return sym - VirtualKey_A + window->GetKeyState(VirtualKey_Shift) ? 'A' : 'a'
|
||||
else if (sym >= VirtualKey::A && sym <= VirtualKey::Z)
|
||||
return uint32_t(sym - VirtualKey::A) +
|
||||
(window->GetKeyState(VirtualKey::Shift) != CoreVirtualKeyStates::None) ? 'A' : 'a';
|
||||
return 0;
|
||||
}
|
||||
|
||||
static EModifierKey translateModifiers(CoreWindow^ window)
|
||||
{
|
||||
EModifierKey retval = EModifierKey::None;
|
||||
if (window->GetKeyState(VirtualKey_Shift) != None)
|
||||
if (window->GetKeyState(VirtualKey::Shift) != CoreVirtualKeyStates::None)
|
||||
retval |= EModifierKey::Shift;
|
||||
if (window->GetKeyState(VirtualKey_Control) != None)
|
||||
if (window->GetKeyState(VirtualKey::Control) != CoreVirtualKeyStates::None)
|
||||
retval |= EModifierKey::Ctrl;
|
||||
if (window->GetKeyState(LefVirtualKey_Menu) != None)
|
||||
if (window->GetKeyState(VirtualKey::Menu) != CoreVirtualKeyStates::None)
|
||||
retval |= EModifierKey::Alt;
|
||||
return retval;
|
||||
}
|
||||
@@ -253,7 +248,36 @@ class WindowUWP : public IWindow
|
||||
|
||||
public:
|
||||
|
||||
WindowUWP(SystemStringView title, Boo3DAppContext& b3dCtx, uint32_t sampleCount)
|
||||
ref struct EventReceiver sealed
|
||||
{
|
||||
void OnKeyDown(CoreWindow^ window, KeyEventArgs^ keyEventArgs)
|
||||
{
|
||||
w.OnKeyDown(window, keyEventArgs);
|
||||
}
|
||||
|
||||
void OnKeyUp(CoreWindow^ window, KeyEventArgs^ keyEventArgs)
|
||||
{
|
||||
w.OnKeyUp(window, keyEventArgs);
|
||||
}
|
||||
|
||||
void OnClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
|
||||
{
|
||||
w.OnClosed(sender, args);
|
||||
}
|
||||
|
||||
internal:
|
||||
WindowUWP& w;
|
||||
EventReceiver(WindowUWP& w) : w(w)
|
||||
{
|
||||
w.m_coreWindow->KeyDown += ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &EventReceiver::OnKeyDown);
|
||||
w.m_coreWindow->KeyUp += ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &EventReceiver::OnKeyUp);
|
||||
w.m_coreWindow->Closed += ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &EventReceiver::OnClosed);
|
||||
}
|
||||
};
|
||||
EventReceiver^ m_eventReceiver;
|
||||
|
||||
WindowUWP(SystemStringView title, Boo3DAppContextUWP& b3dCtx, uint32_t sampleCount)
|
||||
: m_eventReceiver(ref new EventReceiver(*this))
|
||||
{
|
||||
IGraphicsContext::EGraphicsAPI api = IGraphicsContext::EGraphicsAPI::D3D11;
|
||||
#if _WIN32_WINNT_WIN10
|
||||
@@ -263,9 +287,6 @@ public:
|
||||
m_gfxCtx.reset(new GraphicsContextUWPD3D(api, this, m_coreWindow, b3dCtx, sampleCount));
|
||||
|
||||
setTitle(title);
|
||||
m_coreWindow->KeyDown += ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &WindowUWP::OnKeyDown);
|
||||
m_coreWindow->KeyUp += ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &WindowUWP::OnKeyUp);
|
||||
m_coreWindow->Closed += ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &WindowUWP::OnClosed);
|
||||
}
|
||||
|
||||
~WindowUWP()
|
||||
@@ -293,12 +314,12 @@ public:
|
||||
|
||||
SystemString getTitle()
|
||||
{
|
||||
return SystemString(m_appView->Title.Data());
|
||||
return SystemString(m_appView->Title->Data());
|
||||
}
|
||||
|
||||
void setTitle(SystemStringView title)
|
||||
{
|
||||
m_appView->Title = title.data();
|
||||
m_appView->Title = ref new Platform::String(title.data());
|
||||
}
|
||||
|
||||
void setCursor(EMouseCursor cursor)
|
||||
@@ -315,18 +336,18 @@ public:
|
||||
|
||||
void getWindowFrame(float& xOut, float& yOut, float& wOut, float& hOut) const
|
||||
{
|
||||
xOut = m_coreWindow->bounds.X;
|
||||
yOut = m_coreWindow->bounds.Y;
|
||||
wOut = m_coreWindow->bounds.Width;
|
||||
hOut = m_coreWindow->bounds.Height;
|
||||
xOut = m_coreWindow->Bounds.X;
|
||||
yOut = m_coreWindow->Bounds.Y;
|
||||
wOut = m_coreWindow->Bounds.Width;
|
||||
hOut = m_coreWindow->Bounds.Height;
|
||||
}
|
||||
|
||||
void getWindowFrame(int& xOut, int& yOut, int& wOut, int& hOut) const
|
||||
{
|
||||
xOut = m_coreWindow->bounds.X;
|
||||
yOut = m_coreWindow->bounds.Y;
|
||||
wOut = m_coreWindow->bounds.Width;
|
||||
hOut = m_coreWindow->bounds.Height;
|
||||
xOut = m_coreWindow->Bounds.X;
|
||||
yOut = m_coreWindow->Bounds.Y;
|
||||
wOut = m_coreWindow->Bounds.Width;
|
||||
hOut = m_coreWindow->Bounds.Height;
|
||||
}
|
||||
|
||||
void setWindowFrame(float x, float y, float w, float h)
|
||||
@@ -339,8 +360,8 @@ public:
|
||||
|
||||
float getVirtualPixelFactor() const
|
||||
{
|
||||
DisplayInformation dispInfo = DisplayInformation::GetForCurrentView();
|
||||
return dispInfo.LogicalDpi / 96.f;
|
||||
DisplayInformation^ dispInfo = DisplayInformation::GetForCurrentView();
|
||||
return dispInfo->LogicalDpi / 96.f;
|
||||
}
|
||||
|
||||
bool isFullscreen() const
|
||||
@@ -359,6 +380,7 @@ public:
|
||||
|
||||
bool clipboardCopy(EClipboardType type, const uint8_t* data, size_t sz)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<uint8_t[]> clipboardPaste(EClipboardType type, size_t& sz)
|
||||
@@ -384,37 +406,31 @@ public:
|
||||
|
||||
void OnKeyDown(CoreWindow^ window, KeyEventArgs^ keyEventArgs)
|
||||
{
|
||||
if (auto w = m_window.lock())
|
||||
{
|
||||
ESpecialKey specialKey;
|
||||
EModifierKey modifierKey;
|
||||
uint32_t charCode = translateKeysym(keyEventArgs->VirtualKey, specialKey, modifierKey);
|
||||
EModifierKey modifierMask = translateModifiers(window);
|
||||
bool repeat = keyEventArgs->KeyStatus.RepeatCount > 1;
|
||||
if (charCode)
|
||||
m_callback->charKeyDown(charCode, modifierMask, repeat);
|
||||
else if (specialKey != ESpecialKey::None)
|
||||
m_callback->specialKeyDown(specialKey, modifierMask, repeat);
|
||||
else if (modifierKey != EModifierKey::None)
|
||||
m_callback->modKeyDown(modifierKey, repeat);
|
||||
}
|
||||
ESpecialKey specialKey;
|
||||
EModifierKey modifierKey;
|
||||
uint32_t charCode = translateKeysym(m_coreWindow, keyEventArgs->VirtualKey, specialKey, modifierKey);
|
||||
EModifierKey modifierMask = translateModifiers(window);
|
||||
bool repeat = keyEventArgs->KeyStatus.RepeatCount > 1;
|
||||
if (charCode)
|
||||
m_callback->charKeyDown(charCode, modifierMask, repeat);
|
||||
else if (specialKey != ESpecialKey::None)
|
||||
m_callback->specialKeyDown(specialKey, modifierMask, repeat);
|
||||
else if (modifierKey != EModifierKey::None)
|
||||
m_callback->modKeyDown(modifierKey, repeat);
|
||||
}
|
||||
|
||||
void OnKeyUp(CoreWindow^ window, KeyEventArgs^ keyEventArgs)
|
||||
{
|
||||
if (auto w = m_window.lock())
|
||||
{
|
||||
ESpecialKey specialKey;
|
||||
EModifierKey modifierKey;
|
||||
uint32_t charCode = translateKeysym(keyEventArgs->VirtualKey, specialKey, modifierKey);
|
||||
EModifierKey modifierMask = translateModifiers(window);
|
||||
if (charCode)
|
||||
m_callback->charKeyDown(charCode, modifierMask);
|
||||
else if (specialKey != ESpecialKey::None)
|
||||
m_callback->specialKeyDown(specialKey, modifierMask);
|
||||
else if (modifierKey != EModifierKey::None)
|
||||
m_callback->modKeyDown(modifierKey);
|
||||
}
|
||||
ESpecialKey specialKey;
|
||||
EModifierKey modifierKey;
|
||||
uint32_t charCode = translateKeysym(m_coreWindow, keyEventArgs->VirtualKey, specialKey, modifierKey);
|
||||
EModifierKey modifierMask = translateModifiers(window);
|
||||
if (charCode)
|
||||
m_callback->charKeyUp(charCode, modifierMask);
|
||||
else if (specialKey != ESpecialKey::None)
|
||||
m_callback->specialKeyUp(specialKey, modifierMask);
|
||||
else if (modifierKey != EModifierKey::None)
|
||||
m_callback->modKeyUp(modifierKey);
|
||||
}
|
||||
|
||||
void OnClosed(CoreWindow ^sender, CoreWindowEventArgs ^args)
|
||||
@@ -459,7 +475,7 @@ public:
|
||||
|
||||
};
|
||||
|
||||
std::shared_ptr<IWindow> _WindowUAPNew(SystemStringView title, Boo3DAppContext& d3dCtx,
|
||||
std::shared_ptr<IWindow> _WindowUWPNew(SystemStringView title, Boo3DAppContextUWP& d3dCtx,
|
||||
uint32_t sampleCount)
|
||||
{
|
||||
return std::make_shared<WindowUWP>(title, d3dCtx, sampleCount);
|
||||
|
||||
Reference in New Issue
Block a user