user3245528
user3245528

Reputation: 11

SharpDx toolkit SwapChainPanel integration

I am currently working with SharpDx for a project that targets Win 8.1 and requires multiple 3D viewports on a page, along with other xaml elements. I have so far been able to install the SharpDx toolkit via Nuget, and been able to run a standard toolkit project. However the project uses the SwapChainBackgroundPanel control as the method of rendering the 3D content, shown below.

MainPage.xaml

<SwapChainBackgroundPanel
    x:Class="MyGame1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MyGame1"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignWidth="1280"
    d:DesignHeight="800">

</SwapChainBackgroundPanel>

MainPage.xaml.cs

  public sealed partial class MainPage
  {
    private readonly MyGame1 game;

    public MainPage()
    {
      this.InitializeComponent();
      game = new MyGame1();
      this.Loaded += (sender, args) => game.Run(this);
    }
  }

According to documentation I read, the SwapChainBackgroundPanel has been deprecated in favour of the newly introduced SwapChainPanel, however when I attempted to replace the SwapChainBackgroundPanel with the SwapChainPanel, I received an error.

Does anyone know if there is a plan in the immediate future to update the SharpDx toolkit to work with the SwapChainPanel in the same manner as it currently does with the SwapChainBackgroundPanel?

Thanks!

Upvotes: 1

Views: 1518

Answers (1)

Artiom Ciumac
Artiom Ciumac

Reputation: 414

The DirectX 11.2 build already fully supports integration with SwapChainPanel.

I have added a sample that demonstrates this feature.

First, make sure your project references DirectX 11.2 assemblies - this involves project editing, as described here.

After this, edit your page xaml as needed, for example like this (some code is omitted for brevity):

<Page ...>
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <SwapChainPanel x:Name="panel" x:FieldModifier="private" />
    </Grid>
</Page>

Then you need to run your game as usual like this:

using SharpDX.Toolkit;

public sealed partial class MainPage
{
    private readonly Game _game;

    public MainPage()
    {
        InitializeComponent();

        _game = new MiniCubeGame();
        _game.Run(panel);
    }
}

You can move the _game.Run(...) call to Loaded event handler if this fits better your architecture.

Upvotes: 3

Related Questions