The Xna implementation of the RenderWindow class.
Inheritance: Axiom.Graphics.RenderWindow, Microsoft.Xna.Framework.Graphics.IGraphicsDeviceService
Example #1
0
		//private XFG.DepthStencilBuffer _getDepthStencilFor( XFG.SurfaceFormat fmt, XFG.MultiSampleType multisample, int width, int height )
		//{
		//    XFG.DepthStencilBuffer zbuffer = null;

		//    XFG.DepthFormat dsfmt = _getDepthStencilFormatFor( fmt );
		//    if ( dsfmt == XFG.DepthFormat.Unknown )
		//        return null;

		//    /// Check if result is cached
		//    ZBufferFormat zbfmt = new ZBufferFormat( dsfmt, multisample );
		//    XFG.DepthStencilBuffer cachedzBuffer;
		//    if ( zBufferCache.TryGetValue( zbfmt, out cachedzBuffer ) )
		//    {
		//        /// Check if size is larger or equal
		//        if ( cachedzBuffer.Width >= width &&
		//            cachedzBuffer.Height >= height )
		//        {
		//            zbuffer = cachedzBuffer;
		//        }
		//        else
		//        {
		//            zBufferCache.Remove( zbfmt );
		//            cachedzBuffer.Dispose();
		//        }
		//    }

		//    if ( zbuffer == null )
		//    {
		//        // If not, create the depthstencil surface
		//        zbuffer = new XFG.DepthStencilBuffer( _device, width, height, dsfmt, multisample, 0 );
		//        zBufferCache[ zbfmt ] = zbuffer;
		//    }

		//    return zbuffer;
		//}

















		//public struct ZBufferFormat
		//{
		//    public ZBufferFormat( XFG.DepthFormat f, XFG.MultiSampleType m )
		//    {
		//        this.format = f;
		//        this.multisample = m;
		//    }
		//    public XFG.DepthFormat format;
		//    public XFG.MultiSampleType multisample;
		//}
		//protected Dictionary<ZBufferFormat, XFG.DepthStencilBuffer> zBufferCache = new Dictionary<ZBufferFormat, XFG.DepthStencilBuffer>();
		//protected Dictionary<XFG.SurfaceFormat, XFG.DepthFormat> depthStencilCache = new Dictionary<XFG.SurfaceFormat, XFG.DepthFormat>();



		//private XFG.DepthStencilBuffer _getDepthStencilFor( XFG.SurfaceFormat fmt, XFG.MultiSampleType multisample, int width, int height )
		//{
		//    XFG.DepthStencilBuffer zbuffer = null;

		//    XFG.DepthFormat dsfmt = _getDepthStencilFormatFor( fmt );
		//    if ( dsfmt == XFG.DepthFormat.Unknown )
		//        return null;

		//    /// Check if result is cached
		//    ZBufferFormat zbfmt = new ZBufferFormat( dsfmt, multisample );
		//    XFG.DepthStencilBuffer cachedzBuffer;
		//    if ( zBufferCache.TryGetValue( zbfmt, out cachedzBuffer ) )
		//    {
		//        /// Check if size is larger or equal
		//        if ( cachedzBuffer.Width >= width &&
		//            cachedzBuffer.Height >= height )
		//        {
		//            zbuffer = cachedzBuffer;
		//        }
		//        else
		//        {
		//            zBufferCache.Remove( zbfmt );
		//            cachedzBuffer.Dispose();
		//        }
		//    }

		//    if ( zbuffer == null )
		//    {
		//        // If not, create the depthstencil surface
		//        zbuffer = new XFG.DepthStencilBuffer( _device, width, height, dsfmt, multisample, 0 );
		//        zBufferCache[ zbfmt ] = zbuffer;
		//    }

		//    return zbuffer;
		//}
		/// <summary>
		///	Helper method to go through and interrogate hardware capabilities.
		/// </summary>
		private RenderSystemCapabilities _checkHardwareCapabilities( XnaRenderWindow window )
		{
			//TODO Detect what graphics profile we should use, depending on current platform.
			//This information should be retrieved from _device.GraphicsProfile property
#if SILVERLIGHT
			XFG.GraphicsProfile profile = XFG.GraphicsProfile.Reach;
#else
			XFG.GraphicsProfile profile = XFG.GraphicsProfile.HiDef;
#endif

			var rsc = realCapabilities ?? new RenderSystemCapabilities();

			_setCapabilitiesForAllProfiles( ref rsc );

#if !SILVERLIGHT
			if ( profile == XFG.GraphicsProfile.HiDef )
				_setCapabilitiesForHiDefProfile( ref rsc );
			else 
#endif
			if ( profile == XFG.GraphicsProfile.Reach )
				_setCapabilitiesForReachProfile( ref rsc );

			else
				throw new AxiomException( "Not a valid profile!" );

			if ( realCapabilities == null )
			{
				realCapabilities = rsc;

				// create & register HLSL factory
				realCapabilities.AddShaderProfile( "hlsl" );

				// if we are using custom capabilities, then 
				// mCurrentCapabilities has already been loaded
				if ( !useCustomCapabilities )
					currentCapabilities = realCapabilities;

				FireEvent( "RenderSystemCapabilitiesCreated" );

				InitializeFromRenderSystemCapabilities( currentCapabilities, window );
			}

			return rsc;
		}
Example #2
0
		/// <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;
		}