The aim of this post is to give you some tricks to enable 3D experiences with Silverlight 5 for your applications.
But first of all, let’s see how you can activate accelerated 3D support inside a Silverlight 5 project.
To activate accelerated 3D support, the host of Silverlight must activate it using a param named “enableGPUAcceleration”:
By doing this, you will allow Silverlight to use the graphic card’s power to render XAML elements. And at the same time, you will activate the accelerated 3D support.
You can detect if 3D is activated or not in your code through the GraphicsDeviceManager class:
The RenderMode property will be set to Unavailable when 3D is not activated.
In this case, the property GraphicsDeviceManager.Current.RenderModeReason will be set to one of these values:
You will get this reason when your graphic card is too old to support 3D required features such as shader model 2.0.
You forgot to set enableGPUAcceleration to true in the hosting HTML page.
When you launch your application, a specific domain entry for 3D can be set to the Permissions tab of the Silverlight Configuration panel.
You will not see this entry unless your domain group policy set it (and in this case you have to ask permissions to your administrator) or you run your Silverlight application under Windows XP.
When you run a Silverlight application under Windows XP, the following behavior happen:
- 3D is enabled automatically in elevated trust (out of browser)
- The first time a user runs a non-elevated 3D application, a domain entry set to Deny is added to the Permissions tab of the Silverlight Configuration panel
To use a 3D application under Windows XP in a non-elevated context, you must change the pre-created Deny entry to Allow.
This happen when the device is lost (for example under lock screen on Windows XP. It doesn’t happen much in WDDM) where Silverlight expects the rendering surface to return at some point.
One other important point to know is that 3D won’t work correctly inside windowless mode. In this case, the draw event will be driven from the UI thread and so will be fired only during UI events such as page scroll for example.
I hope this post was useful to help you use the wonderful accelerated 3D experience of Silverlight 5.
As you can see, the better solution to handle 3D support is to use GraphicsDeviceManager.Current.RenderModeReason.