Windows fixes; experimental UWP framework (not working)

This commit is contained in:
Jack Andersen 2017-10-23 17:09:50 -10:00
parent 41d225bd64
commit d1b980b529
12 changed files with 1114 additions and 134 deletions

View File

@ -33,7 +33,7 @@ set(BOO_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include CACHE PATH "boo include
include_directories(include xxhash ${LOGVISOR_INCLUDE_DIR})
if(NOT GEKKO AND NOT CAFE)
if(NOT GEKKO AND NOT CAFE AND NOT WINDOWS_STORE)
list(APPEND PLAT_SRCS
lib/graphicsdev/GL.cpp
lib/graphicsdev/glew.c)
@ -47,8 +47,26 @@ list(APPEND PLAT_HDRS
add_library(glew lib/graphicsdev/glew.c)
endif()
if(WIN32)
if(WINDOWS_STORE)
list(APPEND PLAT_SRCS
lib/win/ApplicationUWP.cpp
lib/win/WindowUWP.cpp
lib/win/WinCommon.hpp
lib/win/UWPCommon.hpp
lib/inputdev/HIDListenerWinUSB.cpp
lib/inputdev/HIDDeviceWinUSB.cpp
lib/graphicsdev/D3D11.cpp
lib/graphicsdev/D3D12.cpp
lib/audiodev/WASAPI.cpp)
list(APPEND PLAT_HDRS
include/boo/graphicsdev/D3D.hpp)
list(APPEND _BOO_SYS_DEFINES -DUNICODE -D_UNICODE)
list(APPEND _BOO_SYS_LIBS Winusb opengl32 Setupapi Imm32 Winmm Shlwapi Hid Xinput)
elseif(WIN32)
unset(VULKAN_SDK_DIRS CACHE)
get_filename_component(VULKAN_SDK_DIRS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\LunarG\\VulkanSDK;VK_SDK_PATHs]" ABSOLUTE CACHE)
if (NOT ${VULKAN_SDK_DIRS} STREQUAL "/registry")
@ -64,6 +82,7 @@ if(WIN32)
list(APPEND PLAT_SRCS
lib/win/ApplicationWin32.cpp
lib/win/WindowWin32.cpp
lib/win/WinCommon.hpp
lib/win/Win32Common.hpp
lib/inputdev/HIDListenerWinUSB.cpp
lib/inputdev/HIDDeviceWinUSB.cpp
@ -77,6 +96,7 @@ if(WIN32)
list(APPEND _BOO_SYS_DEFINES -DUNICODE -D_UNICODE)
list(APPEND _BOO_SYS_LIBS Winusb opengl32 Setupapi Imm32 Winmm Shlwapi Hid Xinput)
elseif(APPLE)
list(APPEND PLAT_SRCS
lib/mac/ApplicationCocoa.mm
@ -115,6 +135,7 @@ elseif(APPLE)
list(APPEND _BOO_SYS_LIBS ${APPKIT_LIBRARY} ${IOKIT_LIBRARY} ${OPENGL_LIBRARY} ${METAL_LIBRARY}
${QUARTZCORE_LIBRARY} ${COREVIDEO_LIBRARY} ${AUDIOTOOLBOX_LIBRARY}
${COREAUDIO_LIBRARY} ${COREMIDI_LIBRARY})
else(NOT GEKKO)
list(APPEND PLAT_SRCS
lib/x11/XlibCommon.hpp

View File

@ -33,26 +33,16 @@ set(_IPP_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
if(WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib)
set(IPP_LIBNAME_SUFFIX mt)
else()
if(IPP_STATIC)
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES .so)
endif()
endif()
if(IPP_STATIC)
if(IPP_MULTI_THREADED)
set(IPP_LIBNAME_SUFFIX _t)
else()
set(IPP_LIBNAME_SUFFIX _l)
endif()
else()
set(IPP_LIBNAME_SUFFIX "")
endif()
set(IPP_LIBNAME_SUFFIX "")
macro(find_ipp_library IPP_COMPONENT)
string(TOLOWER ${IPP_COMPONENT} IPP_COMPONENT_LOWER)

View File

@ -38,7 +38,7 @@ public:
Cocoa = 4,
CocoaTouch = 5,
Win32 = 6,
WinRT = 7,
UWP = 7,
Revolution = 8,
Cafe = 9
};
@ -80,6 +80,38 @@ ApplicationRun(IApplication::EPlatformType platform,
args.push_back(argv[i]);
return ApplicationRun(platform, cb, uniqueName, friendlyName, argv[0], args, singleInstance);
}
#if WINAPI_FAMILY && WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP
using namespace Windows::ApplicationModel::Core;
ref struct ViewProvider sealed : IFrameworkViewSource
{
ViewProvider(boo::IApplicationCallback& appCb,
const SystemString& uniqueName,
const SystemString& friendlyName,
const SystemString& pname,
Platform::Array<Platform::String^>^ params,
bool singleInstance)
: m_appCb(appCb), m_uniqueName(uniqueName), m_friendlyName(friendlyName),
m_pname(pname), m_singleInstance(singleInstance)
{
SystemChar selfPath[1024];
GetModuleFileNameW(nullptr, selfPath, 1024);
m_args.reserve(params.size() + 1);
m_args.emplace_back(selfPath);
for (Platform::String^ str : params)
m_args.emplace_back(str.Data());
}
IFrameworkView^ CreateView();
boo::IApplicationCallback& m_appCb;
SystemString m_uniqueName;
SystemString m_friendlyName;
SystemString m_pname;
std::vector<SystemString> m_args;
bool m_singleInstance;
};
#endif
}

View File

@ -1369,6 +1369,7 @@ public:
if (FAILED(D3DCompilePROC(vertSource, strlen(vertSource), "HECL Vert Source", nullptr, nullptr, "main",
"vs_5_0", BOO_D3DCOMPILE_FLAG, 0, &vertBlobOut, &errBlob)))
{
printf("%s\n", vertSource);
Log.report(logvisor::Fatal, "error compiling vert shader: %s", errBlob->GetBufferPointer());
}
@ -1387,6 +1388,7 @@ public:
if (FAILED(D3DCompilePROC(fragSource, strlen(fragSource), "HECL Pixel Source", nullptr, nullptr, "main",
"ps_5_0", BOO_D3DCOMPILE_FLAG, 0, &fragBlobOut, &errBlob)))
{
printf("%s\n", fragSource);
Log.report(logvisor::Fatal, "error compiling pixel shader: %s", errBlob->GetBufferPointer());
}

356
lib/win/ApplicationUWP.cpp Normal file
View File

@ -0,0 +1,356 @@
#include "UWPCommon.hpp"
using namespace Windows::Foundation;
using namespace Windows::UI::Core;
using namespace Windows::ApplicationModel::Activation;
using namespace Platform;
#if _DEBUG
#define D3D11_CREATE_DEVICE_FLAGS D3D11_CREATE_DEVICE_DEBUG
#else
#define D3D11_CREATE_DEVICE_FLAGS 0
#endif
#include "boo/System.hpp"
#include "boo/IApplication.hpp"
#include "boo/inputdev/DeviceFinder.hpp"
#include "boo/graphicsdev/D3D.hpp"
#include "logvisor/logvisor.hpp"
#if _WIN32_WINNT_WIN10
PFN_D3D12_SERIALIZE_ROOT_SIGNATURE D3D12SerializeRootSignaturePROC = nullptr;
#endif
pD3DCompile D3DCompilePROC = nullptr;
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;
}
namespace boo
{
static logvisor::Module Log("boo::ApplicationUWP");
std::shared_ptr<IWindow> _WindowUWPNew(const SystemString& title, Boo3DAppContextUWP& d3dCtx,
uint32_t sampleCount);
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;
std::shared_ptr<IWindow> m_window;
bool m_singleInstance;
bool m_issuedWindow = false;
Boo3DAppContextUWP m_3dCtx;
void _deletedWindow(IWindow* window)
{
}
public:
ApplicationUWP(IApplicationCallback& callback,
const SystemString& uniqueName,
const SystemString& friendlyName,
const SystemString& pname,
const std::vector<SystemString>& args,
bool singleInstance)
: m_callback(callback),
m_uniqueName(uniqueName),
m_friendlyName(friendlyName),
m_pname(pname),
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");
bool no12 = false;
for (const SystemString& arg : args)
if (!arg.compare(L"--d3d11"))
no12 = true;
#if _WIN32_WINNT_WIN10
HMODULE d3d12lib = LoadLibraryW(L"D3D12.dll");
if (!no12 && d3d12lib)
{
#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");
/* 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");
/* Obtain DXGI Factory */
HRESULT hr = MyCreateDXGIFactory1(__uuidof(IDXGIFactory2), &m_3dCtx.m_ctx12.m_dxFactory);
if (FAILED(hr))
Log.report(logvisor::Fatal, "unable to create DXGI factory");
/* Adapter */
ComPtr<IDXGIAdapter1> ppAdapter;
for (UINT adapterIndex = 0; ; ++adapterIndex)
{
ComPtr<IDXGIAdapter1> pAdapter;
if (DXGI_ERROR_NOT_FOUND == m_3dCtx.m_ctx12.m_dxFactory->EnumAdapters1(adapterIndex, &pAdapter))
break;
// Check to see if the adapter supports Direct3D 12, but don't create the
// actual device yet.
if (SUCCEEDED(MyD3D12CreateDevice(pAdapter.Get(), D3D_FEATURE_LEVEL_11_0, _uuidof(ID3D12Device), nullptr)))
{
ppAdapter = std::move(pAdapter);
break;
}
}
/* Create device */
hr = ppAdapter ? MyD3D12CreateDevice(ppAdapter.Get(), D3D_FEATURE_LEVEL_11_0, __uuidof(ID3D12Device), &m_3dCtx.m_ctx12.m_dev) : E_FAIL;
if (!FAILED(hr))
{
/* Establish loader objects */
if (FAILED(m_3dCtx.m_ctx12.m_dev->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
__uuidof(ID3D12CommandAllocator), &m_3dCtx.m_ctx12.m_loadqalloc)))
Log.report(logvisor::Fatal, "unable to create loader allocator");
D3D12_COMMAND_QUEUE_DESC desc =
{
D3D12_COMMAND_LIST_TYPE_DIRECT,
D3D12_COMMAND_QUEUE_PRIORITY_NORMAL,
D3D12_COMMAND_QUEUE_FLAG_NONE
};
if (FAILED(m_3dCtx.m_ctx12.m_dev->CreateCommandQueue(&desc, __uuidof(ID3D12CommandQueue), &m_3dCtx.m_ctx12.m_loadq)))
Log.report(logvisor::Fatal, "unable to create loader queue");
if (FAILED(m_3dCtx.m_ctx12.m_dev->CreateFence(0, D3D12_FENCE_FLAG_NONE, __uuidof(ID3D12Fence), &m_3dCtx.m_ctx12.m_loadfence)))
Log.report(logvisor::Fatal, "unable to create loader fence");
m_3dCtx.m_ctx12.m_loadfencehandle = CreateEvent(nullptr, FALSE, FALSE, nullptr);
if (FAILED(m_3dCtx.m_ctx12.m_dev->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_3dCtx.m_ctx12.m_loadqalloc.Get(),
nullptr, __uuidof(ID3D12GraphicsCommandList), &m_3dCtx.m_ctx12.m_loadlist)))
Log.report(logvisor::Fatal, "unable to create loader list");
Log.report(logvisor::Info, "initialized D3D12 renderer");
return;
}
else
{
/* Some Win10 client HW doesn't support D3D12 (despite being supposedly HW-agnostic) */
m_3dCtx.m_ctx12.m_dev.Reset();
m_3dCtx.m_ctx12.m_dxFactory.Reset();
}
}
#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");
/* Create device */
D3D_FEATURE_LEVEL level = D3D_FEATURE_LEVEL_11_0;
ComPtr<ID3D11Device> tempDev;
ComPtr<ID3D11DeviceContext> tempCtx;
if (FAILED(MyD3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, D3D11_CREATE_DEVICE_FLAGS, &level,
1, D3D11_SDK_VERSION, &tempDev, nullptr, &tempCtx)))
Log.report(logvisor::Fatal, "unable to create D3D11 device");
ComPtr<IDXGIDevice2> device;
if (FAILED(tempDev.As<ID3D11Device1>(&m_3dCtx.m_ctx11.m_dev)) || !m_3dCtx.m_ctx11.m_dev ||
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);
}
/* Obtain DXGI Factory */
ComPtr<IDXGIAdapter> adapter;
device->GetParent(__uuidof(IDXGIAdapter), &adapter);
adapter->GetParent(__uuidof(IDXGIFactory2), &m_3dCtx.m_ctx11.m_dxFactory);
/* Build default sampler here */
CD3D11_SAMPLER_DESC sampDesc(D3D11_DEFAULT);
sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
m_3dCtx.m_ctx11.m_dev->CreateSamplerState(&sampDesc, &m_3dCtx.m_ctx11.m_ss[0]);
sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_BORDER;
sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_BORDER;
sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
m_3dCtx.m_ctx11.m_dev->CreateSamplerState(&sampDesc, &m_3dCtx.m_ctx11.m_ss[1]);
Log.report(logvisor::Info, "initialized D3D11 renderer");
return;
}
Log.report(logvisor::Fatal, "system doesn't support D3D11 or D3D12");
}
EPlatformType getPlatformType() const
{
return EPlatformType::UWP;
}
int run()
{
/* Spawn client thread */
int clientReturn = 0;
std::thread clientThread([&]()
{
logvisor::RegisterThreadName("Boo Client Thread");
clientReturn = m_callback.appMain(this);
});
m_callback.appQuitting(this);
clientThread.join();
return clientReturn;
}
const SystemString& getUniqueName() const
{
return m_uniqueName;
}
const SystemString& getFriendlyName() const
{
return m_friendlyName;
}
const SystemString& getProcessName() const
{
return m_pname;
}
const std::vector<SystemString>& getArgs() const
{
return m_args;
}
std::shared_ptr<IWindow> newWindow(const SystemString& title, uint32_t sampleCount)
{
if (!m_issuedWindow)
{
m_issuedWindow = true;
return m_window;
}
return {};
}
void _setWindow(CoreWindow^ window)
{
m_window = _WindowUWPNew(m_friendlyName, m_3dCtx, 1);
}
};
IApplication* APP = NULL;
ref class AppView sealed : public IFrameworkView
{
ApplicationUWP m_app;
internal:
AppView(IApplicationCallback& callback,
const SystemString& uniqueName,
const SystemString& friendlyName,
const SystemString& pname,
const std::vector<SystemString>& args,
bool singleInstance)
: m_app(callback, uniqueName, friendlyName, pname, args, singleInstance) { APP = &m_app; }
public:
virtual void Initialize(CoreApplicationView^ applicationView)
{
applicationView->Activated += ref new TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &AppView::OnActivated);
}
virtual void SetWindow(CoreWindow^ window)
{
m_app._setWindow(window);
}
virtual void Load(String^ entryPoint)
{
}
virtual void Run()
{
m_app.run();
}
virtual void Uninitialize()
{
}
void OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
{
CoreWindow::GetForCurrentThread()->Activate();
}
};
IFrameworkView^ ViewProvider::CreateView()
{
return ref new AppView(m_appCb, m_uniqueName, m_friendlyName, m_pname, m_args, m_singleInstance);
}
}

