Share via


Taking the phone to the 3rd dimension - Direct3D on Windows Phone 8 for Windows 8 Store app developers

There are a lot of really great tutorials explaining how to get the most out of Direct3D on the Windows 8 Store or Windows Phone 8 platforms. In this blog I’m going to try to compare the two, focusing on what is different on the phone. Since I am going to be focusing on the phone I make some assumptions that you understand the basic concepts behind programming Direct3D in a Windows Store 8 app.

With the advent of Windows Phone 8 for the first time we were able to bring the magic of Direct3D to the phone. In this revision we focused on porting virtually the entire API. This is in an effort to bring premium gaming experiences to the phone giving developers the familiar Direct3D APIs that you have come to know.

One of the things that came along with the addition of Direct3D to the phone was support for C++. As you can guess C++ is required for Direct3D support. What this really means is that if you want to write a Direct3D based app on Windows Phone 8 you will need to write it in C++. We don’t officially support writing Direct3D based games with any programming language other than C++. The good news is that if you are a C# or VB.NET developer you have options.

We do still have support for XNA on the Windows Phone platform. For those not familiar with it, XNA is a light weight relatively easy to use game development platform based on .NET. While we are encouraging all of our Windows Phone game developers to move from XNA to C++ the migration path isn’t easy. Luckily we’ve gotten a lot of help from our partners and the community. I would encourage you to check out some of the exciting work being done by 3rd parties for XNA and Direct3D on Windows Phone 8.

On an interesting side note, since we now support C++ on Windows Phone 8 what happens if you want to write a strictly C++ based app based on XAML? Unfortunately this is not yet possible. The amazing C++ XAML stack that was created for Windows 8 Store apps is not yet available on the phone. On the phone you can either choose to create a Direct3D app (C++) with XAML (C#) or just a native Direct3D app (C++). Either way you get a “spinning cube” by default. But what if you are like one of our friends on the Windows Phone 8 forum and don’t need D3D but still want to add some C++ classes to your app? Luckily we have an easy solution, you can do this by creating a simple C# app and then adding a C++ “Windows Phone Runtime Component” project to it.

That brings us to XAML interop. One of the other cool new features that we added to Windows 8 Store Apps is XAML interop with Direct3D. By redesigning the way the XAML rich compositor works with Direct3D we now allow you to mix Direct3D and XAML in the same application. This adds a huge benefit for game developers. You no longer need to worry about creating your “heads up display” in painstaking Direct3D. Now you can use the rich layout capabilities of XAML to show your life bar and score by styling the built in XAML controls.

Many of the concepts are the same between the two platforms. Unfortunately the nomenclature is different. Hopefully this simple chart will show you what controls are equivalent at the conceptual level.

Windows Store

Windows Phone 8

SwapChainBackgroundPanel

DrawingSurfaceBackgroundGrid

SurfaceImageSource

DrawingSurface

You can now leverage the layout power of XAML to quickly create your “heads up display” (HUD). You can lay XAML over the top of your Direct3D environment using the “DrawingSurfaceBackgroundGrid” or the “SwapChainBackground” panel on Windows Phone 8 and Windows 8 Store apps respectively. If you just want to add “splashes” of Direct3D to your otherwise XAML heavy app you should consider using the “SurfaceImageSource” or the “DrawingSurface” on Windows Store app and Windows Phone 8 respectively.

I want to make you aware of a few of the differences between Windows 8 Store apps and Windows Phone 8 apps using Direct3D that developers on the forums run into from time to time:

  • We mentioned this before but as you know we don’t have a XAML stack for C++ on the Phone, because of this if you want to use XAML and Direct3D you will need to create a mixed solution using C# for your HUD and C++ for your Direct3D calls. Interestingly though if you don’t need XAML you can create a pure C++ Direct3D app.

  • When using the “DrawingSurfaceBackgroundGrid” on the Phone you may want to have more interaction with the composition process. You can do this by using the “IDrawingSurfaceBackgroundContentProvider”. This interface is designed to allow you to start creating and preparing resources ahead of rendering time. For example: Create elements of the 3D scene such as shaders, vertex buffers, etc. We also give you a level of control when rendering your scene using this interface.

  • Finally I want to make you aware of the biggest head scratcher we’ve had reported via our friends in the forum. There is no mixed mode debugging in Visual Studio 2012 for Windows Phone 8. In other words unlike a Windows 8 Store app you can’t set a breakpoint in your C# code and one in your C++ code and expect both of them to be hit during the same debugging session. To allow debuging into your C++ code in your mixed XAML and Direct3D app you need to enable “native only” debugging. You can do this by clicking on your C# project and selecting “project” from the menu bar. Then select “[your app] project…” from the pop-up menu. On the Application properties page find the “UI task” under “debugger type”. Change the mode to “native only” using the drop down.

    Since this is an important one and pictures are worth a thousand words:

 

Here are a few links to hopefully help you get started.

Tutorial Series - Introduction to Direct3D with XAML application development for Windows Phone 8

https://blogs.msdn.com/b/jdupuy/archive/2013/07/15/tutorial-series-introduction-to-direct3d-with-xaml-application-development-for-windows-phone-8.aspx

XAML and Direct3D apps for Windows Phone 8

https://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207012(v=vs.105).aspx/css

Supported Direct3D APIs for Windows Phone 8

https://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207010%28v=vs.105%29.aspx

I hope this helps,

James

 Check us out on twitter #wsdevsol