From c305a4f180fb5629d7cf749b6032106dcd38a8b0 Mon Sep 17 00:00:00 2001
From: kgv <kgv@opencascade.com>
Date: Fri, 19 Jul 2019 19:19:23 +0300
Subject: [PATCH] 0029918: Samples - extend UWP sample with 3D Viewer

---
 samples/xaml/App.cpp                     | 471 +++++++++++++++++++++++
 samples/xaml/App.h                       |  86 +++++
 samples/xaml/App.xaml                    |   7 -
 samples/xaml/App.xaml.cpp                | 124 ------
 samples/xaml/App.xaml.h                  |  27 --
 samples/xaml/Assets/OpenSans-Regular.ttf | Bin 0 -> 217360 bytes
 samples/xaml/CMakeLists.txt              |  17 +-
 samples/xaml/MainPage.xaml               |  47 ---
 samples/xaml/MainPage.xaml.cpp           | 436 ---------------------
 samples/xaml/MainPage.xaml.h             |  51 ---
 samples/xaml/OcctAspectWindow.h          |  74 ++++
 samples/xaml/pch.cpp                     |   6 -
 samples/xaml/pch.h                       |  11 -
 13 files changed, 639 insertions(+), 718 deletions(-)
 create mode 100644 samples/xaml/App.cpp
 create mode 100644 samples/xaml/App.h
 delete mode 100644 samples/xaml/App.xaml
 delete mode 100644 samples/xaml/App.xaml.cpp
 delete mode 100644 samples/xaml/App.xaml.h
 create mode 100644 samples/xaml/Assets/OpenSans-Regular.ttf
 delete mode 100644 samples/xaml/MainPage.xaml
 delete mode 100644 samples/xaml/MainPage.xaml.cpp
 delete mode 100644 samples/xaml/MainPage.xaml.h
 create mode 100644 samples/xaml/OcctAspectWindow.h
 delete mode 100644 samples/xaml/pch.cpp
 delete mode 100644 samples/xaml/pch.h