View File

@ -15,8 +15,6 @@ PFN_GetScaleFactorForMonitor MyGetScaleFactorForMonitor = nullptr;
#define D3D11_CREATE_DEVICE_FLAGS 0
#endif
#include <unordered_map>
#include "boo/System.hpp"
#include "boo/IApplication.hpp"
#include "boo/inputdev/DeviceFinder.hpp"
@ -69,7 +67,7 @@ namespace boo
static logvisor::Module Log("boo::ApplicationWin32");
Win32Cursors WIN32_CURSORS;
std::shared_ptr<IWindow> _WindowWin32New(const SystemString& title, Boo3DAppContext& d3dCtx,
std::shared_ptr<IWindow> _WindowWin32New(const SystemString& title, Boo3DAppContextWin32& d3dCtx,
void* vulkanHandle, uint32_t sampleCount);
class ApplicationWin32 final : public IApplication
@ -82,7 +80,7 @@ class ApplicationWin32 final : public IApplication
std::unordered_map<HWND, std::weak_ptr<IWindow>> m_allWindows;
bool m_singleInstance;
Boo3DAppContext m_3dCtx;
Boo3DAppContextWin32 m_3dCtx;
#if BOO_HAS_VULKAN
PFN_vkGetInstanceProcAddr m_getVkProc = nullptr;
#endif

89
lib/win/UWPCommon.hpp Normal file
View File

@ -0,0 +1,89 @@
#ifndef BOO_UWPCOMMON_HPP
#define BOO_UWPCOMMON_HPP
#include "WinCommon.hpp"
using namespace Windows::ApplicationModel::Core;
struct Boo3DAppContextUWP : Boo3DAppContext
{
bool isFullscreen(const boo::IWindow* window)
{
#if _WIN32_WINNT_WIN10
if (m_ctx12.m_dev)
{
D3D12Context::Window& win = m_ctx12.m_windows[window];
BOOL isFScr;
win.m_swapChain->GetFullscreenState(&isFScr, nullptr);
return isFScr != 0;
}
#endif
if (m_ctx11.m_dev)
{
D3D11Context::Window& win = m_ctx11.m_windows[window];
BOOL isFScr;
win.m_swapChain->GetFullscreenState(&isFScr, nullptr);
return isFScr != 0;
}
return false;
}
bool setFullscreen(boo::IWindow* window, bool fs)
{
#if _WIN32_WINNT_WIN10
if (m_ctx12.m_dev)
{
D3D12Context::Window& win = m_ctx12.m_windows[window];
BOOL isFScr;
win.m_swapChain->GetFullscreenState(&isFScr, nullptr);
if (fs && isFScr)
return false;
else if (!fs && !isFScr)
return false;
if (fs)
{
ComPtr<IDXGIOutput> out;
win.m_swapChain->GetContainingOutput(&out);
DXGI_OUTPUT_DESC outDesc;
out->GetDesc(&outDesc);
win.m_swapChain->SetFullscreenState(true, nullptr);
DXGI_MODE_DESC mdesc = {UINT(outDesc.DesktopCoordinates.right - outDesc.DesktopCoordinates.left),
UINT(outDesc.DesktopCoordinates.bottom - outDesc.DesktopCoordinates.top)};
win.m_swapChain->ResizeTarget(&mdesc);
}
else
win.m_swapChain->SetFullscreenState(false, nullptr);
return true;
}
#endif
if (m_ctx11.m_dev)
{
D3D11Context::Window& win = m_ctx11.m_windows[window];
BOOL isFScr;
win.m_swapChain->GetFullscreenState(&isFScr, nullptr);
if (fs && isFScr)
return false;
else if (!fs && !isFScr)
return false;
if (fs)
{
ComPtr<IDXGIOutput> out;
win.m_swapChain->GetContainingOutput(&out);
DXGI_OUTPUT_DESC outDesc;
out->GetDesc(&outDesc);
win.m_fsdesc.Width = outDesc.DesktopCoordinates.right;
win.m_fsdesc.Height = outDesc.DesktopCoordinates.bottom;
}
win.m_fs = fs;
win.m_needsFSTransition = true;
return true;
}
return false;
}
};
#endif // BOO_UWPCOMMON_HPP

View File

@ -7,15 +7,11 @@
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif
#include "WinCommon.hpp"
#include <windows.h>
#include <unordered_map>
extern DWORD g_mainThreadId;
#include "boo/IWindow.hpp"
namespace boo {class IWindow;}
#if _WIN32_WINNT_WINBLUE
#include <ShellScalingApi.h>
typedef HRESULT (WINAPI* PFN_SetProcessDpiAwareness)( _In_ PROCESS_DPI_AWARENESS );
@ -23,64 +19,6 @@ typedef HRESULT (WINAPI* PFN_GetScaleFactorForMonitor)( _In_ HMONITOR, _Out_ DEV
extern PFN_GetScaleFactorForMonitor MyGetScaleFactorForMonitor;
#endif
#if _WIN32_WINNT_WIN10
#include <dxgi1_4.h>
#include <d3d12.h>
#include <d3d11_1.h>
#include <d3dcompiler.h>
#include <wingdi.h>
struct D3D12Context
{
ComPtr<IDXGIFactory2> m_dxFactory;
ComPtr<ID3D12Device> m_dev;
ComPtr<ID3D12CommandAllocator> m_qalloc[2];
ComPtr<ID3D12CommandQueue> m_q;
ComPtr<ID3D12CommandAllocator> m_loadqalloc;
ComPtr<ID3D12CommandQueue> m_loadq;
ComPtr<ID3D12Fence> m_loadfence;
UINT64 m_loadfenceval = 0;
HANDLE m_loadfencehandle;
ComPtr<ID3D12GraphicsCommandList> m_loadlist;
ComPtr<ID3D12RootSignature> m_rs;
struct Window
{
ComPtr<IDXGISwapChain3> m_swapChain;
UINT m_backBuf = 0;
bool m_needsResize = false;
size_t width, height;
};
std::unordered_map<const boo::IWindow*, Window> m_windows;
};
#elif _WIN32_WINNT_WIN7
#include <dxgi1_2.h>
#include <d3d11_1.h>
#include <d3dcompiler.h>
#include <wingdi.h>
#else
#error Unsupported Windows target
#endif
struct D3D11Context
{
ComPtr<IDXGIFactory2> m_dxFactory;
ComPtr<ID3D11Device1> m_dev;
ComPtr<ID3D11DeviceContext1> m_devCtx;
ComPtr<ID3D11SamplerState> m_ss[2];
struct Window
{
ComPtr<IDXGISwapChain1> m_swapChain;
bool m_needsResize = false;
size_t width, height;
bool m_needsFSTransition = false;
bool m_fs = false;
DXGI_MODE_DESC m_fsdesc = {};
};
std::unordered_map<const boo::IWindow*, Window> m_windows;
};
struct OGLContext
{
ComPtr<IDXGIFactory1> m_dxFactory;
@ -103,35 +41,11 @@ struct OGLContext
std::unordered_map<const boo::IWindow*, Window> m_windows;
};
struct Boo3DAppContext
struct Boo3DAppContextWin32 : Boo3DAppContext
{
D3D11Context m_ctx11;
#if _WIN32_WINNT_WIN10
D3D12Context m_ctx12;
#endif
OGLContext m_ctxOgl;
ComPtr<IDXGIFactory1> m_vulkanDxFactory;
void resize(boo::IWindow* window, size_t width, size_t height)
{
#if _WIN32_WINNT_WIN10
if (m_ctx12.m_dev)
{
D3D12Context::Window& win = m_ctx12.m_windows[window];
win.width = width;
win.height = height;
win.m_needsResize = true;
}
else
#endif
{
D3D11Context::Window& win = m_ctx11.m_windows[window];
win.width = width;
win.height = height;
win.m_needsResize = true;
}
}
bool isFullscreen(const boo::IWindow* window)
{
#if _WIN32_WINNT_WIN10

96
lib/win/WinCommon.hpp Normal file
View File

@ -0,0 +1,96 @@
#ifndef BOO_WI2COMMON_HPP
#define BOO_WINCOMMON_HPP
#include <unordered_map>
#include "boo/IWindow.hpp"
namespace boo {class IWindow;}
#if _WIN32_WINNT_WIN10
#include <dxgi1_4.h>
#include <d3d12.h>
#include <d3d11_1.h>
#include <d3dcompiler.h>
#include <wingdi.h>
#elif _WIN32_WINNT_WIN7
#include <dxgi1_2.h>
#include <d3d11_1.h>
#include <d3dcompiler.h>
#include <wingdi.h>
#else
#error Unsupported Windows target
#endif
struct D3D12Context
{
ComPtr<IDXGIFactory2> m_dxFactory;
ComPtr<ID3D12Device> m_dev;
ComPtr<ID3D12CommandAllocator> m_qalloc[2];
ComPtr<ID3D12CommandQueue> m_q;
ComPtr<ID3D12CommandAllocator> m_loadqalloc;
ComPtr<ID3D12CommandQueue> m_loadq;
ComPtr<ID3D12Fence> m_loadfence;
UINT64 m_loadfenceval = 0;
HANDLE m_loadfencehandle;
ComPtr<ID3D12GraphicsCommandList> m_loadlist;
ComPtr<ID3D12RootSignature> m_rs;
struct Window
{
ComPtr<IDXGISwapChain3> m_swapChain;
UINT m_backBuf = 0;
bool m_needsResize = false;
size_t width, height;
};
std::unordered_map<const boo::IWindow*, Window> m_windows;
};
struct D3D11Context
{
ComPtr<IDXGIFactory2> m_dxFactory;
ComPtr<ID3D11Device1> m_dev;
ComPtr<ID3D11DeviceContext1> m_devCtx;
ComPtr<ID3D11SamplerState> m_ss[2];
struct Window
{
ComPtr<IDXGISwapChain1> m_swapChain;
bool m_needsResize = false;
size_t width, height;
bool m_needsFSTransition = false;
bool m_fs = false;
DXGI_MODE_DESC m_fsdesc = {};
};
std::unordered_map<const boo::IWindow*, Window> m_windows;
};
struct Boo3DAppContext
{
D3D11Context m_ctx11;
#if _WIN32_WINNT_WIN10
D3D12Context m_ctx12;
#endif
void resize(boo::IWindow* window, size_t width, size_t height)
{
#if _WIN32_WINNT_WIN10
if (m_ctx12.m_dev)
{
D3D12Context::Window& win = m_ctx12.m_windows[window];
win.width = width;
win.height = height;
win.m_needsResize = true;
}
else
#endif
{
D3D11Context::Window& win = m_ctx11.m_windows[window];
win.width = width;
win.height = height;
win.m_needsResize = true;
}
}
};
#endif // BOO_WINCOMMON_HPP

468
lib/win/WindowUWP.cpp Normal file
View File

@ -0,0 +1,468 @@
#include "UWPCommon.hpp"
#include "boo/IApplication.hpp"
#include "boo/IWindow.hpp"
#include "boo/IGraphicsContext.hpp"
#include "logvisor/logvisor.hpp"
#include "boo/graphicsdev/D3D.hpp"
#include "boo/audiodev/IAudioVoiceEngine.hpp"
using namespace Windows::UI::Core;
using namespace Windows::System;
namespace boo
{
static logvisor::Module Log("boo::WindowWin32");
#if _WIN32_WINNT_WIN10
IGraphicsCommandQueue* _NewD3D12CommandQueue(D3D12Context* ctx, D3D12Context::Window* windowCtx, IGraphicsContext* parent,
ID3D12CommandQueue** cmdQueueOut);
IGraphicsDataFactory* _NewD3D12DataFactory(D3D12Context* ctx, IGraphicsContext* parent, uint32_t sampleCount);
#endif
IGraphicsCommandQueue* _NewD3D11CommandQueue(D3D11Context* ctx, D3D11Context::Window* windowCtx, IGraphicsContext* parent);
IGraphicsDataFactory* _NewD3D11DataFactory(D3D11Context* ctx, IGraphicsContext* parent, uint32_t sampleCount);
struct GraphicsContextUWP : IGraphicsContext
{
EGraphicsAPI m_api;
EPixelFormat m_pf;
IWindow* m_parentWindow;
Boo3DAppContextUWP& m_3dCtx;
ComPtr<IDXGIOutput> m_output;
GraphicsContextUWP(EGraphicsAPI api, IWindow* parentWindow, Boo3DAppContextUWP& b3dCtx)
: m_api(api),
m_pf(EPixelFormat::RGBA8),
m_parentWindow(parentWindow),
m_3dCtx(b3dCtx) {}
virtual void resized(const SWindowRect& rect)
{
m_3dCtx.resize(m_parentWindow, rect.size[0], rect.size[1]);
}
};
struct GraphicsContextUWPD3D : GraphicsContextUWP
{
ComPtr<IDXGISwapChain1> m_swapChain;
IGraphicsCommandQueue* m_commandQueue = nullptr;
IGraphicsDataFactory* m_dataFactory = nullptr;
public:
IWindowCallback* m_callback;
GraphicsContextUWPD3D(EGraphicsAPI api, IWindow* parentWindow, CoreWindow^ coreWindow,
Boo3DAppContextUWP& b3dCtx, uint32_t sampleCount)
: GraphicsContextUWP(api, parentWindow, b3dCtx)
{
/* Create Swap Chain */
DXGI_SWAP_CHAIN_DESC1 scDesc = {};
scDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
scDesc.SampleDesc.Count = 1;
scDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
scDesc.BufferCount = 2;
scDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
scDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
IUnknown* cw = reinterpret_cast<IUnknown*>(coreWindow);
#if _WIN32_WINNT_WIN10
if (b3dCtx.m_ctx12.m_dev)
{
auto insIt = b3dCtx.m_ctx12.m_windows.emplace(std::make_pair(parentWindow, D3D12Context::Window()));
D3D12Context::Window& w = insIt.first->second;
ID3D12CommandQueue* cmdQueue;
m_dataFactory = _NewD3D12DataFactory(&b3dCtx.m_ctx12, this, sampleCount);
m_commandQueue = _NewD3D12CommandQueue(&b3dCtx.m_ctx12, &w, this, &cmdQueue);
scDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
HRESULT hr = b3dCtx.m_ctx12.m_dxFactory->CreateSwapChainForCoreWindow(cmdQueue,
cw, &scDesc, nullptr, &m_swapChain);
if (FAILED(hr))
Log.report(logvisor::Fatal, "unable to create swap chain");
m_swapChain.As<IDXGISwapChain3>(&w.m_swapChain);
ComPtr<ID3D12Resource> fb;
m_swapChain->GetBuffer(0, __uuidof(ID3D12Resource), &fb);
w.m_backBuf = w.m_swapChain->GetCurrentBackBufferIndex();
D3D12_RESOURCE_DESC resDesc = fb->GetDesc();
w.width = resDesc.Width;
w.height = resDesc.Height;
if (FAILED(m_swapChain->GetContainingOutput(&m_output)))
Log.report(logvisor::Fatal, "unable to get DXGI output");
}
else
#endif
{
if (FAILED(b3dCtx.m_ctx11.m_dxFactory->CreateSwapChainForCoreWindow(b3dCtx.m_ctx11.m_dev.Get(),
cw, &scDesc, nullptr, &m_swapChain)))
Log.report(logvisor::Fatal, "unable to create swap chain");
auto insIt = b3dCtx.m_ctx11.m_windows.emplace(std::make_pair(parentWindow, D3D11Context::Window()));
D3D11Context::Window& w = insIt.first->second;
m_swapChain.As<IDXGISwapChain1>(&w.m_swapChain);
ComPtr<ID3D11Texture2D> fbRes;
m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), &fbRes);
D3D11_TEXTURE2D_DESC resDesc;
fbRes->GetDesc(&resDesc);
w.width = resDesc.Width;
w.height = resDesc.Height;
m_dataFactory = _NewD3D11DataFactory(&b3dCtx.m_ctx11, this, sampleCount);
m_commandQueue = _NewD3D11CommandQueue(&b3dCtx.m_ctx11, &insIt.first->second, this);
if (FAILED(m_swapChain->GetContainingOutput(&m_output)))
Log.report(logvisor::Fatal, "unable to get DXGI output");
}
}
~GraphicsContextUWPD3D()
{
#if _WIN32_WINNT_WIN10
if (m_3dCtx.m_ctx12.m_dev)
m_3dCtx.m_ctx12.m_windows.erase(m_parentWindow);
else
#endif
m_3dCtx.m_ctx11.m_windows.erase(m_parentWindow);
}
void _setCallback(IWindowCallback* cb)
{
m_callback = cb;
}
EGraphicsAPI getAPI() const
{
return m_api;
}
EPixelFormat getPixelFormat() const
{
return m_pf;
}
void setPixelFormat(EPixelFormat pf)
{
if (pf > EPixelFormat::RGBAF32_Z24)
return;
m_pf = pf;
}
bool initializeContext(void*) {return true;}
void makeCurrent() {}
void postInit() {}
void present() {}
IGraphicsCommandQueue* getCommandQueue()
{
return m_commandQueue;
}
IGraphicsDataFactory* getDataFactory()
{
return m_dataFactory;
}
IGraphicsDataFactory* getMainContextDataFactory()
{
return m_dataFactory;
}
IGraphicsDataFactory* getLoadContextDataFactory()
{
return m_dataFactory;
}
};
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)
{
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)
specialSym = ESpecialKey::Esc;
else if (sym == VirtualKey_Enter)
specialSym = ESpecialKey::Enter;
else if (sym == VirtualKey_Back)
specialSym = ESpecialKey::Backspace;
else if (sym == VirtualKey_Insert)
specialSym = ESpecialKey::Insert;
else if (sym == VirtualKey_Delete)
specialSym = ESpecialKey::Delete;
else if (sym == VirtualKey_Home)
specialSym = ESpecialKey::Home;
else if (sym == VirtualKey_End)
specialSym = ESpecialKey::End;
else if (sym == VirtualKey_PageUp)
specialSym = ESpecialKey::PgUp;
else if (sym == VirtualKey_PageDown)
specialSym = ESpecialKey::PgDown;
else if (sym == VirtualKey_Left)
specialSym = ESpecialKey::Left;
else if (sym == VirtualKey_Right)
specialSym = ESpecialKey::Right;
else if (sym == VirtualKey_Up)
specialSym = ESpecialKey::Up;
else if (sym == VirtualKey_Down)
specialSym = ESpecialKey::Down;
else if (sym == VirtualKey_Shift)
modifierSym = EModifierKey::Shift;
else if (sym == VirtualKey_Control)
modifierSym = EModifierKey::Ctrl;
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'
return 0;
}
static EModifierKey translateModifiers(CoreWindow^ window)
{
EModifierKey retval = EModifierKey::None;
if (window->GetKeyState(VirtualKey_Shift) != None)
retval |= EModifierKey::Shift;
if (window->GetKeyState(VirtualKey_Control) != None)
retval |= EModifierKey::Ctrl;
if (window->GetKeyState(LefVirtualKey_Menu) != None)
retval |= EModifierKey::Alt;
return retval;
}
class WindowUWP : public IWindow
{
friend struct GraphicsContextUWP;
ApplicationView^ m_appView = ApplicationView::GetForCurrentView();
CoreWindow^ m_coreWindow = CoreWindow::GetForCurrentThread();
std::unique_ptr<GraphicsContextUWP> m_gfxCtx;
IWindowCallback* m_callback = nullptr;
public:
WindowUWP(const SystemString& title, Boo3DAppContext& b3dCtx, uint32_t sampleCount)
{
IGraphicsContext::EGraphicsAPI api = IGraphicsContext::EGraphicsAPI::D3D11;
#if _WIN32_WINNT_WIN10
if (b3dCtx.m_ctx12.m_dev)
api = IGraphicsContext::EGraphicsAPI::D3D12;
#endif
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()
{
}
void setCallback(IWindowCallback* cb)
{
m_callback = cb;
}
void closeWindow()
{
m_coreWindow->Close();
}
void showWindow()
{
}
void hideWindow()
{
}
SystemString getTitle()
{
return SystemString(m_appView->Title.Data());
}
void setTitle(const SystemString& title)
{
m_appView->Title = title.c_str();
}
void setCursor(EMouseCursor cursor)
{
}
void setWaitCursor(bool wait)
{
}
void setWindowFrameDefault()
{
}
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;
}
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;
}
void setWindowFrame(float x, float y, float w, float h)
{
}
void setWindowFrame(int x, int y, int w, int h)
{
}
float getVirtualPixelFactor() const
{
DisplayInformation dispInfo = DisplayInformation::GetForCurrentView();
return dispInfo.LogicalDpi / 96.f;
}
bool isFullscreen() const
{
return m_gfxCtx->m_3dCtx.isFullscreen(this);
}
void setFullscreen(bool fs)
{
m_gfxCtx->m_3dCtx.setFullscreen(this, fs);
}
void claimKeyboardFocus(const int coord[2])
{
}
bool clipboardCopy(EClipboardType type, const uint8_t* data, size_t sz)
{
}
std::unique_ptr<uint8_t[]> clipboardPaste(EClipboardType type, size_t& sz)
{
return std::unique_ptr<uint8_t[]>();
}
void waitForRetrace(IAudioVoiceEngine* engine)
{
if (engine)
engine->pumpAndMixVoices();
m_gfxCtx->m_output->WaitForVBlank();
}
uintptr_t getPlatformHandle() const
{
return 0;
}
void _incomingEvent(void* ev)
{
}
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);
}
}
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);
}
}
void OnClosed(CoreWindow ^sender, CoreWindowEventArgs ^args)
{
}
ETouchType getTouchType() const
{
return ETouchType::None;
}
void setStyle(EWindowStyle style)
{
}
EWindowStyle getStyle() const
{
EWindowStyle retval = EWindowStyle::None;
return retval;
}
IGraphicsCommandQueue* getCommandQueue()
{
return m_gfxCtx->getCommandQueue();
}
IGraphicsDataFactory* getDataFactory()
{
return m_gfxCtx->getDataFactory();
}
/* Creates a new context on current thread!! Call from main client thread */
IGraphicsDataFactory* getMainContextDataFactory()
{
return m_gfxCtx->getMainContextDataFactory();
}
/* Creates a new context on current thread!! Call from client loading thread */
IGraphicsDataFactory* getLoadContextDataFactory()
{
return m_gfxCtx->getLoadContextDataFactory();
}
};
std::shared_ptr<IWindow> _WindowUAPNew(const SystemString& title, Boo3DAppContext& d3dCtx,
uint32_t sampleCount)
{
return std::make_shared<WindowUWP>(title, d3dCtx, sampleCount);
}
}

