Initialization (optional) - RolandKoenig/SeeingSharp GitHub Wiki
Automatic initialization
The following steps are done automatically with default settings if you load any 3D view or such like. So you need only to do them if you want to change initialization settings. A sample scenario would be that you want to enable debug mode of Direct3D.
Initialization
There are two things that must be initialized before we can display any 3d graphics using Seeing#. The first one is the global SeeingSharpApplication object. This one is like a baseline for all Seeing# components and manages things like all bootstrappers, application services, automatic type search, singletons and such like. The second global object that we have to initialize is the GraphicsCore. Just like it sounds, this one is the core component of the Graphics Engine and manages available graphics devices and the rendering loop.
Here you see the Coding for a WPF application:
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
// Default initializations
SeeingSharpApplication.InitializeAsync(
Assembly.GetExecutingAssembly(),
new Assembly[]{
typeof(GraphicsCore).Assembly
},
new string[0]).Wait();
GraphicsCore.Initialize();
}
}
As you see here, we give some Assemblies to the SeeingSharpApplication object. Seeing# needs these objects for internal type queries. The bad thing here is the synchronous Wait call. I use this one because we must have all things initialized before the first 3d-view opens. Clearly, not the best solution for WPF, but for now it does its Job.
Initialization for Win.Forms looks just like the code above. On WinRT things are a bit different because there we can use the async-await pattern correctly. Just read the next sample code.
public sealed partial class App : Application
{
public App()
{
this.InitializeComponent();
}
protected override async void OnLaunched(LaunchActivatedEventArgs e)
{
// Initialize application and graphics
Exception initException = null;
if (!SeeingSharpApplication.IsInitialized)
{
await SeeingSharpApplication.InitializeAsync(
this.GetType().GetTypeInfo().Assembly,
new Assembly[]
{
typeof(SeeingSharpApplication).GetTypeInfo().Assembly,
typeof(GraphicsCore).GetTypeInfo().Assembly
},
new string[] { e.Arguments });
try
{
GraphicsCore.Initialize();
#if WINDOWS_APP
// Force high texture quality on tablet devices
foreach(EngineDevice actDevice in GraphicsCore.Current.LoadedDevices)
{
if (actDevice.IsSoftware) { continue; }
actDevice.Configuration.TextureQuality = TextureQuality.Hight;
}
#endif
}
catch (Exception ex)
{
initException = ex;
}
}
// Create the main game page and associate it withe the main window
if (initException == null)
{
MainGamePage gamePage = new MainGamePage();
Window.Current.Content = gamePage;
}
else
{
ExceptionInfo exInfo = new ExceptionInfo(initException);
DummyPage exceptionPage = new DummyPage();
exceptionPage.DataContext = exInfo;
Window.Current.Content = exceptionPage;
}
// Ensure that the main window is activated
Window.Current.Activate();
}
}