/// <summary>
/// Creates a new render window.
/// </summary>
/// <remarks>
/// This method creates a new rendering window as specified
/// by the paramteters. The rendering system could be
/// responible for only a single window (e.g. in the case
/// of a game), or could be in charge of multiple ones (in the
/// case of a level editor). The option to create the window
/// as a child of another is therefore given.
/// This method will create an appropriate subclass of
/// RenderWindow depending on the API and platform implementation.
/// </remarks>
/// <param name="name"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="isFullScreen"></param>
/// <param name="miscParams">
/// A collection of addition rendersystem specific options.
/// </param>
public override RenderWindow CreateRenderWindow(string name, int width, int height, bool isFullScreen, NamedParameterList miscParams)
{
// Check we're not creating a secondary window when the primary
// was fullscreen
if (_primaryWindow != null && _primaryWindow.IsFullScreen)
throw new Exception("Cannot create secondary windows when the primary is full screen.");
if (_primaryWindow != null && isFullScreen)
throw new ArgumentException("Cannot create full screen secondary windows.");
// Log a message
var strParams = new StringBuilder();
if (miscParams != null)
{
foreach (var entry in miscParams)
{
strParams.AppendFormat("{0} = {1}; ", entry.Key, entry.Value);
}
}
LogManager.Instance.Write("[XNA] : Creating RenderWindow \"{0}\", {1}x{2} {3} miscParams: {4}",
name, width, height, isFullScreen ? "fullscreen" : "windowed",
strParams.ToString());
// Make sure we don't already have a render target of the
// same name as the one supplied
if (renderTargets.ContainsKey(name))
{
throw new Exception(String.Format("A render target of the same name '{0}' already exists." +
"You cannot create a new window with this name.", name));
}
RenderWindow window = new XnaRenderWindow(_activeDriver, _primaryWindow != null ? _device : null);
// create the window
window.Create(name, width, height, isFullScreen, miscParams);
// add the new render target
AttachRenderTarget(window);
// If this is the first window, get the D3D device and create the texture manager
if (_primaryWindow == null)
{
_primaryWindow = (XnaRenderWindow)window;
_device = (GraphicsDevice)window["XNADEVICE"];
basicEffect = new BasicEffect(_device);
skinnedEffect = new SkinnedEffect(_device);
// Create the texture manager for use by others
textureManager = new XnaTextureManager(_device);
// Also create hardware buffer manager
_hardwareBufferManager = new XnaHardwareBufferManager( _device );
// Create the GPU program manager
gpuProgramMgr = new XnaGpuProgramManager(_device);
// create & register HLSL factory
//gpuProgramMgr.PushSyntaxCode("hlsl"));
realCapabilities = new RenderSystemCapabilities();
// use real capabilities if custom capabilities are not available
if (!useCustomCapabilities)
{
currentCapabilities = realCapabilities;
}
FireEvent("RenderSystemCapabilitiesCreated");
InitializeFromRenderSystemCapabilities(currentCapabilities, window);
// Initialize the capabilities structures
_checkHardwareCapabilities( _primaryWindow );
}
else
{
_secondaryWindows.Add((XnaRenderWindow)window);
}
#if !SILVERLIGHT // Can only work on _device inside the Draw callback
StateManager.ResetState( _device );
#endif
return window;
}