View File

@ -50,9 +50,9 @@ struct GraphicsContextWin32 : IGraphicsContext
EGraphicsAPI m_api;
EPixelFormat m_pf;
IWindow* m_parentWindow;
Boo3DAppContext& m_3dCtx;
Boo3DAppContextWin32& m_3dCtx;
ComPtr<IDXGIOutput> m_output;
GraphicsContextWin32(EGraphicsAPI api, IWindow* parentWindow, Boo3DAppContext& b3dCtx)
GraphicsContextWin32(EGraphicsAPI api, IWindow* parentWindow, Boo3DAppContextWin32& b3dCtx)
: m_api(api),
m_pf(EPixelFormat::RGBA8),
m_parentWindow(parentWindow),
@ -75,7 +75,7 @@ public:
IWindowCallback* m_callback;
GraphicsContextWin32D3D(EGraphicsAPI api, IWindow* parentWindow, HWND hwnd,
Boo3DAppContext& b3dCtx, uint32_t sampleCount)
Boo3DAppContextWin32& b3dCtx, uint32_t sampleCount)
: GraphicsContextWin32(api, parentWindow, b3dCtx)
{
/* Create Swap Chain */
@ -211,7 +211,7 @@ public:
IWindowCallback* m_callback;
GraphicsContextWin32GL(EGraphicsAPI api, IWindow* parentWindow, HWND hwnd,
Boo3DAppContext& b3dCtx, uint32_t sampleCount)
Boo3DAppContextWin32& b3dCtx, uint32_t sampleCount)
: GraphicsContextWin32(api, parentWindow, b3dCtx)
{
@ -416,7 +416,7 @@ public:
IWindowCallback* m_callback;
GraphicsContextWin32Vulkan(IWindow* parentWindow, HINSTANCE appInstance, HWND hwnd,
VulkanContext* ctx, Boo3DAppContext& b3dCtx, uint32_t drawSamples)
VulkanContext* ctx, Boo3DAppContextWin32& b3dCtx, uint32_t drawSamples)
: GraphicsContextWin32(EGraphicsAPI::Vulkan, parentWindow, b3dCtx),
m_appInstance(appInstance), m_hwnd(hwnd), m_ctx(ctx), m_sampleCount(drawSamples)
{
@ -973,7 +973,7 @@ class WindowWin32 : public IWindow
public:
WindowWin32(const SystemString& title, Boo3DAppContext& b3dCtx, void* vulkanHandle, uint32_t sampleCount)
WindowWin32(const SystemString& title, Boo3DAppContextWin32& b3dCtx, void* vulkanHandle, uint32_t sampleCount)
{
m_hwnd = CreateWindowW(L"BooWindow", title.c_str(), WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
@ -1585,7 +1585,7 @@ public:
};
std::shared_ptr<IWindow> _WindowWin32New(const SystemString& title, Boo3DAppContext& d3dCtx,
std::shared_ptr<IWindow> _WindowWin32New(const SystemString& title, Boo3DAppContextWin32& d3dCtx,
void* vulkanHandle, uint32_t sampleCount)
{
return std::make_shared<WindowWin32>(title, d3dCtx, vulkanHandle, sampleCount);

View File

@ -107,9 +107,9 @@ class GenericPadCallback : public IGenericPadCallback
class TestDeviceFinder : public DeviceFinder
{
std::shared_ptr<DolphinSmashAdapter> smashAdapter;
std::shared_ptr<DualshockPad> ds3;
std::shared_ptr<GenericPad> generic;
std::shared_ptr<DolphinSmashAdapter> m_smashAdapter;
std::shared_ptr<DualshockPad> m_ds3;
std::shared_ptr<GenericPad> m_generic;
DolphinSmashAdapterCallback m_cb;
DualshockPadCallback m_ds3CB;
GenericPadCallback m_genericCb;
@ -119,33 +119,33 @@ public:
{}
void deviceConnected(DeviceToken& tok)
{
smashAdapter = std::dynamic_pointer_cast<DolphinSmashAdapter>(tok.openAndGetDevice());
if (smashAdapter)
m_smashAdapter = std::dynamic_pointer_cast<DolphinSmashAdapter>(tok.openAndGetDevice());
if (m_smashAdapter)
{
smashAdapter->setCallback(&m_cb);
smashAdapter->startRumble(0);
m_smashAdapter->setCallback(&m_cb);
m_smashAdapter->startRumble(0);
return;
}
ds3 = std::dynamic_pointer_cast<DualshockPad>(tok.openAndGetDevice());
if (ds3)
m_ds3 = std::dynamic_pointer_cast<DualshockPad>(tok.openAndGetDevice());
if (m_ds3)
{
ds3->setCallback(&m_ds3CB);
ds3->setLED(EDualshockLED::LED_1);
m_ds3->setCallback(&m_ds3CB);
m_ds3->setLED(EDualshockLED::LED_1);
}
generic = std::dynamic_pointer_cast<GenericPad>(tok.openAndGetDevice());
if (generic)
m_generic = std::dynamic_pointer_cast<GenericPad>(tok.openAndGetDevice());
if (m_generic)
{
generic->setCallback(&m_genericCb);
m_generic->setCallback(&m_genericCb);
}
}
void deviceDisconnected(DeviceToken&, DeviceBase* device)
{
if (smashAdapter.get() == device)
smashAdapter.reset();
if (ds3.get() == device)
ds3.reset();
if (generic.get() == device)
generic.reset();
if (m_smashAdapter.get() == device)
m_smashAdapter.reset();
if (m_ds3.get() == device)
m_ds3.reset();
if (m_generic.get() == device)
m_generic.reset();
}
};
@ -571,7 +571,21 @@ int main(int argc, const boo::SystemChar** argv)
return ret;
}
#if _WIN32
#if WINAPI_FAMILY && !WINAPI_PARTITION_DESKTOP
using namespace Windows::ApplicationModel::Core;
[Platform::MTAThread]
int WINAPIV main(Platform::Array<Platform::String^>^ params)
{
logvisor::RegisterStandardExceptions();
logvisor::RegisterConsoleLogger();
boo::TestApplicationCallback appCb;
auto viewProvider = ref new ViewProvider(appCb, _S("boo"), _S("boo"), params, false);
CoreApplication::Run(viewProvider);
return 0;
}
#elif _WIN32
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR lpCmdLine, int)
{
int argc = 0;