public Create ( string name, int width, int height, bool fullScreen, Axiom miscParams ) : void | ||
name | string | |
width | int | |
height | int | |
fullScreen | bool | |
miscParams | Axiom | |
return | void |
public override void Create( string name, int width, int height, bool fullScreen, Axiom.Collections.NamedParameterList miscParams )
{
IntPtr parentHWnd = IntPtr.Zero;
IntPtr externalHWnd = IntPtr.Zero;
String title = name;
int colourDepth = 32;
int left = -1; // Defaults to screen center
int top = -1; // Defaults to screen center
bool depthBuffer = true;
string border = "";
bool outerSize = false;
_useNVPerfHUD = false;
_fsaaQuality = 0;
_vSync = false;
if ( miscParams != null )
{
// left (x)
if ( miscParams.ContainsKey( "left" ) )
{
left = Int32.Parse( miscParams[ "left" ].ToString() );
}
// top (y)
if ( miscParams.ContainsKey( "top" ) )
{
top = Int32.Parse( miscParams[ "top" ].ToString() );
}
// Window title
if ( miscParams.ContainsKey( "title" ) )
{
title = (string)miscParams[ "title" ];
}
#if !(XBOX || XBOX360 || SILVERLIGHT)
// parentWindowHandle -> parentHWnd
if ( miscParams.ContainsKey( "parentWindowHandle" ) )
{
object handle = miscParams[ "parentWindowHandle" ];
if ( handle.GetType() == typeof( IntPtr ) )
{
parentHWnd = (IntPtr)handle;
}
else if ( handle.GetType() == typeof( System.Int32 ) )
{
parentHWnd = new IntPtr( (int)handle );
}
}
// externalWindowHandle -> externalHWnd
if ( miscParams.ContainsKey( "externalWindowHandle" ) )
{
object handle = miscParams[ "externalWindowHandle" ];
if ( handle.GetType() == typeof( IntPtr ) )
{
externalHWnd = (IntPtr)handle;
}
else if ( handle.GetType() == typeof( System.Int32 ) )
{
externalHWnd = new IntPtr( (int)handle );
}
}
#endif
// vsync [parseBool]
if ( miscParams.ContainsKey( "vsync" ) )
{
_vSync = bool.Parse( miscParams[ "vsync" ].ToString() );
}
// displayFrequency
if ( miscParams.ContainsKey( "displayFrequency" ) )
{
_displayFrequency = Int32.Parse( miscParams[ "displayFrequency" ].ToString() );
}
// colourDepth
if ( miscParams.ContainsKey( "colorDepth" ) )
{
colourDepth = Int32.Parse( miscParams[ "colorDepth" ].ToString() );
}
// depthBuffer [parseBool]
if ( miscParams.ContainsKey( "depthBuffer" ) )
{
depthBuffer = bool.Parse( miscParams[ "depthBuffer" ].ToString() );
}
//FSAA type should hold a bool value, because anti-aliasing is either enabled, or it isn't.
//// FSAA type
//if ( miscParams.ContainsKey( "FSAA" ) )
//{
// //_fsaaType = (XFG.MultiSampleType)miscParams[ "FSAA" ];
//}
// FSAA quality
if ( miscParams.ContainsKey( "FSAAQuality" ) )
{
_fsaaQuality = Int32.Parse( miscParams[ "FSAAQuality" ].ToString() );
}
// window border style
if ( miscParams.ContainsKey( "border" ) )
{
border = ( (string)miscParams[ "border" ] ).ToLower();
}
// set outer dimensions?
if ( miscParams.ContainsKey( "outerDimensions" ) )
{
outerSize = bool.Parse( miscParams[ "outerDimensions" ].ToString() );
}
// NV perf HUD?
if ( miscParams.ContainsKey( "useNVPerfHUD" ) )
{
_useNVPerfHUD = bool.Parse( miscParams[ "useNVPerfHUD" ].ToString() );
}
}
#if !(XBOX || XBOX360 || SILVERLIGHT)
if ( _windowHandle != IntPtr.Zero )
Dispose();
if ( externalHWnd == IntPtr.Zero )
{
Width = width;
Height = height;
this.top = top;
this.left = left;
_isExternal = false;
DefaultForm newWin = new DefaultForm();
newWin.Text = title;
/* If we're in fullscreen, we can use the device's back and stencil buffers.
* If we're in windowed mode, we'll want our own.
* get references to the render target and depth stencil surface
*/
if ( !fullScreen )
{
newWin.StartPosition = SWF.FormStartPosition.CenterScreen;
if ( parentHWnd != IntPtr.Zero )
{
newWin.Parent = SWF.Control.FromHandle( parentHWnd );
}
else
{
if ( border == "none" )
{
newWin.FormBorderStyle = SWF.FormBorderStyle.None;
}
else if ( border == "fixed" )
{
newWin.FormBorderStyle = SWF.FormBorderStyle.FixedSingle;
newWin.MaximizeBox = false;
}
}
if ( !outerSize )
{
newWin.ClientSize = new System.Drawing.Size( Width, Height );
}
else
{
newWin.Width = Width;
newWin.Height = Height;
}
if ( top < 0 )
top = ( SWF.Screen.PrimaryScreen.Bounds.Height - Height ) / 2;
if ( left < 0 )
left = ( SWF.Screen.PrimaryScreen.Bounds.Width - Width ) / 2;
}
else
{
//dwStyle |= WS_POPUP;
top = left = 0;
}
// Create our main window
newWin.Top = top;
newWin.Left = left;
newWin.RenderWindow = this;
_windowHandle = newWin.Handle;
WindowEventMonitor.Instance.RegisterWindow( this );
}
else
{
_windowHandle = externalHWnd;
_isExternal = true;
}
#endif
// set the params of the window
this.Name = name;
this.ColorDepth = colourDepth;
this.Width = width;
this.Height = height;
this.IsFullScreen = fullScreen;
this.isDepthBuffered = depthBuffer;
this.top = top;
this.left = left;
CreateXnaResources();
#if !(XBOX || XBOX360 || SILVERLIGHT)
( SWF.Control.FromHandle( _windowHandle ) ).Show();
#endif
IsActive = true;
_isClosed = false;
LogManager.Instance.Write( "[XNA] : Created D3D9 Rendering Window '{0}' : {1}x{2}, {3}bpp", Name, Width, Height, ColorDepth );
}
/// <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; }