-
Notifications
You must be signed in to change notification settings - Fork 154
Re-enable UWP as a build target #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
785d730
UWP-compliant bgfx.cmake submodule.
syntheticmagus 11c6f93
CMake changes to be able to build for UWP.
syntheticmagus 7abc364
Update to bgfx.cmake for bimg changes.
syntheticmagus d1c10f9
Changes to get Library to build for UWP.
syntheticmagus bd0d1c0
Fixing errors for TestApp, need to rework Arcana's inclusion pattern …
syntheticmagus ea71214
Able to build Library for UWP.
syntheticmagus 97f25b2
Visual output in UWP! It's wrong, but I can SEE IT!
syntheticmagus 1a68633
Fixed wrong render target size on startup.
syntheticmagus 981887e
Added manifest, key, and assets to UWP build.
syntheticmagus 0f21149
Take BGFX WinRT fix.
syntheticmagus dd575b7
Merge from master.
syntheticmagus ab9fd87
Cleanup before PR.
syntheticmagus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule bgfx.cmake
updated
5 files
| +1 −1 | bgfx | |
| +1 −1 | bimg | |
| +1 −1 | bx | |
| +5 −0 | cmake/3rdparty/nvtt.cmake | |
| +10 −0 | cmake/bx.cmake |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,24 @@ | ||
| #pragma once | ||
|
|
||
| #include "Runtime.h" | ||
|
|
||
| #include <windows.ui.core.h> | ||
| #include <windows.ui.xaml.controls.h> | ||
|
|
||
| #include <memory> | ||
|
|
||
| namespace babylon | ||
| { | ||
| class Runtime; | ||
|
|
||
| class RuntimeUWP final : public Runtime | ||
| { | ||
| public: | ||
| explicit RuntimeUWP(ABI::Windows::UI::Core::ICoreWindow* window, const std::string& rootUrl = {}); | ||
| explicit RuntimeUWP(ABI::Windows::UI::Xaml::Controls::ISwapChainPanel* panel, const std::string& rootUrl = {}); | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opening an issue to track the following TODO.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a line in the Feature Backlog (#6) |
||
| // TODO: Allow creation from swap chain, which is required by XAML apps. | ||
| // explicit RuntimeUWP(ABI::Windows::UI::Xaml::Controls::ISwapChainPanel* panel, const std::string& rootUrl = {}); | ||
|
|
||
| RuntimeUWP(const Runtime&) = delete; | ||
| ~RuntimeUWP() = default; | ||
| ~RuntimeUWP(); | ||
|
|
||
| private: | ||
| class Impl; | ||
| ABI::Windows::UI::Core::ICoreWindow* m_window{}; | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,191 +1,28 @@ | ||
| #include "RuntimeUWP.h" | ||
| #include "CommonUWP.h" | ||
| #include "Babylon/Runtime.h" | ||
| #include "Babylon/RuntimeUWP.h" | ||
| #include "RuntimeImpl.h" | ||
| #include <ScriptHost/ScriptHost.h> | ||
| #include <ScriptHost/Console.h> | ||
| #include <ScriptHost/Window.h> | ||
| #include <ScriptHost/XMLHttpRequest.h> | ||
| #include <arcana/experimental/array.h> | ||
| #include <arcana/threading/cancellation.h> | ||
| #include <arcana/threading/coroutine.h> | ||
| #include <arcana/threading/dispatcher.h> | ||
| #include <arcana/threading/task.h> | ||
| #include <arcana/threading/task_conversions.h> | ||
| #include <winrt/Windows.ApplicationModel.h> | ||
| #include <winrt/Windows.ApplicationModel.Core.h> | ||
| #include <winrt/Windows.UI.Core.h> | ||
| #include <winrt/Windows.Storage.h> | ||
| #include <winrt/Windows.Graphics.Display.h> | ||
| #include <winrt/Windows.UI.Xaml.Controls.h> | ||
| #include <exception> | ||
| #include <dxgi1_2.h> | ||
| #include <windows.ui.xaml.media.dxinterop.h> | ||
| #include <variant> | ||
|
|
||
| namespace | ||
| { | ||
| arcana::task<std::string, std::exception_ptr> read_text_async(std::string filename) | ||
| { | ||
| auto folder = winrt::Windows::ApplicationModel::Package::Current().InstalledLocation(); | ||
| return arcana::create_task<std::exception_ptr>(folder.GetFileAsync(winrt::to_hstring(filename))) | ||
| .then(arcana::inline_scheduler, arcana::cancellation::none(), [filename](const winrt::Windows::Storage::StorageFile& file) | ||
| { | ||
| return arcana::create_task<std::exception_ptr>(winrt::Windows::Storage::FileIO::ReadTextAsync(file)); | ||
| }).then(arcana::inline_scheduler, arcana::cancellation::none(), [filename](const winrt::hstring& hstring) | ||
| { | ||
| return winrt::to_string(hstring); | ||
| }); | ||
| } | ||
|
|
||
| // Converts a length in device-independent pixels (DIPs) to a length in physical pixels. | ||
| float dips_to_pixels(float dips, float dpi) | ||
| { | ||
| static const float dipsPerInch = 96.0f; | ||
| return floorf(dips * dpi / dipsPerInch + 0.5f); // Round to nearest integer. | ||
| } | ||
|
|
||
| template<typename T> | ||
| T from_abi(void* from) | ||
| { | ||
| T to{ nullptr }; | ||
| winrt::copy_from_abi(to, from); | ||
| return std::move(to); | ||
| } | ||
|
|
||
| // TODO: fix for bgfx | ||
| //Spectre::Engine::EngineDescription GetEngineDescription(winrt::agile_ref<winrt::Windows::UI::Core::CoreWindow>& window) | ||
| //{ | ||
| // Spectre::Engine::EngineDescription engineDesc{}; | ||
|
|
||
| // Spectre::Engine::GeneralDescription& general = engineDesc.General; | ||
| // general.ThreadingMode = Spectre::Engine::Lockable::ThreadingMode::Single; | ||
|
|
||
| // Spectre::Engine::DeviceDescription& device = engineDesc.Device; | ||
| // device.Platform = Spectre::Engine::DevicePlatform::DirectX11; | ||
|
|
||
| // Spectre::Engine::OutputDescription& output = engineDesc.Output; | ||
| // output.Mode = Spectre::Engine::RenderOutputMode::CoreWindow; | ||
| // output.NativeWindow = winrt::get_abi(reinterpret_cast<winrt::com_ptr<IAgileReference>&>(window)); | ||
| // output.PerformanceLogging = Spectre::Engine::RenderOutputPerformanceLogging::Enable; | ||
|
|
||
| // return std::move(engineDesc); | ||
| //} | ||
|
|
||
| //void SPECTRESDK_CALL OnSwapChainCreatedCallback(void* dxgiSwapChain, void* pUserData) | ||
| //{ | ||
| // auto panel = from_abi<winrt::Windows::UI::Xaml::Controls::SwapChainPanel>(pUserData); | ||
| // panel.Dispatcher().RunAsync(winrt::Windows::UI::Core::CoreDispatcherPriority::Normal, [=] | ||
| // { | ||
| // winrt::check_hresult(panel.as<ISwapChainPanelNative>()->SetSwapChain(static_cast<IDXGISwapChain1*>(dxgiSwapChain))); | ||
| // }); | ||
| //} | ||
|
|
||
| //Spectre::Engine::EngineDescription GetEngineDescription(winrt::Windows::UI::Xaml::Controls::SwapChainPanel& panel) | ||
| //{ | ||
| // Spectre::Engine::EngineDescription engineDesc{}; | ||
|
|
||
| // Spectre::Engine::GeneralDescription& general = engineDesc.General; | ||
| // general.ThreadingMode = Spectre::Engine::Lockable::ThreadingMode::Single; | ||
|
|
||
| // Spectre::Engine::DeviceDescription& device = engineDesc.Device; | ||
| // device.Platform = Spectre::Engine::DevicePlatform::DirectX11; | ||
|
|
||
| // Spectre::Engine::OutputDescription& output = engineDesc.Output; | ||
| // output.Mode = Spectre::Engine::RenderOutputMode::XAML; | ||
| // output.NativeWindow = winrt::get_abi(panel); | ||
| // output.OnSwapChainCreatedCallback = OnSwapChainCreatedCallback; | ||
| // output.PerformanceLogging = Spectre::Engine::RenderOutputPerformanceLogging::Enable; | ||
|
|
||
| // return std::move(engineDesc); | ||
| //} | ||
| } | ||
|
|
||
| namespace babylon | ||
| { | ||
| class RuntimeUWP::Impl final : public RuntimeImpl | ||
| { | ||
| public: | ||
| // TODO: fix RenderPAL to take a CoreWindow directly instead of an agile ref to a CoreWindow once we switch to RenderPAL. | ||
| explicit Impl(winrt::agile_ref<winrt::Windows::UI::Core::CoreWindow> window, const std::string& rootUrl); | ||
| explicit Impl(winrt::Windows::UI::Xaml::Controls::SwapChainPanel panel, const std::string& rootUrl); | ||
| ~Impl() override = default; | ||
|
|
||
| virtual void RunScript(const std::string& url) override; | ||
| virtual void RunScript(const std::string& script, const std::string& url) override; | ||
|
|
||
| private: | ||
| std::variant<winrt::agile_ref<winrt::Windows::UI::Core::CoreWindow>, winrt::Windows::UI::Xaml::Controls::SwapChainPanel> m_windowsUiContext; | ||
| }; | ||
|
|
||
| RuntimeUWP::DefaultInitializationScriptsArray RuntimeUWP::DEFAULT_INITIALIZATION_SCRIPTS = arcana::make_array<std::string> | ||
| ( | ||
| #ifdef _DEBUG | ||
| "Scripts\\babylon.max.js", | ||
| "Scripts\\babylon.glTF2FileLoader.js" | ||
| #else | ||
| "Scripts\\babylon.js", | ||
| "Scripts\\babylon.glTF2FileLoader.min.js" | ||
| #endif | ||
| ); | ||
|
|
||
| RuntimeUWP::RuntimeUWP(ABI::Windows::UI::Core::ICoreWindow* window, const std::string& rootUrl) | ||
| : Runtime{ std::make_unique<RuntimeUWP::Impl>(from_abi<winrt::Windows::UI::Core::CoreWindow>(window), rootUrl) } | ||
| : Runtime { std::make_unique<RuntimeImpl>(window, rootUrl) } | ||
| , m_window{ window } | ||
| { | ||
| m_window->AddRef(); | ||
| } | ||
|
|
||
| RuntimeUWP::RuntimeUWP(ABI::Windows::UI::Xaml::Controls::ISwapChainPanel* panel, const std::string& rootUrl) | ||
| : Runtime{ std::make_unique<RuntimeUWP::Impl>(from_abi<winrt::Windows::UI::Xaml::Controls::SwapChainPanel>(panel), rootUrl) } | ||
| RuntimeUWP::~RuntimeUWP() | ||
| { | ||
| m_window->Release(); | ||
| } | ||
|
|
||
| RuntimeUWP::Impl::Impl(winrt::agile_ref<winrt::Windows::UI::Core::CoreWindow> window, const std::string& rootUrl) | ||
| : RuntimeImpl{ /*std::make_unique<SpectreEngine>(GetEngineDescription(window), *this)*/nullptr, rootUrl } | ||
| , m_windowsUiContext{ window } | ||
| /*RuntimeUWP::RuntimeUWP(ABI::Windows::UI::Xaml::Controls::ISwapChainPanel* panel, const std::string& rootUrl) | ||
| : Runtime{ std::make_unique<RuntimeImpl>(from_abi<winrt::Windows::UI::Xaml::Controls::SwapChainPanel>(panel), rootUrl) } | ||
| { | ||
| // Set initial render output size. | ||
| const auto windowBounds = window.get().Bounds(); | ||
| const auto currentDisplayInformation = winrt::Windows::Graphics::Display::DisplayInformation::GetForCurrentView(); | ||
| const float dpi = currentDisplayInformation.LogicalDpi(); | ||
| UpdateSize(dips_to_pixels(windowBounds.Width, dpi), dips_to_pixels(windowBounds.Height, dpi)); | ||
|
|
||
| for (const auto& url : RuntimeUWP::DEFAULT_INITIALIZATION_SCRIPTS) | ||
| { | ||
| RunScript(url); | ||
| } | ||
| } | ||
|
|
||
| RuntimeUWP::Impl::Impl(winrt::Windows::UI::Xaml::Controls::SwapChainPanel panel, const std::string& rootUrl) | ||
| : RuntimeImpl{ /*std::make_unique<SpectreEngine>(GetEngineDescription(panel), *this)*/nullptr, rootUrl } | ||
| , m_windowsUiContext{ panel } | ||
| { | ||
| // Set initial render output size. | ||
| const auto currentDisplayInformation = winrt::Windows::Graphics::Display::DisplayInformation::GetForCurrentView(); | ||
| const float dpi = currentDisplayInformation.LogicalDpi(); | ||
| UpdateSize(dips_to_pixels(static_cast<float>(panel.ActualWidth()), dpi), dips_to_pixels(static_cast<float>(panel.ActualHeight()), dpi)); | ||
|
|
||
| for (const auto& url : RuntimeUWP::DEFAULT_INITIALIZATION_SCRIPTS) | ||
| { | ||
| RunScript(url); | ||
| } | ||
| } | ||
|
|
||
| void RuntimeUWP::Impl::RunScript(const std::string& url) | ||
| { | ||
| auto lock = AcquireTaskLock(); | ||
| Task = Task.then(arcana::inline_scheduler, Cancellation(), [url] | ||
| { | ||
| return read_text_async(url); | ||
| }).then(Dispatcher(), Cancellation(), [this, url](const std::string& script) | ||
| { | ||
| RunScriptWithNapi(script, url); | ||
| }); | ||
| } | ||
| }*/ | ||
|
|
||
| void RuntimeUWP::Impl::RunScript(const std::string& script, const std::string& url) | ||
| void RuntimeImpl::ThreadProcedure() | ||
| { | ||
| Execute([this, script, url](auto&) | ||
| { | ||
| RunScriptWithNapi(script, url); | ||
| }); | ||
| RuntimeImpl::BaseThreadProcedure(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opening an issue to track the following TODO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#28