2016-08-29 22:31:11 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2011-2016 Branimir Karadzic. All rights reserved.
|
|
|
|
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "entry_p.h"
|
|
|
|
|
|
|
|
#if BX_PLATFORM_WINRT || BX_PLATFORM_XBOXONE
|
|
|
|
|
2017-04-11 08:16:10 +02:00
|
|
|
#include <bgfx/platform.h>
|
2016-08-29 22:31:11 +02:00
|
|
|
#include <bx/thread.h>
|
2018-02-03 17:39:28 +01:00
|
|
|
#include <bx/math.h>
|
2016-08-29 22:31:11 +02:00
|
|
|
#include <Unknwn.h>
|
|
|
|
|
|
|
|
using namespace Windows::ApplicationModel;
|
|
|
|
using namespace Windows::ApplicationModel::Core;
|
|
|
|
using namespace Windows::ApplicationModel::Activation;
|
|
|
|
using namespace Windows::UI::Core;
|
|
|
|
using namespace Windows::UI::Input;
|
|
|
|
using namespace Windows::System;
|
|
|
|
using namespace Windows::Foundation;
|
|
|
|
#if BX_PLATFORM_WINRT
|
|
|
|
using namespace Windows::Graphics::Display;
|
|
|
|
#endif // BX_PLATFORM_WINRT
|
|
|
|
using namespace Platform;
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
static const char* const g_emptyArgs[] = { "app.exe", "", "" };
|
2016-08-29 22:31:11 +02:00
|
|
|
static entry::WindowHandle g_defaultWindow = { 0 };
|
|
|
|
static entry::EventQueue g_eventQueue;
|
|
|
|
|
|
|
|
///
|
|
|
|
inline void winrtSetWindow(::IUnknown* _window)
|
|
|
|
{
|
|
|
|
bgfx::PlatformData pd;
|
|
|
|
pd.ndt = NULL;
|
|
|
|
pd.nwh = _window;
|
|
|
|
pd.context = NULL;
|
|
|
|
pd.backBuffer = NULL;
|
|
|
|
pd.backBufferDS = NULL;
|
|
|
|
bgfx::setPlatformData(pd);
|
|
|
|
}
|
|
|
|
|
|
|
|
ref class App sealed : public IFrameworkView
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
App()
|
|
|
|
: m_windowVisible(true)
|
|
|
|
, m_windowClosed(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// IFrameworkView Methods.
|
|
|
|
virtual void Initialize(CoreApplicationView^ applicationView)
|
|
|
|
{
|
|
|
|
applicationView->Activated += ref new
|
|
|
|
TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &App::OnActivated);
|
|
|
|
|
|
|
|
CoreApplication::Suspending += ref new
|
|
|
|
EventHandler<SuspendingEventArgs^>(this, &App::OnSuspending);
|
|
|
|
|
|
|
|
CoreApplication::Resuming += ref new
|
|
|
|
EventHandler<Platform::Object^>(this, &App::OnResuming);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SetWindow(CoreWindow^ window)
|
|
|
|
{
|
|
|
|
window->VisibilityChanged += ref new
|
|
|
|
TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &App::OnVisibilityChanged);
|
|
|
|
|
|
|
|
window->Closed += ref new
|
|
|
|
TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &App::OnWindowClosed);
|
|
|
|
|
|
|
|
winrtSetWindow(reinterpret_cast<IUnknown*>(window) );
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Load(String^ entryPoint)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Run()
|
|
|
|
{
|
2018-02-03 17:39:28 +01:00
|
|
|
bgfx::renderFrame();
|
|
|
|
|
2016-08-29 22:31:11 +02:00
|
|
|
bx::Thread thread;
|
|
|
|
thread.init(MainThreadFunc, nullptr);
|
|
|
|
|
|
|
|
CoreWindow^ window = CoreWindow::GetForCurrentThread();
|
|
|
|
auto bounds = window->Bounds;
|
|
|
|
|
|
|
|
#if BX_PLATFORM_WINRT
|
|
|
|
auto dpi = DisplayInformation::GetForCurrentView()->LogicalDpi;
|
|
|
|
static const float dipsPerInch = 96.0f;
|
|
|
|
g_eventQueue.postSizeEvent(g_defaultWindow
|
2018-02-03 17:39:28 +01:00
|
|
|
, lround(bx::floor(bounds.Width * dpi / dipsPerInch + 0.5f) )
|
|
|
|
, lround(bx::floor(bounds.Height * dpi / dipsPerInch + 0.5f) )
|
2016-08-29 22:31:11 +02:00
|
|
|
);
|
|
|
|
#endif // BX_PLATFORM_WINRT
|
|
|
|
|
|
|
|
while (!m_windowClosed)
|
|
|
|
{
|
|
|
|
if (m_windowVisible)
|
|
|
|
{
|
|
|
|
window->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
window->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending);
|
|
|
|
}
|
2018-02-03 17:39:28 +01:00
|
|
|
|
|
|
|
bgfx::renderFrame();
|
2016-08-29 22:31:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
g_eventQueue.postExitEvent();
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
while (bgfx::RenderFrame::NoContext != bgfx::renderFrame() ) {};
|
|
|
|
|
2016-08-29 22:31:11 +02:00
|
|
|
thread.shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Uninitialize()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_windowVisible;
|
|
|
|
bool m_windowClosed;
|
|
|
|
|
|
|
|
void OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
|
|
|
|
{
|
|
|
|
CoreWindow::GetForCurrentThread()->Activate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args)
|
|
|
|
{
|
|
|
|
m_windowVisible = args->Visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args)
|
|
|
|
{
|
|
|
|
SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral();
|
|
|
|
BX_UNUSED(deferral);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnResuming(Platform::Object^ sender, Platform::Object^ args)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
|
|
|
|
{
|
|
|
|
m_windowClosed = true;
|
|
|
|
}
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
static int32_t MainThreadFunc(bx::Thread*, void*)
|
2016-08-29 22:31:11 +02:00
|
|
|
{
|
2018-02-03 17:39:28 +01:00
|
|
|
return entry::main(BX_COUNTOF(g_emptyArgs), g_emptyArgs);
|
2016-08-29 22:31:11 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ref class AppSource sealed : IFrameworkViewSource
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual IFrameworkView^ CreateView()
|
|
|
|
{
|
|
|
|
return ref new App();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace entry
|
|
|
|
{
|
|
|
|
const Event* poll()
|
|
|
|
{
|
|
|
|
return g_eventQueue.poll();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Event* poll(WindowHandle _handle)
|
|
|
|
{
|
|
|
|
return g_eventQueue.poll(_handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void release(const Event* _event)
|
|
|
|
{
|
|
|
|
g_eventQueue.release(_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowHandle createWindow(int32_t _x, int32_t _y, uint32_t _width, uint32_t _height, uint32_t _flags, const char* _title)
|
|
|
|
{
|
|
|
|
BX_UNUSED(_x, _y, _width, _height, _flags, _title);
|
|
|
|
WindowHandle handle = { UINT16_MAX };
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void destroyWindow(WindowHandle _handle)
|
|
|
|
{
|
|
|
|
BX_UNUSED(_handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setWindowPos(WindowHandle _handle, int32_t _x, int32_t _y)
|
|
|
|
{
|
|
|
|
BX_UNUSED(_handle, _x, _y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height)
|
|
|
|
{
|
|
|
|
BX_UNUSED(_handle, _width, _height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setWindowTitle(WindowHandle _handle, const char* _title)
|
|
|
|
{
|
|
|
|
BX_UNUSED(_handle, _title);
|
|
|
|
}
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
void setWindowFlags(WindowHandle _handle, uint32_t _flags, bool _enabled)
|
2016-08-29 22:31:11 +02:00
|
|
|
{
|
2018-02-03 17:39:28 +01:00
|
|
|
BX_UNUSED(_handle, _flags, _enabled);
|
2016-08-29 22:31:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void toggleFullscreen(WindowHandle _handle)
|
|
|
|
{
|
|
|
|
BX_UNUSED(_handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setMouseLock(WindowHandle _handle, bool _lock)
|
|
|
|
{
|
|
|
|
BX_UNUSED(_handle, _lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[MTAThread]
|
|
|
|
int main(Array<String^>^)
|
|
|
|
{
|
|
|
|
auto appSource = ref new AppSource();
|
|
|
|
CoreApplication::Run(appSource);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // BX_PLATFORM_WINRT || BX_PLATFORM_XBOXONE
|