2014-01-28 50 views
1

我目前正在與SharpDx合作開發一款針對Win 8.1並且需要多個3D視口以及其他xaml元素的項目。到目前爲止,我已經能夠通過Nuget安裝SharpDx工具包,並且能夠運行標準的工具包項目。但是該項目使用SwapChainBackgroundPanel控件作爲渲染3D內容的方法,如下所示。SharpDx工具包SwapChainPanel集成

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); 
    } 
    } 

根據文檔我讀的SwapChainBackgroundPanel一直支持新推出的SwapChainPanel的過時了,但是當我試圖用SwapChainPanel替換SwapChainBackgroundPanel,我收到一個錯誤。

是否有人知道是否有計劃在不久的將來更新SharpDx工具包以與SwapChainBackgroundPanel一樣的方式使用SwapChainPanel?

謝謝!

+0

SharpDX幾乎每天都會更新。您可以下載[最新開發版](http://sharpdx.org/upload/SharpDX-SDK-LatestDev.exe) 無論如何,你得到了什麼錯誤?如果尚未實現,可以在[GitHub](https://github.com/sharpdx/SharpDX)上詢問。 – TheWanderer

回答

3

DirectX 11.2 build已經完全支持與SwapChainPanel的集成。

我已經添加了一個演示此功能的sample

首先,確保您的項目引用DirectX 11.2程序集 - 這涉及項目編輯,如here所述。

在此之後,根據需要,例如像這樣(爲了簡潔省略了一些代碼)編輯你的頁面的XAML:

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

然後,你需要這樣的運行遊戲像往常一樣:

using SharpDX.Toolkit; 

public sealed partial class MainPage 
{ 
    private readonly Game _game; 

    public MainPage() 
    { 
     InitializeComponent(); 

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

如果這更適合您的架構,您可以將_game.Run(...)調用移動到Loaded事件處理程序。

+0

什麼是釋放遊戲資源的正確方法? MiniCubeGame阻礙了IDisposable,所以它必須在某些時候被調用。 – Dmitry