diff --git a/templates/cpp-template-default/proj.win8.1-universal/App.Shared/Cocos2dRenderer.cpp b/templates/cpp-template-default/proj.win8.1-universal/App.Shared/Cocos2dRenderer.cpp index 81e78540c1..d8ffe6913b 100644 --- a/templates/cpp-template-default/proj.win8.1-universal/App.Shared/Cocos2dRenderer.cpp +++ b/templates/cpp-template-default/proj.win8.1-universal/App.Shared/Cocos2dRenderer.cpp @@ -114,27 +114,29 @@ void Cocos2dRenderer::DeviceLost() void Cocos2dRenderer::Draw(GLsizei width, GLsizei height, float dpi, DisplayOrientations orientation) { + auto glView = GLViewImpl::sharedOpenGLView(); + if (orientation != m_orientation) { m_orientation = orientation; - GLViewImpl::sharedOpenGLView()->UpdateOrientation(orientation); + glView->UpdateOrientation(orientation); } if (width != m_width || height != m_height) { m_width = width; m_height = height; - GLViewImpl::sharedOpenGLView()->UpdateForWindowSizeChange(static_cast(width), static_cast(height)); + glView->UpdateForWindowSizeChange(static_cast(width), static_cast(height)); } if (dpi != m_dpi) { m_dpi = dpi; - GLViewImpl::sharedOpenGLView()->SetDPI(m_dpi); + glView->SetDPI(m_dpi); } - GLViewImpl::sharedOpenGLView()->ProcessEvents(); - GLViewImpl::sharedOpenGLView()->Render(); + glView->ProcessEvents(); + glView->Render(); } void Cocos2dRenderer::QueuePointerEvent(cocos2d::PointerEventType type, Windows::UI::Core::PointerEventArgs^ args) diff --git a/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLES.cpp b/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLES.cpp index c375a709e7..3afdab08a9 100644 --- a/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLES.cpp +++ b/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLES.cpp @@ -62,7 +62,12 @@ void OpenGLES::Initialize() // EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER is an optimization that can have large performance benefits on mobile devices. // Its syntax is subject to change, though. Please update your Visual Studio templates if you experience compilation issues with it. - EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL_TRUE, + EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL_TRUE, + + // EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE is an option that enables ANGLE to automatically call + // the IDXGIDevice3::Trim method on behalf of the application when it gets suspended. + // Calling IDXGIDevice3::Trim when an application is suspended is a Windows Store application certification requirement. + EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE, EGL_TRUE, EGL_NONE, }; @@ -74,6 +79,7 @@ void OpenGLES::Initialize() EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, 9, EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, 3, EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL_TRUE, + EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE, EGL_TRUE, EGL_NONE, }; @@ -84,6 +90,7 @@ void OpenGLES::Initialize() EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE, EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL_TRUE, + EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE, EGL_TRUE, EGL_NONE, }; diff --git a/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLES.h b/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLES.h index 1a57b68739..e2e7d7e8aa 100644 --- a/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLES.h +++ b/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLES.h @@ -39,10 +39,10 @@ public: void MakeCurrent(const EGLSurface surface); EGLBoolean SwapBuffers(const EGLSurface surface); void Reset(); + void Cleanup(); private: void Initialize(); - void Cleanup(); private: EGLDisplay mEglDisplay; diff --git a/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLESPage.xaml.cpp b/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLESPage.xaml.cpp index 6a6a5fd00c..b53511535b 100644 --- a/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLESPage.xaml.cpp +++ b/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLESPage.xaml.cpp @@ -261,7 +261,13 @@ void OpenGLESPage::TerminateApp() { { critical_section::scoped_lock lock(mRenderSurfaceCriticalSection); - DestroyRenderSurface(); + + if (mOpenGLES) + { + mOpenGLES->DestroySurface(mRenderSurface); + mOpenGLES->Cleanup(); + } + } Windows::UI::Xaml::Application::Current->Exit(); } @@ -311,10 +317,21 @@ void OpenGLESPage::StartRenderLoop() GetSwapChainPanelSize(&panelWidth, &panelHeight); m_renderer.get()->Draw(panelWidth, panelHeight, m_dpi, m_orientation); - // The call to eglSwapBuffers might not be successful (i.e. due to Device Lost) - // If the call fails, then we must reinitialize EGL and the GL resources. - if (mOpenGLES->SwapBuffers(mRenderSurface) != GL_TRUE) + // run on main UI thread + if (m_renderer->AppShouldExit()) { + swapChainPanel->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new DispatchedHandler([this]() + { + TerminateApp(); + })); + + return; + } + else if (mOpenGLES->SwapBuffers(mRenderSurface) != GL_TRUE) + { + // The call to eglSwapBuffers might not be successful (i.e. due to Device Lost) + // If the call fails, then we must reinitialize EGL and the GL resources. + m_deviceLost = true; if (m_renderer) @@ -330,17 +347,6 @@ void OpenGLESPage::StartRenderLoop() return; } - - // run on main UI thread - if (m_renderer->AppShouldExit()) - { - swapChainPanel->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new DispatchedHandler([this]() - { - TerminateApp(); - })); - - return; - } } if (m_renderer)