diff --git a/samples/xaml/App.cpp b/samples/xaml/App.cpp
new file mode 100644
index 0000000000..ce835ed70a
--- /dev/null
+++ b/samples/xaml/App.cpp
@@ -0,0 +1,471 @@
+//
+// App.cpp
+// Implementation of the App class.
+//
+
+#include "App.h"
+
+#include "OcctAspectWindow.h"
+
+#include <OpenGl_GraphicDriver.hxx>
+#include <OSD_Environment.hxx>
+#include <NCollection_String.hxx>
+#include <Font_FontMgr.hxx>
+
+#include <AIS_Shape.hxx>
+#include <BRepPrimAPI_MakeBox.hxx>
+
+using namespace uwp;
+
+using namespace Platform;
+using namespace Windows::ApplicationModel;
+using namespace Windows::ApplicationModel::Activation;
+using namespace Windows::Foundation;
+using namespace Windows::Foundation::Collections;
+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::Interop;
+using namespace Windows::UI::Xaml::Media;
+using namespace Windows::UI::Xaml::Navigation;
+
+// Implementation of the IFrameworkViewSource interface, necessary to run our app.
+ref class SimpleApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource
+{
+public:
+  virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView()
+  {
+    return ref new App();
+  }
+};
+
+// The main function creates an IFrameworkViewSource for our app, and runs the app.
+[Platform::MTAThread]
+int main (Platform::Array<Platform::String^>^)
+{
+  auto simpleApplicationSource = ref new SimpleApplicationSource();
+  Windows::ApplicationModel::Core::CoreApplication::Run(simpleApplicationSource);
+  return 0;
+}
+
+// =======================================================================
+// function : App
+// purpose  :
+// =======================================================================
+App::App()
+: myEglDisplay (EGL_NO_DISPLAY),
+  myEglContext (EGL_NO_CONTEXT),
+  myEglSurface (EGL_NO_SURFACE),
+  myEglConfig  (nullptr),
+  myPanelWidth (0),
+  myPanelHeight(0),
+  myIsWindowClosed (false),
+  myIsWindowVisible(true)
+{
+  //
+}
+
+// =======================================================================
+// function : Initialize
+// purpose  :
+// =======================================================================
+void App::Initialize (Windows::ApplicationModel::Core::CoreApplicationView^ theAppView)
+{
+  Windows::Storage::StorageFolder^ anAppFolderRef = Windows::ApplicationModel::Package::Current->InstalledLocation;
+  const NCollection_String anAppFolder (anAppFolderRef->Path->Data());
+  const TCollection_AsciiString anAssetsFolder = (anAppFolder + "\\Assets").ToCString();
+
+  // assign paths to OCCT file resources
+  OSD_Environment aShadersDir ("CSF_ShadersDirectory");
+  aShadersDir.SetValue (anAssetsFolder);
+  aShadersDir.Build();
+
+  // register custom fonts - system fonts are unavailable for OCCT within UWP
+  TCollection_AsciiString aFontPath = anAssetsFolder + "\\OpenSans-Regular.ttf";
+  Handle(Font_FontMgr)    aMgr = Font_FontMgr::GetInstance();
+  Handle(Font_SystemFont) aFont = aMgr->CheckFont (aFontPath.ToCString());
+  if (aFont.IsNull())
+  {
+    throw Exception::CreateException(E_FAIL, L"Error: font can not be loaded!");
+  }
+  else
+  {
+    aFont = new Font_SystemFont(new TCollection_HAsciiString("Courier"), Font_FA_Regular, new TCollection_HAsciiString (aFontPath));
+    aMgr->RegisterFont(aFont, Standard_True);
+  }
+
+  // Register event handlers for app lifecycle. This example includes Activated,
+  // so that we can make the CoreWindow active and start rendering on the window.
+  theAppView->Activated += ref new Windows::Foundation::TypedEventHandler <Windows::ApplicationModel::Core::CoreApplicationView^, IActivatedEventArgs^> (this, &App::onActivated);
+
+  // Logic for other event handlers could go here.
+  // Information about the Suspending and Resuming event handlers can be found here:
+  // http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh994930.aspx
+}
+
+// =======================================================================
+// function : SetWindow
+// purpose  :
+// =======================================================================
+void App::SetWindow (Windows::UI::Core::CoreWindow^ theWindow)
+{
+  theWindow->VisibilityChanged += ref new TypedEventHandler<Windows::UI::Core::CoreWindow^, Windows::UI::Core::VisibilityChangedEventArgs^> (this, &App::onVisibilityChanged);
+  theWindow->Closed            += ref new TypedEventHandler<Windows::UI::Core::CoreWindow^, Windows::UI::Core::CoreWindowEventArgs^>        (this, &App::onWindowClosed);
+
+  // The CoreWindow has been created, so EGL can be initialized.
+  initializeEGL (theWindow);
+}
+
+// =======================================================================
+// function : Load
+// purpose  :
+// =======================================================================
+void App::Load (Platform::String^ theEntryPoint)
+{
+  recreateRenderer();
+}
+
+// =======================================================================
+// function : recreateRenderer
+// purpose  :
+// =======================================================================
+void App::recreateRenderer()
+{
+  if (myEglContext == EGL_NO_CONTEXT)
+  {
+    return;
+  }
+
+  eglQuerySurface (myEglDisplay, myEglSurface, EGL_WIDTH,  &myPanelWidth);
+  eglQuerySurface (myEglDisplay, myEglSurface, EGL_HEIGHT, &myPanelHeight);
+  if (!myViewer.IsNull())
+  {
+    Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(myViewer->Driver());
+    Handle(OcctAspectWindow)     aWindow = Handle(OcctAspectWindow)::DownCast(myView->Window());
+    if (!aDriver->InitEglContext (myEglDisplay, myEglContext, myEglConfig))
+    {
+      throw Exception::CreateException (E_FAIL, L"Error: OpenGl_GraphicDriver can not be initialized!");
+    }
+
+    aWindow->SetSize (myPanelWidth, myPanelHeight);
+    myView->SetWindow (aWindow, (Aspect_RenderingContext )myEglContext);
+    return;
+  }
+
+  Handle(OpenGl_GraphicDriver) aDriver = new OpenGl_GraphicDriver (Handle(Aspect_DisplayConnection)(), Standard_False);
+  aDriver->ChangeOptions().buffersNoSwap = true;
+  if (!aDriver->InitEglContext (myEglDisplay, myEglContext, myEglConfig))
+  {
+    throw Exception::CreateException(E_FAIL, L"Error: OpenGl_GraphicDriver can not be initialized!");
+  }
+
+  myViewer = new V3d_Viewer (aDriver, TCollection_ExtendedString("Viewer").ToExtString(), "", 1000.0,
+                             V3d_XposYnegZpos, Quantity_NOC_BLACK, V3d_ZBUFFER, V3d_GOURAUD, V3d_WAIT,
+                             Standard_False, Standard_False);
+  myViewer->SetDefaultLights();
+
+  Handle(OcctAspectWindow) aWindow = new OcctAspectWindow (myPanelWidth, myPanelHeight);
+  myView = myViewer->CreateView();
+  myView->SetImmediateUpdate (Standard_False);
+  myView->TriedronDisplay (Aspect_TOTP_RIGHT_LOWER, Quantity_NOC_WHITE, 0.08, V3d_ZBUFFER);
+  myView->SetWindow (aWindow, (Aspect_RenderingContext )myEglContext);
+
+  myContext = new AIS_InteractiveContext(myViewer);
+  myContext->SetDisplayMode (AIS_Shaded);
+
+
+  TopoDS_Shape theBox = BRepPrimAPI_MakeBox (200, 60, 60);
+  Handle(AIS_Shape) aShape = new AIS_Shape (theBox);
+  myContext->Display (aShape);
+  myView->FitAll();
+}
+
+// =======================================================================
+// function : Run
+// purpose  :
+// =======================================================================
+void App::Run()
+{
+  while (!myIsWindowClosed)
+  {
+    if (myIsWindowVisible)
+    {
+      Windows::UI::Core::CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents (Windows::UI::Core::CoreProcessEventsOption::ProcessAllIfPresent);
+
+      eglQuerySurface (myEglDisplay, myEglSurface, EGL_WIDTH,  &myPanelWidth);
+      eglQuerySurface (myEglDisplay, myEglSurface, EGL_HEIGHT, &myPanelHeight);
+
+      if (!myView.IsNull())
+      {
+        Handle(OcctAspectWindow) aWindow = Handle(OcctAspectWindow)::DownCast(myView->Window());
+        if (aWindow->SetSize (myPanelWidth, myPanelHeight))
+        {
+          myView->MustBeResized();
+          myView->Invalidate();
+        }
+
+        myView->Redraw();
+      }
+
+//      ::glViewport (0, 0, myPanelWidth, myPanelHeight);
+//      ::glClearColor (1.0f, 0.0f, 0.0f, 1.0f);
+//      ::glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+      // The call to eglSwapBuffers might not be successful (e.g. due to Device Lost)
+      // If the call fails, then we must reinitialize EGL and the GL resources.
+      if (eglSwapBuffers (myEglDisplay, myEglSurface) != EGL_TRUE)
+      {
+        cleanupEGL();
+        initializeEGL (Windows::UI::Core::CoreWindow::GetForCurrentThread());
+        recreateRenderer();
+      }
+    }
+    else
+    {
+      Windows::UI::Core::CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents (Windows::UI::Core::CoreProcessEventsOption::ProcessOneAndAllPending);
+    }
+  }
+
+  cleanupEGL();
+}
+
+// =======================================================================
+// function : Uninitialize
+// purpose  :
+// =======================================================================
+void App::Uninitialize()
+{
+}
+
+// =======================================================================
+// function : onActivated
+// purpose  :
+// =======================================================================
+void App::onActivated (Windows::ApplicationModel::Core::CoreApplicationView^ theAppView,
+                       IActivatedEventArgs^ theArgs)
+{
+  // Run() won't start until the CoreWindow is activated.
+  Windows::UI::Core::CoreWindow::GetForCurrentThread()->Activate();
+}
+
+// =======================================================================
+// function : onVisibilityChanged
+// purpose  :
+// =======================================================================
+void App::onVisibilityChanged (Windows::UI::Core::CoreWindow^ theSender,
+                               Windows::UI::Core::VisibilityChangedEventArgs^ theArgs)
+{
+  myIsWindowVisible = theArgs->Visible;
+}
+
+// =======================================================================
+// function : onWindowClosed
+// purpose  :
+// =======================================================================
+void App::onWindowClosed (Windows::UI::Core::CoreWindow^ theSender,
+                          Windows::UI::Core::CoreWindowEventArgs^ theArgs)
+{
+  myIsWindowClosed = true;
+}
+
+// =======================================================================
+// function : initializeEGL
+// purpose  :
+// =======================================================================
+void App::initializeEGL (Windows::UI::Core::CoreWindow^ theWindow)
+{
+  // this code reproduces OpenGlesSample project template
+  const EGLint aConfigAttributes[] =
+  {
+    EGL_RED_SIZE,     8,
+    EGL_GREEN_SIZE,   8,
+    EGL_BLUE_SIZE,    8,
+    EGL_ALPHA_SIZE,   0,
+    EGL_DEPTH_SIZE,   24,
+    EGL_STENCIL_SIZE, 8,
+    EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+    EGL_NONE
+  };
+
+  const EGLint aCtxAttributes[] =
+  {
+    EGL_CONTEXT_CLIENT_VERSION, 2,
+    EGL_NONE
+  };
+
+  const EGLint aSurfAttributes[] =
+  {
+  #ifdef EGL_ANGLE_SURFACE_RENDER_TO_BACK_BUFFER
+    // EGL_ANGLE_SURFACE_RENDER_TO_BACK_BUFFER is part of the same optimization as EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER (see above).
+    // If you have compilation issues with it then please update your Visual Studio templates.
+    EGL_ANGLE_SURFACE_RENDER_TO_BACK_BUFFER, EGL_TRUE,
+  #endif
+    EGL_NONE
+  };
+
+  const EGLint aDefaultDisplayAttributes[] =
+  {
+    // These are the default display attributes, used to request ANGLE's D3D11 renderer.
+    // eglInitialize will only succeed with these attributes if the hardware supports D3D11 Feature Level 10_0+.
+    EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
+
+  #ifdef EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER
+    // 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,
+  #endif
+
+    // 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,
+  };
+
+  const EGLint fl9_3DisplayAttributes[] =
+  {
+    // These can be used to request ANGLE's D3D11 renderer, with D3D11 Feature Level 9_3.
+    // These attributes are used if the call to eglInitialize fails with the default display attributes.
+    EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
+    EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, 9,
+    EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, 3,
+  #ifdef EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER
+    EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL_TRUE,
+  #endif
+    EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE, EGL_TRUE,
+    EGL_NONE,
+  };
+
+  const EGLint aWarpDisplayAttributes[] =
+  {
+    // These attributes can be used to request D3D11 WARP.
+    // They are used if eglInitialize fails with both the default display attributes and the 9_3 display attributes.
+    EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
+    EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE,
+  #ifdef EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER
+    EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL_TRUE,
+  #endif
+    EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE, EGL_TRUE,
+    EGL_NONE,
+  };
+
+  myEglConfig = NULL;
+
+  // eglGetPlatformDisplayEXT is an alternative to eglGetDisplay. It allows us to pass in display attributes, used to configure D3D11.
+  PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT = reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>(eglGetProcAddress ("eglGetPlatformDisplayEXT"));
+  if (eglGetPlatformDisplayEXT == nullptr)
+  {
+    throw Exception::CreateException (E_FAIL, L"Failed to get function eglGetPlatformDisplayEXT");
+  }
+
+  //
+  // To initialize the display, we make three sets of calls to eglGetPlatformDisplayEXT and eglInitialize, with varying 
+  // parameters passed to eglGetPlatformDisplayEXT:
+  // 1) The first calls uses "aDefaultDisplayAttributes" as a parameter. This corresponds to D3D11 Feature Level 10_0+.
+  // 2) If eglInitialize fails for step 1 (e.g. because 10_0+ isn't supported by the default GPU), then we try again 
+  //    using "fl9_3DisplayAttributes". This corresponds to D3D11 Feature Level 9_3.
+  // 3) If eglInitialize fails for step 2 (e.g. because 9_3+ isn't supported by the default GPU), then we try again 
+  //    using "aWarpDisplayAttributes".  This corresponds to D3D11 Feature Level 11_0 on WARP, a D3D11 software rasterizer.
+  //
+
+  // This tries to initialize EGL to D3D11 Feature Level 10_0+. See above comment for details.
+  myEglDisplay = eglGetPlatformDisplayEXT (EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, aDefaultDisplayAttributes);
+  if (myEglDisplay == EGL_NO_DISPLAY)
+  {
+    throw Exception::CreateException (E_FAIL, L"Failed to get EGL display");
+  }
+
+  if (eglInitialize (myEglDisplay, NULL, NULL) == EGL_FALSE)
+  {
+    // This tries to initialize EGL to D3D11 Feature Level 9_3, if 10_0+ is unavailable (e.g. on some mobile devices).
+    myEglDisplay = eglGetPlatformDisplayEXT (EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, fl9_3DisplayAttributes);
+    if (myEglDisplay == EGL_NO_DISPLAY)
+    {
+      throw Exception::CreateException (E_FAIL, L"Failed to get EGL display");
+    }
+
+    if (eglInitialize (myEglDisplay, NULL, NULL) == EGL_FALSE)
+    {
+      // This initializes EGL to D3D11 Feature Level 11_0 on WARP, if 9_3+ is unavailable on the default GPU.
+      myEglDisplay = eglGetPlatformDisplayEXT (EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, aWarpDisplayAttributes);
+      if (myEglDisplay == EGL_NO_DISPLAY)
+      {
+        throw Exception::CreateException (E_FAIL, L"Failed to get EGL display");
+      }
+
+      if (eglInitialize (myEglDisplay, NULL, NULL) == EGL_FALSE)
+      {
+        // If all of the calls to eglInitialize returned EGL_FALSE then an error has occurred.
+        throw Exception::CreateException (E_FAIL, L"Failed to initialize EGL");
+      }
+    }
+  }
+
+  EGLint aNbConfigs = 0;
+  if (eglChooseConfig (myEglDisplay, aConfigAttributes, &myEglConfig, 1, &aNbConfigs) == EGL_FALSE
+   || aNbConfigs == 0)
+  {
+    throw Exception::CreateException (E_FAIL, L"Failed to choose first EGLConfig");
+  }
+
+  // Create a PropertySet and initialize with the EGLNativeWindowType.
+  PropertySet^ aSurfProps = ref new PropertySet();
+  aSurfProps->Insert (ref new String(EGLNativeWindowTypeProperty), theWindow);
+
+  // You can configure the surface to render at a lower resolution and be scaled up to 
+  // the full window size. The 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);
+  // aSurfProps->Insert (ref new String(EGLRenderSurfaceSizeProperty), PropertyValue::CreateSize (customRenderSurfaceSize));
+  //
+  // 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;
+  // aSurfProps->Insert (ref new String(EGLRenderResolutionScaleProperty), PropertyValue::CreateSingle (customResolutionScale));
+  myEglSurface = eglCreateWindowSurface (myEglDisplay, myEglConfig, reinterpret_cast<IInspectable*>(aSurfProps), aSurfAttributes);
+  if (myEglSurface == EGL_NO_SURFACE)
+  {
+    throw Exception::CreateException(E_FAIL, L"Failed to create EGL fullscreen surface");
+  }
+
+  myEglContext = eglCreateContext (myEglDisplay, myEglConfig, EGL_NO_CONTEXT, aCtxAttributes);
+  if (myEglContext == EGL_NO_CONTEXT)
+  {
+    throw Exception::CreateException (E_FAIL, L"Failed to create EGL context");
+  }
+
+  if (eglMakeCurrent (myEglDisplay, myEglSurface, myEglSurface, myEglContext) == EGL_FALSE)
+  {
+    throw Exception::CreateException (E_FAIL, L"Failed to make fullscreen EGLSurface current");
+  }
+}
+
+// =======================================================================
+// function : cleanupEGL
+// purpose  :
+// =======================================================================
+void App::cleanupEGL()
+{
+  if (myEglDisplay != EGL_NO_DISPLAY
+   && myEglSurface != EGL_NO_SURFACE)
+  {
+    eglDestroySurface (myEglDisplay, myEglSurface);
+    myEglSurface = EGL_NO_SURFACE;
+  }
+
+  if (myEglDisplay != EGL_NO_DISPLAY
+   && myEglContext != EGL_NO_CONTEXT)
+  {
+    eglDestroyContext (myEglDisplay, myEglContext);
+    myEglContext = EGL_NO_CONTEXT;
+  }
+
+  if (myEglDisplay != EGL_NO_DISPLAY)
+  {
+    eglTerminate (myEglDisplay);
+    myEglDisplay = EGL_NO_DISPLAY;
+  }
+}
diff --git a/samples/xaml/App.h b/samples/xaml/App.h
new file mode 100644
index 0000000000..05fe2e3a77
--- /dev/null
+++ b/samples/xaml/App.h
@@ -0,0 +1,86 @@
+//
+// App.h
+// Declaration of the App class.
+//
+
+#pragma once
+
+// EGL includes
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+#include <EGL/eglplatform.h>
+
+// ANGLE include for Windows Store
+#include <angle_windowsstore.h>
+
+#include <AIS_InteractiveContext.hxx>
+#include <V3d_Viewer.hxx>
+#include <V3d_View.hxx>
+
+namespace uwp
+{
+  /// <summary>
+  /// Provides application-specific behavior to supplement the default Application class.
+  /// </summary>
+  ref class App sealed : public Windows::ApplicationModel::Core::IFrameworkView
+  {
+  public: // IFrameworkView Methods
+
+    //! The first method called when the IFrameworkView is being created.
+    virtual void Initialize (Windows::ApplicationModel::Core::CoreApplicationView^ theAppView);
+
+    //! Called when the CoreWindow object is created (or re-created).
+    virtual void SetWindow (Windows::UI::Core::CoreWindow^ theWindow);
+
+    //! Initializes scene resources
+    virtual void Load (Platform::String^ theEntryPoint);
+
+    //! This method is called after the window becomes active.
+    virtual void Run();
+
+    //! Terminate events do not cause Uninitialize to be called.
+    //! It will be called if your IFrameworkView class is torn down while the app is in the foreground.
+    virtual void Uninitialize();
+
+  internal:
+
+    //! Initializes the singleton application object.
+    //! This is the first line of authored code executed,
+    //! and as such is the logical equivalent of main() or WinMain().
+    App();
+
+  private:
+
+    void recreateRenderer();
+
+    //! Application lifecycle event handlers.
+    void onActivated (Windows::ApplicationModel::Core::CoreApplicationView^ theAppView,
+                      Windows::ApplicationModel::Activation::IActivatedEventArgs^ theArgs);
+
+    //! Window event handlers.
+    void onVisibilityChanged (Windows::UI::Core::CoreWindow^ theSender,
+                              Windows::UI::Core::VisibilityChangedEventArgs^ theArgs);
+    void onWindowClosed (Windows::UI::Core::CoreWindow^ theSender,
+                         Windows::UI::Core::CoreWindowEventArgs^ theArgs);
+
+    void initializeEGL (Windows::UI::Core::CoreWindow^ theWindow);
+    void cleanupEGL();
+
+  private:
+
+    Handle(AIS_InteractiveContext) myContext;
+    Handle(V3d_Viewer) myViewer;
+    Handle(V3d_View)   myView;
+
+    EGLDisplay myEglDisplay;
+    EGLContext myEglContext;
+    EGLSurface myEglSurface;
+    EGLConfig  myEglConfig;
+    EGLint     myPanelWidth;
+    EGLint     myPanelHeight;
+
+    bool myIsWindowClosed;
+    bool myIsWindowVisible;
+
+  };
+}
diff --git a/samples/xaml/App.xaml b/samples/xaml/App.xaml
deleted file mode 100644
index e922bc13c4..0000000000
--- a/samples/xaml/App.xaml
+++ /dev/null
@@ -1,7 +0,0 @@
-<Application
-  x:Class="uwp.App"
-  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-  xmlns:local="using:uwp"
-  RequestedTheme="Light">
-</Application>
diff --git a/samples/xaml/App.xaml.cpp b/samples/xaml/App.xaml.cpp
deleted file mode 100644
index a948197a29..0000000000
--- a/samples/xaml/App.xaml.cpp
+++ /dev/null
@@ -1,124 +0,0 @@
-//
-// App.xaml.cpp
-// Implementation of the App class.
-//
-
-#include "pch.h"
-#include "MainPage.xaml.h"
-
-using namespace uwp;
-
-using namespace Platform;
-using namespace Windows::ApplicationModel;
-using namespace Windows::ApplicationModel::Activation;
-using namespace Windows::Foundation;
-using namespace Windows::Foundation::Collections;
-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::Interop;
-using namespace Windows::UI::Xaml::Media;
-using namespace Windows::UI::Xaml::Navigation;
-
-/// <summary>
-/// Initializes the singleton application object.  This is the first line of authored code
-/// executed, and as such is the logical equivalent of main() or WinMain().
-/// </summary>
-App::App()
-{
-  InitializeComponent();
-  Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
-}
-
-/// <summary>
-/// Invoked when the application is launched normally by the end user.  Other entry points
-/// will be used such as when the application is launched to open a specific file.
-/// </summary>
-/// <param name="theEvent">Details about the launch request and process.</param>
-void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ theEvent)
-{
-#if _DEBUG
-  // Show graphics profiling information while debugging.
-  if (IsDebuggerPresent())
-  {
-    // Display the current frame rate counters
-    DebugSettings->EnableFrameRateCounter = true;
-  }
-#endif
-  auto rootFrame = dynamic_cast<Frame^>(Window::Current->Content);
-
-  // Do not repeat app initialization when the Window already has content,
-  // just ensure that the window is active
-  if (rootFrame == nullptr)
-  {
-    // Create a Frame to act as the navigation context and associate it with
-    // a SuspensionManager key
-    rootFrame = ref new Frame();
-
-    rootFrame->NavigationFailed += ref new Windows::UI::Xaml::Navigation::NavigationFailedEventHandler(this, &App::OnNavigationFailed);
-
-    if (theEvent->PreviousExecutionState == ApplicationExecutionState::Terminated)
-    {
-      // TODO: Restore the saved session state only when appropriate, scheduling the
-      // final launch steps after the restore is complete
-
-    }
-
-    if (theEvent->PrelaunchActivated == false)
-    {
-      if (rootFrame->Content == nullptr)
-      {
-        // When the navigation stack isn't restored navigate to the first page,
-        // configuring the new page by passing required information as a navigation
-        // parameter
-        rootFrame->Navigate(TypeName(MainPage::typeid), theEvent->Arguments);
-      }
-      // Place the frame in the current Window
-      Window::Current->Content = rootFrame;
-      // Ensure the current window is active
-      Window::Current->Activate();
-    }
-  }
-  else
-  {
-    if (theEvent->PrelaunchActivated == false)
-    {
-      if (rootFrame->Content == nullptr)
-      {
-        // When the navigation stack isn't restored navigate to the first page,
-        // configuring the new page by passing required information as a navigation
-        // parameter
-        rootFrame->Navigate(TypeName(MainPage::typeid), theEvent->Arguments);
-      }
-      // Ensure the current window is active
-      Window::Current->Activate();
-    }
-  }
-}
-
-/// <summary>
-/// Invoked when application execution is being suspended.  Application state is saved
-/// without knowing whether the application will be terminated or resumed with the contents
-/// of memory still intact.
-/// </summary>
-/// <param name="theSender">The source of the suspend request.</param>
-/// <param name="theEvent">Details about the suspend request.</param>
-void App::OnSuspending(Object^ theSender, SuspendingEventArgs^ theEvent)
-{
-  (void)theSender;  // Unused parameter
-  (void)theEvent;   // Unused parameter
-
-                    //TODO: Save application state and stop any background activity
-}
-
-/// <summary>
-/// Invoked when Navigation to a certain page fails
-/// </summary>
-/// <param name="theSender">The Frame which failed navigation</param>
-/// <param name="theEvent">Details about the navigation failure</param>
-void App::OnNavigationFailed(Platform::Object ^theSender, Windows::UI::Xaml::Navigation::NavigationFailedEventArgs ^theEvent)
-{
-  throw ref new FailureException("Failed to load Page " + theEvent->SourcePageType.Name);
-}
\ No newline at end of file
diff --git a/samples/xaml/App.xaml.h b/samples/xaml/App.xaml.h
deleted file mode 100644
index 20cba08021..0000000000
--- a/samples/xaml/App.xaml.h
+++ /dev/null
@@ -1,27 +0,0 @@
-//
-// App.xaml.h
-// Declaration of the App class.
-//
-
-#pragma once
-
-#include "App.g.h"
-
-namespace uwp
-{
-  /// <summary>
-  /// Provides application-specific behavior to supplement the default Application class.
-  /// </summary>
-  ref class App sealed
-  {
-  protected:
-    virtual void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ theEvent) override;
-
-  internal:
-    App();
-
-  private:
-    void OnSuspending(Platform::Object^ theSender, Windows::ApplicationModel::SuspendingEventArgs^ theEvent);
-    void OnNavigationFailed(Platform::Object ^theSender, Windows::UI::Xaml::Navigation::NavigationFailedEventArgs ^theEvent);
-  };
-}
diff --git a/samples/xaml/Assets/OpenSans-Regular.ttf b/samples/xaml/Assets/OpenSans-Regular.ttf
new file mode 100644
index 0000000000000000000000000000000000000000..db433349b7047f72f40072630c1bc110620bf09e
GIT binary patch
diff --git a/samples/xaml/CMakeLists.txt b/samples/xaml/CMakeLists.txt
index ee7ab9acf2..8889b46706 100644
--- a/samples/xaml/CMakeLists.txt
+++ b/samples/xaml/CMakeLists.txt
@@ -4,20 +4,15 @@ project(uwp)
 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
 
 set(SOURCE_FILES
-  App.xaml.cpp
-  MainPage.xaml.cpp
-  pch.cpp
+  App.cpp
   )
 
 set(HEADER_FILES
-  App.xaml.h
-  MainPage.xaml.h
-  pch.h
+  App.h
+  OcctAspectWindow.h
   )
 
 set(XAML_FILES
-  App.xaml
-  MainPage.xaml
   )
 
 set(ASSET_FILES
@@ -28,7 +23,9 @@ set(ASSET_FILES
     Assets/Square44x44Logo.targetsize-24_altform-unplated.png
     Assets/StoreLogo.png
     Assets/Wide310x150Logo.scale-200.png
-    )
+    Assets/OpenSans-Regular.ttf
+    ${CMAKE_SOURCE_DIR}/src/Shaders/Declarations.glsl
+    ${CMAKE_SOURCE_DIR}/src/Shaders/DeclarationsImpl.glsl)
 
 set(CONTENT_FILES
     Package.appxmanifest
@@ -107,6 +104,8 @@ set (uwp_USED_LIBS        TKernel
                           TKXSBase
                           TKSTL
                           TKVRML
+                          TKOpenGl
+                          libEGL
                           )
 
 target_link_libraries (uwp ${uwp_USED_LIBS})
diff --git a/samples/xaml/MainPage.xaml b/samples/xaml/MainPage.xaml
deleted file mode 100644
index 58ca32c34e..0000000000
--- a/samples/xaml/MainPage.xaml
+++ /dev/null
@@ -1,47 +0,0 @@
-<Page
-  x:Class="uwp.MainPage"
-  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-  xmlns:local="using:uwp"
-  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
-  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
-  mc:Ignorable="d">
-
-  <!-- Common grid-->
-  <Grid x:Name="contentPanel" HorizontalAlignment="Center" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" MinWidth="800" MinHeight="800">
-    <Grid.RowDefinitions>
-      <RowDefinition MinHeight="40" MaxHeight="40"/>
-      <RowDefinition MinHeight="30" MaxHeight="30"/>
-      <RowDefinition MinHeight="30"/>
-    </Grid.RowDefinitions>
-
-    <!-- Grid for buttons (locates at first row of Common grid)-->
-    <Grid x:Name="buttonPanel" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Grid.Row="0">
-      <Grid.RowDefinitions>
-        <RowDefinition MinHeight="40"/>
-      </Grid.RowDefinitions>
-      <Grid.ColumnDefinitions>
-        <ColumnDefinition MinWidth="190"/>
-        <ColumnDefinition MinWidth="190"/>
-        <ColumnDefinition MinWidth="190"/>
-        <ColumnDefinition MinWidth="190"/>
-        <ColumnDefinition MinWidth="190"/>
-      </Grid.ColumnDefinitions>
-      <Button x:Name="offset"  MaxHeight="30" MinHeight="30" MaxWidth="180" MinWidth="180" Content="Test offset"                 Grid.Row="0" Grid.Column="0" Click="OnClickOffset"/>
-      <Button x:Name="mesh"    MaxHeight="30" MinHeight="30" MaxWidth="180" MinWidth="180" Content="Test mesh"                   Grid.Row="0" Grid.Column="1" Click="OnClickMesh"/>
-      <Button x:Name="boolean" MaxHeight="30" MinHeight="30" MaxWidth="180" MinWidth="180" Content="Test boolean operation"      Grid.Row="0" Grid.Column="2" Click="OnClickBoolean"/>
-      <Button x:Name="tmpdir"  MaxHeight="30" MinHeight="30" MaxWidth="180" MinWidth="180" Content="Create temp file"            Grid.Row="0" Grid.Column="3" Click="OnClickBuildTemporary"/>
-      <Button x:Name="de"      MaxHeight="30" MinHeight="30" MaxWidth="180" MinWidth="180" Content="Test DataExchange"           Grid.Row="0" Grid.Column="4" Click="OnClickDataExchange"/>
-    </Grid>
-
-    <!-- TextBlock for label -->
-    <StackPanel Grid.Row="1"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
-      <TextBlock Text="Output:" HorizontalAlignment="Left" Grid.Row="1"/>
-    </StackPanel>
-
-    <!-- TextBlock for output information -->
-    <StackPanel Grid.Row="2"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
-      <TextBlock x:Name="Output_TextBlock" Text="" HorizontalAlignment="Left" Grid.Row="2"/>
-    </StackPanel>
-  </Grid>
-</Page>
diff --git a/samples/xaml/MainPage.xaml.cpp b/samples/xaml/MainPage.xaml.cpp
deleted file mode 100644
index 9915da53d7..0000000000
--- a/samples/xaml/MainPage.xaml.cpp
+++ /dev/null
@@ -1,436 +0,0 @@
-//
-// MainPage.xaml.cpp
-// Implementation of the MainPage class.
-//
-
-#include "pch.h"
-#include "MainPage.xaml.h"
-
-using namespace uwp;
-
-using namespace Platform;
-using namespace Windows::Foundation;
-using namespace Windows::Foundation::Collections;
-using namespace Windows::UI::ViewManagement;
-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;
-
-using namespace Windows::UI::Popups;
-
-#include <BRepAlgo.hxx>
-#include <BRepAlgoAPI_Fuse.hxx>
-#include <BRepMesh_IncrementalMesh.hxx>
-#include <BRepPrimAPI_MakeBox.hxx>
-#include <BRepPrimAPI_MakeSphere.hxx>
-#include <BRepTools.hxx>
-#include <Geom2dAPI_PointsToBSpline.hxx>
-#include <Geom2d_BSplineCurve.hxx>
-#include <Geom2d_OffsetCurve.hxx>
-#include <gp_Pnt.hxx>
-#include <IGESControl_Controller.hxx>
-#include <IGESControl_Reader.hxx>
-#include <IGESControl_Writer.hxx>
-#include <Interface_Static.hxx>
-#include <OSD_Directory.hxx>
-#include <OSD_File.hxx>
-#include <OSD_Path.hxx>
-#include <OSD_Protection.hxx>
-#include <STEPControl_Reader.hxx>
-#include <STEPControl_Writer.hxx>
-#include <StlAPI_Writer.hxx>
-#include <TCollection_AsciiString.hxx>
-#include <TCollection_ExtendedString.hxx>
-#include <TopExp_Explorer.hxx>
-#include <TopoDS.hxx>
-#include <TopoDS_Shape.hxx>
-#include <VrmlAPI_Writer.hxx>
-
-#include <Strsafe.h>
-
-//=======================================================================
-//function : MainPage
-//purpose  :
-//=======================================================================
-MainPage::MainPage()
-{
-  InitializeComponent();
-  ApplicationView::PreferredLaunchViewSize = Size(1000, 500);
-  ApplicationView::PreferredLaunchWindowingMode = ApplicationViewWindowingMode::PreferredLaunchViewSize;
-}
-
-//=======================================================================
-//function : Throw
-//purpose  : Test offset functionality
-//=======================================================================
-void MainPage::OnClickOffset(Platform::Object^  theSender,
-  Windows::UI::Xaml::Input::PointerRoutedEventArgs^ theEvent)
-{
-  TColgp_Array1OfPnt2d array(1, 5); // sizing array
-  array.SetValue(1, gp_Pnt2d(-4, 0)); array.SetValue(2, gp_Pnt2d(-7, 2));
-  array.SetValue(3, gp_Pnt2d(-6, 3)); array.SetValue(4, gp_Pnt2d(-4, 3));
-  array.SetValue(5, gp_Pnt2d(-3, 5));
-  Handle(Geom2d_BSplineCurve) SPL1 = Geom2dAPI_PointsToBSpline(array);
-
-  Standard_Real dist = 1;
-  Handle(Geom2d_OffsetCurve) OC =
-    new Geom2d_OffsetCurve(SPL1, dist);
-  Standard_Real dist2 = 1.5;
-  Handle(Geom2d_OffsetCurve) OC2 =
-    new Geom2d_OffsetCurve(SPL1, dist2);
-
-  Platform::String ^aMessage;
-
-  if (OC.IsNull()) {
-    aMessage = "Error: could not create offset curve with offset distance " + dist;
-  } else if (OC2.IsNull()) {
-    aMessage = "Error: could not create offset curve with offset distance 1.5" + dist2;
-  } else {
-    aMessage = "Result: Two offset curves OC and OC2 were successfully created from source curve SPL1. \n";
-  }
-  Output_TextBlock->Text = aMessage;
-}
-
-//=======================================================================
-//function : OnClickMesh
-//purpose  : Test mesh functionality
-//=======================================================================
-void MainPage::OnClickMesh(Platform::Object^  theSender,
-  Windows::UI::Xaml::Input::PointerRoutedEventArgs^ theEvent)
-{
-  TopoDS_Shape theBox = BRepPrimAPI_MakeBox(200, 60, 60);
-  TopoDS_Shape theSphere = BRepPrimAPI_MakeSphere(gp_Pnt(100, 20, 20), 80);
-  TopoDS_Shape ShapeFused = BRepAlgoAPI_Fuse(theSphere, theBox);
-  BRepMesh_IncrementalMesh(ShapeFused, 1);
-
-  Standard_Integer result(0);
-
-  for (TopExp_Explorer ex(ShapeFused, TopAbs_FACE); ex.More(); ex.Next()) {
-    TopoDS_Face F = TopoDS::Face(ex.Current());
-    TopLoc_Location L;
-    Handle(Poly_Triangulation) facing = BRep_Tool::Triangulation(F, L);
-    result = result + facing->NbTriangles();
-  }
-
-  Platform::String ^aMessage;
-  if (ShapeFused.IsNull()) {
-    aMessage = "Error: could not fuse source shapes";
-  } else if (result == 0) {
-    aMessage = "Error: mesh could not be created";
-  } else {
-    aMessage = "Result: Mesh was created\
---- Number of created triangles ---\n";
-
-    aMessage += result;
-    aMessage += ("\n\n");
-  }
-  Output_TextBlock->Text = aMessage;
-}
-
-//=======================================================================
-//function : OnClickBoolean
-//purpose  : Test boolean operations
-//=======================================================================
-void MainPage::OnClickBoolean(Platform::Object^  theSender,
-  Windows::UI::Xaml::Input::PointerRoutedEventArgs^ theEvent)
-{
-  TCollection_AsciiString asd;
-  gp_Pnt P(-5, 5, -5);
-  TopoDS_Shape theBox1 = BRepPrimAPI_MakeBox(60, 200, 70).Shape();
-
-  TopoDS_Shape theBox2 = BRepPrimAPI_MakeBox(P, 20, 150, 110).Shape();
-
-  TopoDS_Shape FusedShape = BRepAlgoAPI_Fuse(theBox1, theBox2);
-
-  Platform::String ^aMessage;
-
-  if (FusedShape.IsNull()) {
-    aMessage = "Error: could not fuse shapes theBox1 and theBox2";
-  } else {
-    aMessage = "Result: Shapes were successfully fused. \n";
-  }
-  Output_TextBlock->Text = aMessage;
-}
-
-//=======================================================================
-//function : OnClickBuildTemporary
-//purpose  : Test OSD_File::BuildTemporary() method
-//=======================================================================
-void MainPage::OnClickBuildTemporary(Platform::Object^  theSender,
-  Windows::UI::Xaml::Input::PointerRoutedEventArgs^ theEvent)
-{
-  OSD_File theTmpFile;
-  theTmpFile.BuildTemporary();
-  Standard_Boolean fKO = theTmpFile.Failed();
-  if (fKO)
-  {
-    Output_TextBlock->Text = "Error: cannot create temporary file";
-  } else {
-    OSD_Path theTmpFilepath;
-    theTmpFile.Path(theTmpFilepath);
-    TCollection_AsciiString theTmpFilepathTrek;
-    theTmpFilepath.SystemName(theTmpFilepathTrek);
-    wchar_t wchar_str[MAX_PATH];
-    StringCchCopy(wchar_str, _countof(wchar_str), L"Result: ");
-    TCollection_ExtendedString aWName(theTmpFilepathTrek);
-    StringCchCat(wchar_str, _countof(wchar_str), (const wchar_t*)aWName.ToExtString());
-    Platform::String^ p_string = ref new Platform::String(wchar_str);
-    Output_TextBlock->Text = p_string;
-  }
-}
-
-//=======================================================================
-//function : OnClickDataExchange
-//purpose  : Test data exchange functionality
-//=======================================================================
-void MainPage::OnClickDataExchange(Platform::Object^  theSender,
-    Windows::UI::Xaml::Input::PointerRoutedEventArgs^ theEvent)
-{
-  Output_TextBlock->Text = "";
-
-  // Create box for export
-  TopoDS_Shape theBox = BRepPrimAPI_MakeBox(200, 60, 60);
-
-  // Create temporary directory
-  wchar_t tmpPath[MAX_PATH];
-  wchar_t filePath[MAX_PATH];
-  char tmpPathA[MAX_PATH];
-
-  if (!GetTempPathW(_countof(tmpPath), tmpPath)) {
-    StringCchCopyW(tmpPath, _countof(tmpPath), L"./");
-  }
-
-  WideCharToMultiByte(CP_UTF8, 0, tmpPath, -1, tmpPathA, sizeof(tmpPathA), NULL, NULL);
-  OSD_Path tmpDirPath(tmpPathA);
-  OSD_Directory tmpDir(tmpDirPath);
-
-  OSD_Protection srt;
-  tmpDir.Build(srt);
-
-  // Export box to .brep
-  StringCchCopyW(filePath, _countof(filePath), tmpPath);
-  StringCchCatW(filePath, _countof(filePath), L"/box.brep");
-  if (SaveBREP(filePath, theBox))
-    Output_TextBlock->Text += L"OK: export to .brep\n";
-  // Import from .brep
-  TopoDS_Shape theBoxFromBrep;
-  if (ReadBREP(filePath, theBoxFromBrep))
-    Output_TextBlock->Text += L"OK: import from .brep\n";
-  else
-    Output_TextBlock->Text += L"Error: import from .brep\n";
-
-  // Export box to .iges
-  StringCchCopyW(filePath, _countof(filePath), tmpPath);
-  StringCchCatW(filePath, _countof(filePath), L"/box.iges");
-  if (SaveIGES(filePath, theBox))
-    Output_TextBlock->Text += L"OK: export to .iges\n";
-  // Import from .iges
-  TopoDS_Shape theBoxFromIges;
-  if (ReadIGES(filePath, theBoxFromIges))
-    Output_TextBlock->Text += L"OK: import from .iges\n";
-  else
-    Output_TextBlock->Text += L"Error: import from .iges\n";
-
-  // Export box to .step
-  StringCchCopyW(filePath, _countof(filePath), tmpPath);
-  StringCchCatW(filePath, _countof(filePath), L"/box.step");
-
-  STEPControl_StepModelType aSelection = STEPControl_AsIs;
-  if (SaveSTEP(filePath, theBox, aSelection))
-    Output_TextBlock->Text += L"OK: export to .iges\n";
-  // Import from .iges
-  TopoDS_Shape theBoxFromStep;
-  if (ReadSTEP(filePath, theBoxFromStep))
-    Output_TextBlock->Text += L"OK: import from .step\n";
-  else
-    Output_TextBlock->Text += L"Error: import from .step\n";
-
-  // Export box to .stl
-  StringCchCopyW(filePath, _countof(filePath), tmpPath);
-  StringCchCatW(filePath, _countof(filePath), L"/box.stl");
-
-  if (SaveSTL(filePath, theBox))
-    Output_TextBlock->Text += L"OK: export to .stl\n";
-
-  // Export box to .vrml
-  StringCchCopyW(filePath, _countof(filePath), tmpPath);
-  StringCchCatW(filePath, _countof(filePath), L"/box.vrml");
-
-  if (SaveVRML(filePath, theBox))
-    Output_TextBlock->Text += L"OK: export to .vrml\n";
-}
-
-//=======================================================================
-//function : SaveBREP
-//purpose  : Export shape to .brep
-//=======================================================================
-Standard_Boolean MainPage::SaveBREP(const wchar_t* theFilePath, const TopoDS_Shape& theShape)
-{
-  std::filebuf aFileBuf;
-  std::ostream aStream(&aFileBuf);
-
-  if (!aFileBuf.open(theFilePath, ios::out)) {
-    Output_TextBlock->Text += L"Error: cannot open file for export (brep)\n";
-    return Standard_False;
-  }
-
-  BRepTools::Write(theShape, aStream);
-  return Standard_True;
-}
-
-//=======================================================================
-//function : SaveIGES
-//purpose  : Export shape to .iges
-//=======================================================================
-Standard_Boolean MainPage::SaveIGES(const wchar_t* theFilePath, const TopoDS_Shape& theShape)
-{
-  std::filebuf aFileBuf;
-  std::ostream aStream(&aFileBuf);
-
-  if (!aFileBuf.open(theFilePath, ios::out)) {
-    Output_TextBlock->Text += L"Error: cannot open file for export (iges)\n";
-    return Standard_False;
-  }
-
-  IGESControl_Controller::Init();
-  IGESControl_Writer ICW(Interface_Static::CVal("XSTEP.iges.unit"), Interface_Static::IVal("XSTEP.iges.writebrep.mode"));
-
-  ICW.AddShape(theShape);
-  ICW.ComputeModel();
-
-  if (!ICW.Write(aStream)) {
-    Output_TextBlock->Text += L"Error: cannot export box to .iges\n";
-    return Standard_False;
-  }
-
-  return Standard_True;
-}
-
-//=======================================================================
-//function : SaveSTEP
-//purpose  : Export shape to .step
-//=======================================================================
-Standard_Boolean MainPage::SaveSTEP(const wchar_t* theFilePath, const TopoDS_Shape& theShape, const STEPControl_StepModelType theValue)
-{
-  std::filebuf aFileBuf;
-  std::ostream aStream(&aFileBuf);
-
-  if (!aFileBuf.open(theFilePath, ios::out)) {
-    Output_TextBlock->Text += L"Error: cannot open file for export (step)\n";
-    return Standard_False;
-  }
-
-  STEPControl_Writer aWriter;
-
-  if (aWriter.Transfer(theShape, theValue) != IFSelect_RetDone) {
-    Output_TextBlock->Text += L"Error: cannot translate shape to STEP\n";
-    return Standard_False;
-  }
-
-  const TCollection_AsciiString aFilePath (theFilePath);
-  switch (aWriter.Write (aFilePath.ToCString()))
-  {
-  case IFSelect_RetError:
-    Output_TextBlock->Text += L"Error: Incorrect Data\n";
-    break;
-  case IFSelect_RetFail:
-    Output_TextBlock->Text += L"Error: Writing has failed\n";
-    break;
-  case IFSelect_RetVoid:
-    Output_TextBlock->Text += L"Error: Nothing to transfer\n";
-    break;
-  default:
-    return Standard_True;
-  }
-  return Standard_False;
-}
-
-//=======================================================================
-//function : SaveSTL
-//purpose  : Export shape to .stl
-//=======================================================================
-Standard_Boolean MainPage::SaveSTL(const wchar_t* theFilePath, const TopoDS_Shape& theShape)
-{
-  StlAPI_Writer myStlWriter;
-  const TCollection_AsciiString aFilePath (theFilePath);
-  return myStlWriter.Write (theShape, aFilePath.ToCString());
-}
-
-//=======================================================================
-//function : SaveVRML
-//purpose  : Export shape to .vrml
-//=======================================================================
-Standard_Boolean MainPage::SaveVRML(const wchar_t* theFilePath, const TopoDS_Shape& theShape)
-{
-  VrmlAPI_Writer aWriter;
-  const TCollection_AsciiString aFilePath (theFilePath);
-  aWriter.Write (theShape, aFilePath.ToCString());
-  return Standard_True;
-}
-
-//=======================================================================
-//function : ReadBREP
-//purpose  : Import shape from .brep
-//=======================================================================
-Standard_Boolean MainPage::ReadBREP(const wchar_t* theFilePath, TopoDS_Shape& theShape)
-{
-  theShape.Nullify();
-
-  BRep_Builder aBuilder;
-  const TCollection_AsciiString aFilePath (theFilePath);
-  if (!BRepTools::Read(theShape, aFilePath.ToCString(), aBuilder))
-    return Standard_False;
-
-  return !theShape.IsNull() && BRepAlgo::IsValid(theShape);
-}
-
-//=======================================================================
-//function : ReadIGES
-//purpose  : Import shape from .iges
-//=======================================================================
-Standard_Boolean MainPage::ReadIGES(const wchar_t* theFilePath, TopoDS_Shape& theShape)
-{
-  theShape.Nullify();
-
-  IGESControl_Reader Reader;
-
-  const TCollection_AsciiString aFilePath (theFilePath);
-  if (Reader.ReadFile (aFilePath.ToCString()) != IFSelect_RetDone)
-    return Standard_False;
-
-  Reader.TransferRoots();
-  theShape = Reader.OneShape();
-
-  return !theShape.IsNull();
-}
-
-//=======================================================================
-//function : ReadSTEP
-//purpose  : Import shape from .step
-//=======================================================================
-Standard_Boolean MainPage::ReadSTEP(const wchar_t* theFilePath, TopoDS_Shape& theShape)
-{
-  theShape.Nullify();
-
-  STEPControl_Reader aReader;
-  const TCollection_AsciiString aFilePath (theFilePath);
-  switch (aReader.ReadFile (aFilePath.ToCString()))
-  {
-  case IFSelect_RetError:
-    Output_TextBlock->Text += L"Error: Not a valid Step file\n";
-    break;
-  case IFSelect_RetFail:
-    Output_TextBlock->Text += L"Error: Reading has failed\n";
-    break;
-  case IFSelect_RetVoid:
-    Output_TextBlock->Text += L"Error: Nothing to transfer\n";
-    break;
-  default:
-    return Standard_True;
-  }
-  return Standard_False;
-}
diff --git a/samples/xaml/MainPage.xaml.h b/samples/xaml/MainPage.xaml.h
deleted file mode 100644
index 93f08c9852..0000000000
--- a/samples/xaml/MainPage.xaml.h
+++ /dev/null
@@ -1,51 +0,0 @@
-//
-// MainPage.xaml.h
-// Declaration of the MainPage class.
-//
-
-#pragma once
-
-#include <TopoDS_Shape.hxx>
-#include <STEPControl_StepModelType.hxx>
-
-#include "MainPage.g.h"
-
-namespace uwp
-{
-  /// <summary>
-  /// An empty page that can be used on its own or navigated to within a Frame.
-  /// </summary>
-  public ref class MainPage sealed
-  {
-  public:
-    MainPage();
-
-    void OnClickOffset(Platform::Object^  theSender,
-      Windows::UI::Xaml::Input::PointerRoutedEventArgs^ theEvent);
-
-    void OnClickMesh(Platform::Object^  theSender,
-      Windows::UI::Xaml::Input::PointerRoutedEventArgs^ theEvent);
-
-    void OnClickBoolean(Platform::Object^  theSender,
-      Windows::UI::Xaml::Input::PointerRoutedEventArgs^ theEvent);
-
-    void OnClickDataExchange(Platform::Object^  theSender,
-        Windows::UI::Xaml::Input::PointerRoutedEventArgs^ theEvent);
-
-    void OnClickBuildTemporary(Platform::Object^  theSender,
-      Windows::UI::Xaml::Input::PointerRoutedEventArgs^ theEvent);
-
-  private:
-    // test data exchange export functionality
-    Standard_Boolean SaveBREP(const wchar_t* theFilePath, const TopoDS_Shape& theShape);
-    Standard_Boolean SaveIGES(const wchar_t* theFilePath, const TopoDS_Shape& theShape);
-    Standard_Boolean SaveSTEP(const wchar_t* theFilePath, const TopoDS_Shape& theShape, const STEPControl_StepModelType theValue);
-    Standard_Boolean SaveSTL (const wchar_t* theFilePath, const TopoDS_Shape& theShape);
-    Standard_Boolean SaveVRML(const wchar_t* theFilePath, const TopoDS_Shape& theShape);
-
-    // test data exchange import functionality
-    Standard_Boolean ReadBREP(const wchar_t* theFilePath, TopoDS_Shape& theShape);
-    Standard_Boolean ReadIGES(const wchar_t* theFilePath, TopoDS_Shape& theShape);
-    Standard_Boolean ReadSTEP(const wchar_t* theFilePath, TopoDS_Shape& theShape);
-  };
-}
diff --git a/samples/xaml/OcctAspectWindow.h b/samples/xaml/OcctAspectWindow.h
new file mode 100644
index 0000000000..b1d4c48734
--- /dev/null
+++ b/samples/xaml/OcctAspectWindow.h
@@ -0,0 +1,74 @@
+//
+// OcctAspectWindow.h
+//
+
+#pragma once
+
+#include <Aspect_Window.hxx>
+
+namespace uwp
+{
+
+//! This class defines a dummy window.
+class OcctAspectWindow : public Aspect_Window
+{
+  DEFINE_STANDARD_RTTI_INLINE(OcctAspectWindow, Aspect_Window)
+public:
+
+  //! Creates a wrapper over existing Window handle
+  OcctAspectWindow(const int theWidth, const int theHeight)
+  : myWidth (theWidth), myHeight (theHeight) {}
+
+  virtual Aspect_Drawable NativeHandle() const Standard_OVERRIDE { return 0; }
+  virtual Aspect_Drawable NativeParentHandle() const Standard_OVERRIDE { return 0; }
+  virtual Aspect_FBConfig NativeFBConfig() const Standard_OVERRIDE { return 0; }
+  virtual void Destroy() {}
+  virtual void Map() const Standard_OVERRIDE {}
+  virtual void Unmap() const Standard_OVERRIDE {}
+  virtual Aspect_TypeOfResize DoResize() const Standard_OVERRIDE { return Aspect_TOR_UNKNOWN; }
+  virtual Standard_Boolean DoMapping() const Standard_OVERRIDE { return Standard_True; }
+  virtual Standard_Boolean IsMapped() const Standard_OVERRIDE { return Standard_True; }
+
+  //! Returns The Window RATIO equal to the physical WIDTH/HEIGHT dimensions
+  virtual Quantity_Ratio Ratio() const Standard_OVERRIDE { return 1.0; }
+
+  //! Returns The Window POSITION in PIXEL
+  virtual void Position (Standard_Integer& X1, Standard_Integer& Y1,
+                         Standard_Integer& X2, Standard_Integer& Y2) const Standard_OVERRIDE
+  {
+    X1 = 0; X2 = myWidth; Y1 = 0; Y2 = myHeight;
+  }
+
+  //! Returns The Window SIZE in PIXEL
+  virtual void Size (Standard_Integer& theWidth,
+                     Standard_Integer& theHeight) const Standard_OVERRIDE
+  {
+    theWidth  = myWidth;
+    theHeight = myHeight;
+  }
+
+  //! Set The Window SIZE in PIXEL
+  Standard_Boolean SetSize (const Standard_Integer theWidth,
+                            const Standard_Integer theHeight)
+  {
+    if (myWidth  == theWidth
+     && myHeight == theHeight)
+    {
+      return Standard_False;
+    }
+
+    myWidth  = theWidth;
+    myHeight = theHeight;
+    return Standard_True;
+  }
+
+private:
+
+  int myWidth;
+  int myHeight;
+
+};
+
+DEFINE_STANDARD_HANDLE(OcctAspectWindow, Aspect_Window)
+
+}
diff --git a/samples/xaml/pch.cpp b/samples/xaml/pch.cpp
deleted file mode 100644
index 97b544ec11..0000000000
--- a/samples/xaml/pch.cpp
+++ /dev/null
@@ -1,6 +0,0 @@
-//
-// pch.cpp
-// Include the standard header and generate the precompiled header.
-//
-
-#include "pch.h"
diff --git a/samples/xaml/pch.h b/samples/xaml/pch.h
deleted file mode 100644
index b793236d02..0000000000
--- a/samples/xaml/pch.h
+++ /dev/null
@@ -1,11 +0,0 @@
-//
-// pch.h
-// Header for standard system include files.
-//
-
-#pragma once
-
-#include <collection.h>
-#include <ppltasks.h>
-
-#include "App.xaml.h"
-- 
2.24.1.windows.2

