Unfortunately, XNA has a limitation that it works only with DirectX 9. I love the framework but this limitation really annoys me. Mainly because limit the use to Shader Model 3.0. This post shows a library, called MachinaAurum.Xna.SlimDx that ends with this limitation and allows everyone to use DirectX 10 (or DirectX 11 or OpenGL) in XNA. It is NOT a rewrite of the XNA library as MonoXNA. It uses all the code base of XNA but "hacked" to use other graphical devices.
First I will try to show how to render a simple model in XNA 4.0 ( it will only work in XNA 4.0 and C# 4.0 ) and then make the code changes to render the same model in DirectX 10. The change from normal XNA to DirectX 10 has some code changes because both APIs (DirectX 9 and DirectX 10) have some differences. So, let us start!
The first step is to create a game project. Obviously a “Windows Game” because XBOX does not run DirectX 10 (and I do not have a XBOX here…)


Before the change to DirectX 10 I want to render a simple cube to the screen. So I will insert it in the Content Project.

My content type is “.dae”. For those who do not know, “.dae” is a COLLADA model. XNA by default does not have a COLLADA loader, so I am using MachinaAurum.Xna.Collada. For the time of this post the COLLADA loader is only in proof-of-concept form, but it will serve my needs here. It will load the cube and I will show that a custom loader to XNA will work in DirectX 10!!


And now I am ready to load my model in the XNA code.
DISCLAIMER #1: This is not the best way to program games. In later posts I will try to show better ways. The simplicity of the code here is just an example! Please, never write code like this.

The first line of the method loads the cube. Then we export the absolute matrices of the model.

In the Draw method, we have to clear the screen, enumerate all the model meshes, put the matrices in its effects and after, we draw everything. After all of this, we have:

A cube!!
Ok. Nothing fancy… but now let us change the graphical device from XNA DirectX 9 to DirectX 10. The first thing we have to do is add the reference to MachinaAurum.Xna.SlimDx (SlimDx is a framework to work with managed DirectX).

And now starts the code changes… The first change is in the game main class. The XNA template, created the following code…

I will change the base type from Game to AurumGame.

After this I will make a small change in the constructor. The original code is…

The important part here is the GraphicsDeviceManager class. This class creates the XNA DirectX 9 device. So let us change this class to AurumGraphicsDeviceManager.

The second parameter is an enumerator with each graphic API that you can create.
We will choose DirectX10.
After this change we need to change the model type from Model to AurumModel.

The draw method has two little changes…

The first difference is in the clear method. Now we are calling a static class that has an abstract graphic device. The same we created in the game constructor.
The second difference is in the second foreach. We changed the type from BasicEffect to dynamic. For those who do not know, dynamic is a new type in c# 4. Bing about for more information.
And that is it! We are now using DirectX 10!
DISCLAIMER #2: This code is only proof-of-concept. The shader used is ridiculous and useless. There is no way to changed it. Just a small percentage of the API is coded etc...
In future posts I will try to show the advances of this framework.
