mirror of https://github.com/axmolengine/axmol.git
implemented lostDevice support when app loses the directx device
This commit is contained in:
parent
32fe5d07ae
commit
a607d41454
|
@ -83,6 +83,8 @@ void Cocos2dRenderer::Pause()
|
|||
|
||||
void Cocos2dRenderer::DeviceLost()
|
||||
{
|
||||
Pause();
|
||||
|
||||
auto director = cocos2d::Director::getInstance();
|
||||
if (director->getOpenGLView()) {
|
||||
cocos2d::GL::invalidateStateCache();
|
||||
|
|
|
@ -48,7 +48,8 @@ OpenGLESPage::OpenGLESPage(OpenGLES* openGLES) :
|
|||
mCustomRenderSurfaceSize(0,0),
|
||||
mUseCustomRenderSurfaceSize(false),
|
||||
m_coreInput(nullptr),
|
||||
m_dpi(0.0f)
|
||||
m_dpi(0.0f),
|
||||
m_deviceLost(false)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
|
@ -209,7 +210,6 @@ void OpenGLESPage::RecoverFromLostDevice()
|
|||
|
||||
{
|
||||
critical_section::scoped_lock lock(mRenderSurfaceCriticalSection);
|
||||
|
||||
DestroyRenderSurface();
|
||||
mOpenGLES->Reset();
|
||||
CreateRenderSurface();
|
||||
|
@ -249,12 +249,19 @@ void OpenGLESPage::StartRenderLoop()
|
|||
m_renderer = std::make_shared<Cocos2dRenderer>(panelWidth, panelHeight, m_dpi, dispatcher, swapChainPanel);
|
||||
}
|
||||
|
||||
m_renderer->Resume();
|
||||
|
||||
|
||||
while (action->Status == Windows::Foundation::AsyncStatus::Started)
|
||||
if (m_deviceLost)
|
||||
{
|
||||
m_deviceLost = false;
|
||||
m_renderer->DeviceLost();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_renderer->Resume();
|
||||
}
|
||||
|
||||
|
||||
while (action->Status == Windows::Foundation::AsyncStatus::Started && !m_deviceLost)
|
||||
{
|
||||
|
||||
GetSwapChainPanelSize(&panelWidth, &panelHeight);
|
||||
m_renderer.get()->Draw(panelWidth, panelHeight, m_dpi);
|
||||
|
||||
|
@ -262,9 +269,10 @@ void OpenGLESPage::StartRenderLoop()
|
|||
// If the call fails, then we must reinitialize EGL and the GL resources.
|
||||
if (mOpenGLES->SwapBuffers(mRenderSurface) != GL_TRUE)
|
||||
{
|
||||
m_deviceLost = true;
|
||||
|
||||
// XAML objects like the SwapChainPanel must only be manipulated on the UI thread.
|
||||
swapChainPanel->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::High, ref new Windows::UI::Core::DispatchedHandler([=]()
|
||||
//swapChainPanel->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::High, ref new Windows::UI::Core::DispatchedHandler([=]()
|
||||
{
|
||||
RecoverFromLostDevice();
|
||||
}, CallbackContext::Any));
|
||||
|
|
|
@ -69,5 +69,7 @@ namespace cocos2d
|
|||
void OnPointerReleased(Platform::Object^ sender, Windows::UI::Core::PointerEventArgs^ e);
|
||||
|
||||
float m_dpi;
|
||||
bool m_deviceLost;
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
@ -83,6 +83,8 @@ void Cocos2dRenderer::Pause()
|
|||
|
||||
void Cocos2dRenderer::DeviceLost()
|
||||
{
|
||||
Pause();
|
||||
|
||||
auto director = cocos2d::Director::getInstance();
|
||||
if (director->getOpenGLView()) {
|
||||
cocos2d::GL::invalidateStateCache();
|
||||
|
|
|
@ -48,7 +48,8 @@ OpenGLESPage::OpenGLESPage(OpenGLES* openGLES) :
|
|||
mCustomRenderSurfaceSize(0,0),
|
||||
mUseCustomRenderSurfaceSize(false),
|
||||
m_coreInput(nullptr),
|
||||
m_dpi(0.0f)
|
||||
m_dpi(0.0f),
|
||||
m_deviceLost(false)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
|
@ -209,7 +210,7 @@ void OpenGLESPage::RecoverFromLostDevice()
|
|||
|
||||
{
|
||||
critical_section::scoped_lock lock(mRenderSurfaceCriticalSection);
|
||||
|
||||
m_deviceLost = true;
|
||||
DestroyRenderSurface();
|
||||
mOpenGLES->Reset();
|
||||
CreateRenderSurface();
|
||||
|
@ -249,7 +250,15 @@ void OpenGLESPage::StartRenderLoop()
|
|||
m_renderer = std::make_shared<Cocos2dRenderer>(panelWidth, panelHeight, m_dpi, dispatcher, swapChainPanel);
|
||||
}
|
||||
|
||||
m_renderer->Resume();
|
||||
if (m_deviceLost)
|
||||
{
|
||||
m_deviceLost = false;
|
||||
m_renderer->DeviceLost();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_renderer->Resume();
|
||||
}
|
||||
|
||||
|
||||
while (action->Status == Windows::Foundation::AsyncStatus::Started)
|
||||
|
|
|
@ -69,5 +69,7 @@ namespace cocos2d
|
|||
void OnPointerReleased(Platform::Object^ sender, Windows::UI::Core::PointerEventArgs^ e);
|
||||
|
||||
float m_dpi;
|
||||
bool m_deviceLost;
|
||||
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue