2023-03-11 22:10:18 +08:00
|
|
|
/*
|
2023-12-14 01:46:41 +08:00
|
|
|
* cocos2d-x https://axmolengine.github.io/
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010-2014 - cocos2d-x community
|
|
|
|
* Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
*
|
|
|
|
* Portions Copyright (c) Microsoft Open Technologies, Inc.
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
|
|
|
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations under the License.
|
|
|
|
*/
|
2023-09-26 00:11:33 +08:00
|
|
|
#include "OpenGLESPage.h"
|
|
|
|
#include "OpenGLESPage.g.cpp"
|
2023-03-11 22:10:18 +08:00
|
|
|
|
2023-06-11 13:08:08 +08:00
|
|
|
#include "platform/winrt/GLViewImpl-winrt.h"
|
2023-12-14 01:46:41 +08:00
|
|
|
#include "platform/Application.h"
|
|
|
|
|
|
|
|
#include "yasio/wtimer_hres.hpp"
|
2023-03-11 22:10:18 +08:00
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
#include <winrt/Windows.Graphics.h>
|
|
|
|
#include <winrt/Windows.Graphics.Display.h>
|
|
|
|
#include <winrt/Windows.System.Threading.h>
|
|
|
|
#include <winrt/Windows.Foundation.Metadata.h>
|
|
|
|
#include <winrt/Windows.UI.Input.Core.h>
|
|
|
|
|
|
|
|
using namespace winrt;
|
|
|
|
|
2023-03-11 22:10:18 +08:00
|
|
|
using namespace ax;
|
|
|
|
using namespace Concurrency;
|
|
|
|
using namespace Windows::Foundation;
|
|
|
|
using namespace Windows::Graphics::Display;
|
|
|
|
using namespace Windows::System::Threading;
|
|
|
|
using namespace Windows::UI::Core;
|
|
|
|
using namespace Windows::UI::Input;
|
|
|
|
using namespace Windows::UI::Input::Core;
|
|
|
|
using namespace Windows::UI::Xaml;
|
|
|
|
using namespace Windows::UI::Xaml::Controls;
|
|
|
|
using namespace Windows::UI::Xaml::Controls::Primitives;
|
|
|
|
using namespace Windows::UI::Xaml::Data;
|
|
|
|
using namespace Windows::UI::Xaml::Input;
|
|
|
|
using namespace Windows::UI::Xaml::Media;
|
|
|
|
using namespace Windows::UI::Xaml::Navigation;
|
|
|
|
|
|
|
|
#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) || _MSC_VER >= 1900
|
|
|
|
using namespace Windows::UI::Input;
|
|
|
|
#endif
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
namespace winrt::AxmolAppWinRT::implementation
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
OpenGLESPage::OpenGLESPage() : OpenGLESPage(nullptr) {}
|
|
|
|
OpenGLESPage::OpenGLESPage(OpenGLES* openGLES)
|
|
|
|
: mOpenGLES(openGLES)
|
|
|
|
, mRenderSurface(EGL_NO_SURFACE)
|
|
|
|
, mCoreInput(nullptr)
|
|
|
|
, mDpi(0.0f)
|
|
|
|
, mDeviceLost(false)
|
|
|
|
, mCursorVisible(true)
|
|
|
|
, mVisible(false)
|
|
|
|
, mOrientation(DisplayOrientations::Landscape)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
Windows::UI::Core::CoreWindow window = Windows::UI::Xaml::Window::Current().CoreWindow();
|
2023-03-11 22:10:18 +08:00
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
window.VisibilityChanged({this, &OpenGLESPage::OnVisibilityChanged});
|
2023-03-11 22:10:18 +08:00
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
window.KeyDown({this, &OpenGLESPage::OnKeyPressed});
|
2023-03-11 22:10:18 +08:00
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
window.KeyUp({this, &OpenGLESPage::OnKeyReleased});
|
2023-03-11 22:10:18 +08:00
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
window.CharacterReceived({this, &OpenGLESPage::_OnCharacterReceived});
|
2023-03-11 22:10:18 +08:00
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
DisplayInformation currentDisplayInformation = DisplayInformation::GetForCurrentView();
|
2023-03-11 22:10:18 +08:00
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
currentDisplayInformation.OrientationChanged({this, &OpenGLESPage::OnOrientationChanged});
|
2023-03-11 22:10:18 +08:00
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
mOrientation = currentDisplayInformation.CurrentOrientation();
|
2023-03-11 22:10:18 +08:00
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
this->Loaded({this, &OpenGLESPage::OnPageLoaded});
|
2023-03-11 22:10:18 +08:00
|
|
|
|
|
|
|
// If we have a phone contract, hide the status bar
|
2023-09-26 00:11:33 +08:00
|
|
|
Window::Current().SetTitleBar(nullptr);
|
2023-03-11 22:10:18 +08:00
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
if (Windows::Foundation::Metadata::ApiInformation::IsTypePresent(L"Windows.Phone.UI.Input.HardwareButtons"))
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
SystemNavigationManager::GetForCurrentView().BackRequested({this, &OpenGLESPage::OnBackButtonPressed});
|
|
|
|
}
|
2023-03-11 22:10:18 +08:00
|
|
|
|
|
|
|
CreateInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLESPage::CreateInput()
|
|
|
|
{
|
|
|
|
// Register our SwapChainPanel to get independent input pointer events
|
2023-09-26 00:11:33 +08:00
|
|
|
auto workItemHandler = ([this](IAsyncAction const&) {
|
|
|
|
// The CoreIndependentInputSource will raise pointer events for the specified device types on whichever thread
|
|
|
|
// it's created on.
|
|
|
|
mCoreInput = swapChainPanel().CreateCoreIndependentInputSource(Windows::UI::Core::CoreInputDeviceTypes::Mouse |
|
2023-12-14 01:46:41 +08:00
|
|
|
Windows::UI::Core::CoreInputDeviceTypes::Touch |
|
|
|
|
Windows::UI::Core::CoreInputDeviceTypes::Pen);
|
2023-03-11 22:10:18 +08:00
|
|
|
|
|
|
|
// Register for pointer events, which will be raised on the background thread.
|
2023-09-26 00:11:33 +08:00
|
|
|
mCoreInput.PointerPressed({this, &OpenGLESPage::_OnPointerPressed});
|
|
|
|
mCoreInput.PointerMoved({this, &OpenGLESPage::_OnPointerMoved});
|
|
|
|
mCoreInput.PointerReleased({this, &OpenGLESPage::_OnPointerReleased});
|
|
|
|
mCoreInput.PointerWheelChanged({this, &OpenGLESPage::_OnPointerWheelChanged});
|
2023-03-11 22:10:18 +08:00
|
|
|
|
2023-12-01 09:04:51 +08:00
|
|
|
if (GLViewImpl::sharedGLView() && !GLViewImpl::sharedGLView()->isCursorVisible())
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
mCoreInput.PointerCursor(nullptr);
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
// Begin processing input messages as they're delivered.
|
|
|
|
mCoreInput.Dispatcher().ProcessEvents(CoreProcessEventsOption::ProcessUntilQuit);
|
2023-03-11 22:10:18 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
// Run task on a dedicated high priority background thread.
|
|
|
|
mInputLoopWorker = ThreadPool::RunAsync(workItemHandler, WorkItemPriority::High, WorkItemOptions::TimeSliced);
|
|
|
|
}
|
|
|
|
|
|
|
|
OpenGLESPage::~OpenGLESPage()
|
|
|
|
{
|
|
|
|
StopRenderLoop();
|
|
|
|
DestroyRenderSurface();
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void OpenGLESPage::OnPageLoaded(Windows::Foundation::IInspectable const& sender,
|
|
|
|
Windows::UI::Xaml::RoutedEventArgs const& e)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
// The SwapChainPanel has been created and arranged in the page layout, so EGL can be initialized.
|
|
|
|
CreateRenderSurface();
|
|
|
|
StartRenderLoop();
|
|
|
|
mVisible = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLESPage::CreateRenderSurface()
|
|
|
|
{
|
|
|
|
if (mOpenGLES && mRenderSurface == EGL_NO_SURFACE)
|
|
|
|
{
|
|
|
|
// The app can configure the SwapChainPanel which may boost performance.
|
|
|
|
// By default, this template uses the default configuration.
|
2023-09-26 00:11:33 +08:00
|
|
|
mRenderSurface = mOpenGLES->CreateSurface(swapChainPanel(), nullptr, nullptr);
|
2023-03-11 22:10:18 +08:00
|
|
|
|
|
|
|
// You can configure the SwapChainPanel to render at a lower resolution and be scaled up to
|
|
|
|
// the swapchain panel size. This scaling is often free on mobile hardware.
|
|
|
|
//
|
|
|
|
// One way to configure the SwapChainPanel is to specify precisely which resolution it should render at.
|
|
|
|
// Size customRenderSurfaceSize = Size(800, 600);
|
|
|
|
// mRenderSurface = mOpenGLES->CreateSurface(swapChainPanel, &customRenderSurfaceSize, nullptr);
|
|
|
|
//
|
|
|
|
// Another way is to tell the SwapChainPanel to render at a certain scale factor compared to its size.
|
|
|
|
// e.g. if the SwapChainPanel is 1920x1280 then setting a factor of 0.5f will make the app render at 960x640
|
|
|
|
// float customResolutionScale = 0.5f;
|
|
|
|
// mRenderSurface = mOpenGLES->CreateSurface(swapChainPanel, nullptr, &customResolutionScale);
|
2023-09-26 00:11:33 +08:00
|
|
|
//
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLESPage::DestroyRenderSurface()
|
|
|
|
{
|
|
|
|
if (mOpenGLES)
|
|
|
|
{
|
|
|
|
mOpenGLES->DestroySurface(mRenderSurface);
|
|
|
|
}
|
|
|
|
mRenderSurface = EGL_NO_SURFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLESPage::RecoverFromLostDevice()
|
|
|
|
{
|
|
|
|
critical_section::scoped_lock lock(mRenderSurfaceCriticalSection);
|
|
|
|
DestroyRenderSurface();
|
|
|
|
mOpenGLES->Reset();
|
|
|
|
CreateRenderSurface();
|
|
|
|
std::unique_lock<std::mutex> locker(mSleepMutex);
|
|
|
|
mDeviceLost = false;
|
|
|
|
mSleepCondition.notify_one();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLESPage::TerminateApp()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
critical_section::scoped_lock lock(mRenderSurfaceCriticalSection);
|
|
|
|
|
|
|
|
if (mOpenGLES)
|
|
|
|
{
|
|
|
|
mOpenGLES->DestroySurface(mRenderSurface);
|
|
|
|
mOpenGLES->Cleanup();
|
|
|
|
}
|
|
|
|
}
|
2023-09-26 00:11:33 +08:00
|
|
|
Windows::UI::Xaml::Application::Current().Exit();
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
|
2023-05-31 20:42:39 +08:00
|
|
|
void OpenGLESPage::ProcessOperations()
|
|
|
|
{
|
|
|
|
std::function<void()> op;
|
|
|
|
while (mOperations.try_pop(op))
|
|
|
|
op();
|
|
|
|
}
|
|
|
|
|
2023-03-11 22:10:18 +08:00
|
|
|
void OpenGLESPage::StartRenderLoop()
|
|
|
|
{
|
|
|
|
// If the render loop is already running then do not start another thread.
|
2023-09-26 00:11:33 +08:00
|
|
|
if (mRenderLoopWorker != nullptr && mRenderLoopWorker.Status() == Windows::Foundation::AsyncStatus::Started)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
DisplayInformation currentDisplayInformation = DisplayInformation::GetForCurrentView();
|
|
|
|
mDpi = currentDisplayInformation.LogicalDpi();
|
2023-03-11 22:10:18 +08:00
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
auto dispatcher = Windows::UI::Xaml::Window::Current().CoreWindow().Dispatcher();
|
2023-03-11 22:10:18 +08:00
|
|
|
|
|
|
|
// Create a task for rendering that will be run on a background thread.
|
2023-09-26 00:11:33 +08:00
|
|
|
auto workItemHandler = ([this, dispatcher](Windows::Foundation::IAsyncAction const& action) {
|
2023-03-11 22:10:18 +08:00
|
|
|
mOpenGLES->MakeCurrent(mRenderSurface);
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
GLsizei panelWidth = 0;
|
2023-03-11 22:10:18 +08:00
|
|
|
GLsizei panelHeight = 0;
|
|
|
|
mOpenGLES->GetSurfaceDimensions(mRenderSurface, &panelWidth, &panelHeight);
|
|
|
|
|
2023-05-31 20:42:39 +08:00
|
|
|
if (!mRenderer)
|
2023-09-26 00:11:33 +08:00
|
|
|
mRenderer = std::make_shared<AxmolRenderer>(panelWidth, panelHeight, mDpi, mOrientation, dispatcher,
|
|
|
|
swapChainPanel());
|
2023-03-11 22:10:18 +08:00
|
|
|
|
|
|
|
mRenderer->Resume();
|
|
|
|
|
2023-05-31 20:42:39 +08:00
|
|
|
void* thiz = (void*)this;
|
|
|
|
mRenderer->SetQueueOperationCb([thiz](ax::AsyncOperation op, void* param) {
|
2023-09-26 00:11:33 +08:00
|
|
|
auto thisUnsafe = reinterpret_cast<OpenGLESPage*>(thiz);
|
2023-05-31 20:42:39 +08:00
|
|
|
thisUnsafe->mOperations.push([=]() { op(param); });
|
|
|
|
thisUnsafe->mSleepCondition.notify_one();
|
|
|
|
});
|
|
|
|
|
2023-12-14 01:46:41 +08:00
|
|
|
// the actual render frame function
|
|
|
|
std::function<bool(void)> frameFunc = [&]() {
|
|
|
|
|
2023-03-11 22:10:18 +08:00
|
|
|
if (!mVisible)
|
|
|
|
{
|
|
|
|
mRenderer->Pause();
|
|
|
|
}
|
|
|
|
|
|
|
|
// wait until app is visible again or thread is cancelled
|
|
|
|
while (!mVisible)
|
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> lock(mSleepMutex);
|
|
|
|
mSleepCondition.wait(lock);
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
if (action.Status() != Windows::Foundation::AsyncStatus::Started)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-12-14 01:46:41 +08:00
|
|
|
return false; // thread was cancelled. Exit thread
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mVisible)
|
|
|
|
{
|
|
|
|
mRenderer->Resume();
|
|
|
|
}
|
2023-09-26 00:11:33 +08:00
|
|
|
else // spurious wake up
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-05-31 20:42:39 +08:00
|
|
|
ProcessOperations();
|
2023-03-11 22:10:18 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-31 20:42:39 +08:00
|
|
|
ProcessOperations();
|
|
|
|
|
2023-03-11 22:10:18 +08:00
|
|
|
mOpenGLES->GetSurfaceDimensions(mRenderSurface, &panelWidth, &panelHeight);
|
2023-05-31 20:42:39 +08:00
|
|
|
mRenderer->Draw(panelWidth, panelHeight, mDpi, mOrientation);
|
2023-03-11 22:10:18 +08:00
|
|
|
|
|
|
|
// Recreate input dispatch
|
2023-12-01 09:04:51 +08:00
|
|
|
if (GLViewImpl::sharedGLView() && mCursorVisible != GLViewImpl::sharedGLView()->isCursorVisible())
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
CreateInput();
|
2023-12-01 09:04:51 +08:00
|
|
|
mCursorVisible = GLViewImpl::sharedGLView()->isCursorVisible();
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mRenderer->AppShouldExit())
|
|
|
|
{
|
|
|
|
// run on main UI thread
|
|
|
|
auto thiz = this;
|
2023-09-26 00:11:33 +08:00
|
|
|
swapChainPanel().Dispatcher().RunAsync(Windows::UI::Core::CoreDispatcherPriority::High,
|
2023-12-14 01:46:41 +08:00
|
|
|
([thiz]() { thiz->TerminateApp(); }));
|
2023-03-11 22:10:18 +08:00
|
|
|
|
2023-12-14 01:46:41 +08:00
|
|
|
return false;
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
EGLBoolean result = GL_FALSE;
|
|
|
|
{
|
|
|
|
critical_section::scoped_lock lock(mRenderSurfaceCriticalSection);
|
|
|
|
result = mOpenGLES->SwapBuffers(mRenderSurface);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result != GL_TRUE)
|
|
|
|
{
|
|
|
|
// The call to eglSwapBuffers was not be successful (i.e. due to Device Lost)
|
|
|
|
// If the call fails, then we must reinitialize EGL and the GL resources.
|
|
|
|
mRenderer->Pause();
|
|
|
|
mDeviceLost = true;
|
|
|
|
|
|
|
|
// XAML objects like the SwapChainPanel must only be manipulated on the UI thread.
|
|
|
|
auto thiz = this;
|
2023-12-14 01:46:41 +08:00
|
|
|
swapChainPanel().Dispatcher().RunAsync(Windows::UI::Core::CoreDispatcherPriority::High,
|
|
|
|
([thiz]() { thiz->RecoverFromLostDevice(); }));
|
2023-03-11 22:10:18 +08:00
|
|
|
|
|
|
|
// wait until OpenGL is reset or thread is cancelled
|
|
|
|
while (mDeviceLost)
|
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> lock(mSleepMutex);
|
|
|
|
mSleepCondition.wait(lock);
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
if (action.Status() != Windows::Foundation::AsyncStatus::Started)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-12-14 01:46:41 +08:00
|
|
|
return false; // thread was cancelled. Exit thread
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!mDeviceLost)
|
|
|
|
{
|
|
|
|
mOpenGLES->MakeCurrent(mRenderSurface);
|
|
|
|
mRenderer->DeviceLost();
|
|
|
|
}
|
2023-09-26 00:11:33 +08:00
|
|
|
else // spurious wake up
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-12-14 01:46:41 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Sets Sleep(aka NtDelayExecution) resolution to 1ms
|
|
|
|
yasio::wtimer_hres __timer_hres_man;
|
|
|
|
auto application = ax::Application::getInstance();
|
|
|
|
while (action.Status() == Windows::Foundation::AsyncStatus::Started)
|
|
|
|
{
|
|
|
|
if (!application->frameStep(frameFunc))
|
|
|
|
return;
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Run task on a dedicated high priority background thread.
|
2023-09-26 00:11:33 +08:00
|
|
|
mRenderLoopWorker = Windows::System::Threading::ThreadPool::RunAsync(
|
|
|
|
workItemHandler, Windows::System::Threading::WorkItemPriority::High,
|
|
|
|
Windows::System::Threading::WorkItemOptions::TimeSliced);
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLESPage::StopRenderLoop()
|
|
|
|
{
|
|
|
|
if (mRenderLoopWorker)
|
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
mRenderLoopWorker.Cancel();
|
2023-03-11 22:10:18 +08:00
|
|
|
std::unique_lock<std::mutex> locker(mSleepMutex);
|
|
|
|
mSleepCondition.notify_one();
|
|
|
|
mRenderLoopWorker = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void OpenGLESPage::_OnPointerPressed(Windows::Foundation::IInspectable const& sender, PointerEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
bool isMouseEvent =
|
|
|
|
args.CurrentPoint().PointerDevice().PointerDeviceType() == Windows::Devices::Input::PointerDeviceType::Mouse;
|
2023-03-11 22:10:18 +08:00
|
|
|
if (mRenderer)
|
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
mRenderer->QueuePointerEvent(isMouseEvent ? PointerEventType::MousePressed : PointerEventType::PointerPressed,
|
|
|
|
args);
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void OpenGLESPage::_OnPointerMoved(Windows::Foundation::IInspectable const& sender, PointerEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
bool isMouseEvent =
|
|
|
|
args.CurrentPoint().PointerDevice().PointerDeviceType() == Windows::Devices::Input::PointerDeviceType::Mouse;
|
2023-03-11 22:10:18 +08:00
|
|
|
if (mRenderer)
|
|
|
|
{
|
2023-12-14 01:46:41 +08:00
|
|
|
mRenderer->QueuePointerEvent(isMouseEvent ? PointerEventType::MouseMoved : PointerEventType::PointerMoved,
|
|
|
|
args);
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void OpenGLESPage::_OnPointerReleased(Windows::Foundation::IInspectable const& sender, PointerEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
bool isMouseEvent =
|
|
|
|
args.CurrentPoint().PointerDevice().PointerDeviceType() == Windows::Devices::Input::PointerDeviceType::Mouse;
|
2023-03-11 22:10:18 +08:00
|
|
|
|
|
|
|
if (mRenderer)
|
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
mRenderer->QueuePointerEvent(isMouseEvent ? PointerEventType::MouseReleased : PointerEventType::PointerReleased,
|
|
|
|
args);
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-14 01:46:41 +08:00
|
|
|
void OpenGLESPage::_OnPointerWheelChanged(Windows::Foundation::IInspectable const& /*sender*/,
|
|
|
|
PointerEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
bool isMouseEvent =
|
|
|
|
args.CurrentPoint().PointerDevice().PointerDeviceType() == Windows::Devices::Input::PointerDeviceType::Mouse;
|
2023-03-11 22:10:18 +08:00
|
|
|
if (mRenderer && isMouseEvent)
|
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
mRenderer->QueuePointerEvent(PointerEventType::MouseWheelChanged, args);
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void OpenGLESPage::OnKeyPressed(CoreWindow const& sender, KeyEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
// log("OpenGLESPage::OnKeyPressed %d", e->VirtualKey);
|
2023-03-11 22:10:18 +08:00
|
|
|
if (mRenderer)
|
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
mRenderer->QueueKeyboardEvent(WinRTKeyboardEventType::KeyPressed, args);
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void OpenGLESPage::_OnCharacterReceived(CoreWindow const& sender, CharacterReceivedEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-12-14 01:46:41 +08:00
|
|
|
// if (!e->KeyStatus.WasKeyDown)
|
2023-09-26 00:11:33 +08:00
|
|
|
//{
|
2023-12-14 01:46:41 +08:00
|
|
|
// log("OpenGLESPage::OnCharacterReceived %d", e->KeyCode);
|
|
|
|
// }
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void OpenGLESPage::OnKeyReleased(CoreWindow const& sender, KeyEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
// log("OpenGLESPage::OnKeyReleased %d", e->VirtualKey);
|
2023-03-11 22:10:18 +08:00
|
|
|
if (mRenderer)
|
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
mRenderer->QueueKeyboardEvent(WinRTKeyboardEventType::KeyReleased, args);
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void OpenGLESPage::OnOrientationChanged(DisplayInformation const& sender,
|
|
|
|
Windows::Foundation::IInspectable const& /*args*/)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
mOrientation = sender.CurrentOrientation();
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLESPage::SetVisibility(bool isVisible)
|
|
|
|
{
|
|
|
|
if (isVisible && mRenderSurface != EGL_NO_SURFACE)
|
|
|
|
{
|
|
|
|
if (!mVisible)
|
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> locker(mSleepMutex);
|
|
|
|
mVisible = true;
|
|
|
|
mSleepCondition.notify_one();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mVisible = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void OpenGLESPage::OnVisibilityChanged(Windows::UI::Core::CoreWindow const& sender,
|
|
|
|
Windows::UI::Core::VisibilityChangedEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
if (args.Visible() && mRenderSurface != EGL_NO_SURFACE)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
SetVisibility(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetVisibility(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) || _MSC_VER >= 1900
|
|
|
|
/*
|
|
|
|
We set args->Handled = true to prevent the app from quitting when the back button is pressed.
|
2023-09-26 00:11:33 +08:00
|
|
|
This is because this back button event happens on the XAML UI thread and not the axmol UI thread.
|
2023-03-11 22:10:18 +08:00
|
|
|
We need to give the game developer a chance to decide to exit the app depending on where they
|
|
|
|
are in their game. They can receive the back button event by listening for the
|
|
|
|
EventKeyboard::KeyCode::KEY_ESCAPE event.
|
|
|
|
|
|
|
|
The default behavior is to exit the app if the EventKeyboard::KeyCode::KEY_ESCAPE event
|
|
|
|
is not handled by the game.
|
|
|
|
*/
|
2023-09-26 00:11:33 +08:00
|
|
|
void OpenGLESPage::OnBackButtonPressed(Windows::Foundation::IInspectable const& sender,
|
|
|
|
BackRequestedEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
if (mRenderer)
|
|
|
|
{
|
|
|
|
mRenderer->QueueBackButtonEvent();
|
2023-09-26 00:11:33 +08:00
|
|
|
args.Handled(true);
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2023-09-26 00:11:33 +08:00
|
|
|
|
|
|
|
} // namespace winrt::AxmolAppWinRT::implementation
|