mirror of https://github.com/axmolengine/axmol.git
removed old files
This commit is contained in:
parent
3795d6ac28
commit
4f01036bc9
|
@ -1,13 +0,0 @@
|
||||||
<Page
|
|
||||||
x:Class="cpp_tests.OpenGLESPage"
|
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
||||||
xmlns:local="using:cpp_tests"
|
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
|
||||||
mc:Ignorable="d">
|
|
||||||
|
|
||||||
<SwapChainPanel x:Name="swapChainPanel">
|
|
||||||
<TextBlock Text="OpenGL ES and XAML" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="30" />
|
|
||||||
</SwapChainPanel>
|
|
||||||
</Page>
|
|
|
@ -1,188 +0,0 @@
|
||||||
#include "pch.h"
|
|
||||||
#include "OpenGLESPage.xaml.h"
|
|
||||||
|
|
||||||
using namespace cpp_tests;
|
|
||||||
using namespace Platform;
|
|
||||||
using namespace Concurrency;
|
|
||||||
using namespace Windows::Foundation;
|
|
||||||
|
|
||||||
OpenGLESPage::OpenGLESPage() :
|
|
||||||
OpenGLESPage(nullptr)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
OpenGLESPage::OpenGLESPage(OpenGLES* openGLES) :
|
|
||||||
mOpenGLES(openGLES),
|
|
||||||
mRenderSurface(EGL_NO_SURFACE),
|
|
||||||
mCustomRenderSurfaceSize(0,0),
|
|
||||||
mUseCustomRenderSurfaceSize(false)
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
|
|
||||||
Windows::UI::Core::CoreWindow^ window = Windows::UI::Xaml::Window::Current->CoreWindow;
|
|
||||||
|
|
||||||
window->VisibilityChanged +=
|
|
||||||
ref new Windows::Foundation::TypedEventHandler<Windows::UI::Core::CoreWindow^, Windows::UI::Core::VisibilityChangedEventArgs^>(this, &OpenGLESPage::OnVisibilityChanged);
|
|
||||||
|
|
||||||
swapChainPanel->SizeChanged +=
|
|
||||||
ref new Windows::UI::Xaml::SizeChangedEventHandler(this, &OpenGLESPage::OnSwapChainPanelSizeChanged);
|
|
||||||
|
|
||||||
this->Loaded +=
|
|
||||||
ref new Windows::UI::Xaml::RoutedEventHandler(this, &OpenGLESPage::OnPageLoaded);
|
|
||||||
|
|
||||||
#if !(WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
|
|
||||||
// Disable all pointer visual feedback for better performance when touching.
|
|
||||||
// This is not supported on Windows Phone applications.
|
|
||||||
auto pointerVisualizationSettings = Windows::UI::Input::PointerVisualizationSettings::GetForCurrentView();
|
|
||||||
pointerVisualizationSettings->IsContactFeedbackEnabled = false;
|
|
||||||
pointerVisualizationSettings->IsBarrelButtonFeedbackEnabled = false;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
mSwapChainPanelSize = { swapChainPanel->RenderSize.Width, swapChainPanel->RenderSize.Height };
|
|
||||||
}
|
|
||||||
|
|
||||||
OpenGLESPage::~OpenGLESPage()
|
|
||||||
{
|
|
||||||
StopRenderLoop();
|
|
||||||
DestroyRenderSurface();
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenGLESPage::OnPageLoaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
|
|
||||||
{
|
|
||||||
// The SwapChainPanel has been created and arranged in the page layout, so EGL can be initialized.
|
|
||||||
CreateRenderSurface();
|
|
||||||
StartRenderLoop();
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenGLESPage::OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args)
|
|
||||||
{
|
|
||||||
if (args->Visible && mRenderSurface != EGL_NO_SURFACE)
|
|
||||||
{
|
|
||||||
StartRenderLoop();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
StopRenderLoop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenGLESPage::OnSwapChainPanelSizeChanged(Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e)
|
|
||||||
{
|
|
||||||
// Size change events occur outside of the render thread. A lock is required when updating
|
|
||||||
// the swapchainpanel size
|
|
||||||
critical_section::scoped_lock lock(mSwapChainPanelSizeCriticalSection);
|
|
||||||
mSwapChainPanelSize = { e->NewSize.Width, e->NewSize.Height };
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenGLESPage::GetSwapChainPanelSize(GLsizei* width, GLsizei* height)
|
|
||||||
{
|
|
||||||
critical_section::scoped_lock lock(mSwapChainPanelSizeCriticalSection);
|
|
||||||
// If a custom render surface size is specified, return its size instead of
|
|
||||||
// the swapchain panel size.
|
|
||||||
if (mUseCustomRenderSurfaceSize)
|
|
||||||
{
|
|
||||||
*width = static_cast<GLsizei>(mCustomRenderSurfaceSize.Width);
|
|
||||||
*height = static_cast<GLsizei>(mCustomRenderSurfaceSize.Height);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*width = static_cast<GLsizei>(mSwapChainPanelSize.Width);
|
|
||||||
*height = static_cast<GLsizei>(mSwapChainPanelSize.Height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenGLESPage::CreateRenderSurface()
|
|
||||||
{
|
|
||||||
if (mOpenGLES)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// A Custom render surface size can be specified by uncommenting the following lines.
|
|
||||||
// The render surface will be automatically scaled to fit the entire window. Using a
|
|
||||||
// smaller sized render surface can result in a performance gain.
|
|
||||||
//
|
|
||||||
//mCustomRenderSurfaceSize = Size(800, 600);
|
|
||||||
//mUseCustomRenderSurfaceSize = true;
|
|
||||||
|
|
||||||
mRenderSurface = mOpenGLES->CreateSurface(swapChainPanel, mUseCustomRenderSurfaceSize ? &mCustomRenderSurfaceSize : nullptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenGLESPage::DestroyRenderSurface()
|
|
||||||
{
|
|
||||||
if (mOpenGLES)
|
|
||||||
{
|
|
||||||
mOpenGLES->DestroySurface(mRenderSurface);
|
|
||||||
}
|
|
||||||
mRenderSurface = EGL_NO_SURFACE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenGLESPage::RecoverFromLostDevice()
|
|
||||||
{
|
|
||||||
// Stop the render loop, reset OpenGLES, recreate the render surface
|
|
||||||
// and start the render loop again to recover from a lost device.
|
|
||||||
|
|
||||||
StopRenderLoop();
|
|
||||||
|
|
||||||
{
|
|
||||||
critical_section::scoped_lock lock(mRenderSurfaceCriticalSection);
|
|
||||||
|
|
||||||
DestroyRenderSurface();
|
|
||||||
mOpenGLES->Reset();
|
|
||||||
CreateRenderSurface();
|
|
||||||
}
|
|
||||||
|
|
||||||
StartRenderLoop();
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenGLESPage::StartRenderLoop()
|
|
||||||
{
|
|
||||||
// If the render loop is already running then do not start another thread.
|
|
||||||
if (mRenderLoopWorker != nullptr && mRenderLoopWorker->Status == Windows::Foundation::AsyncStatus::Started)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a task for rendering that will be run on a background thread.
|
|
||||||
auto workItemHandler = ref new Windows::System::Threading::WorkItemHandler([this](Windows::Foundation::IAsyncAction ^ action)
|
|
||||||
{
|
|
||||||
critical_section::scoped_lock lock(mRenderSurfaceCriticalSection);
|
|
||||||
|
|
||||||
mOpenGLES->MakeCurrent(mRenderSurface);
|
|
||||||
HelloTriangleRenderer renderer;
|
|
||||||
|
|
||||||
while (action->Status == Windows::Foundation::AsyncStatus::Started)
|
|
||||||
{
|
|
||||||
GLsizei panelWidth = 0;
|
|
||||||
GLsizei panelHeight = 0;
|
|
||||||
|
|
||||||
GetSwapChainPanelSize(&panelWidth, &panelHeight);
|
|
||||||
renderer.Draw(panelWidth, panelHeight);
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
{
|
|
||||||
// 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([=]()
|
|
||||||
{
|
|
||||||
RecoverFromLostDevice();
|
|
||||||
}, CallbackContext::Any));
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Run task on a dedicated high priority background thread.
|
|
||||||
mRenderLoopWorker = Windows::System::Threading::ThreadPool::RunAsync(workItemHandler, Windows::System::Threading::WorkItemPriority::High, Windows::System::Threading::WorkItemOptions::TimeSliced);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenGLESPage::StopRenderLoop()
|
|
||||||
{
|
|
||||||
if (mRenderLoopWorker)
|
|
||||||
{
|
|
||||||
mRenderLoopWorker->Cancel();
|
|
||||||
mRenderLoopWorker = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "OpenGLESPage.g.h"
|
|
||||||
|
|
||||||
namespace cpp_tests
|
|
||||||
{
|
|
||||||
public ref class OpenGLESPage sealed
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
OpenGLESPage();
|
|
||||||
virtual ~OpenGLESPage();
|
|
||||||
|
|
||||||
internal:
|
|
||||||
OpenGLESPage(OpenGLES* openGLES);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void OnPageLoaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
|
|
||||||
void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args);
|
|
||||||
void OnSwapChainPanelSizeChanged(Platform::Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e);
|
|
||||||
void GetSwapChainPanelSize(GLsizei* width, GLsizei* height);
|
|
||||||
void CreateRenderSurface();
|
|
||||||
void DestroyRenderSurface();
|
|
||||||
void RecoverFromLostDevice();
|
|
||||||
void StartRenderLoop();
|
|
||||||
void StopRenderLoop();
|
|
||||||
|
|
||||||
OpenGLES* mOpenGLES;
|
|
||||||
|
|
||||||
Windows::Foundation::Size mSwapChainPanelSize;
|
|
||||||
Concurrency::critical_section mSwapChainPanelSizeCriticalSection;
|
|
||||||
|
|
||||||
Windows::Foundation::Size mCustomRenderSurfaceSize;
|
|
||||||
bool mUseCustomRenderSurfaceSize;
|
|
||||||
|
|
||||||
EGLSurface mRenderSurface; // This surface is associated with a swapChainPanel on the page
|
|
||||||
Concurrency::critical_section mRenderSurfaceCriticalSection;
|
|
||||||
Windows::Foundation::IAsyncAction^ mRenderLoopWorker;
|
|
||||||
};
|
|
||||||
}
|
|
Loading…
Reference in New Issue