public override List<GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters preferredParameters)
        {
            var graphicsDeviceInfos = base.FindBestDevices(preferredParameters);

            // Special case where the default FindBestDevices is not working
            if (graphicsDeviceInfos.Count == 0)
            {
                var graphicsAdapter = GraphicsAdapterFactory.Adapters[0];

                // Iterate on each preferred graphics profile
                foreach (var featureLevel in preferredParameters.PreferredGraphicsProfile)
                {
                    // Check if this profile is supported.
                    if (graphicsAdapter.IsProfileSupported(featureLevel))
                    {
                        var deviceInfo = new GraphicsDeviceInformation
                                             {
                                                 Adapter = graphicsAdapter,
                                                 GraphicsProfile = featureLevel,
                                                 PresentationParameters =
                                                     {
                                                         MultiSampleCount = MSAALevel.None,
                                                         IsFullScreen = preferredParameters.IsFullScreen,
                                                         PresentationInterval = preferredParameters.SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate,
                                                         DeviceWindowHandle =  MainWindow.NativeWindow,
                                                     }
                                             };

                        // Hardcoded format and refresh rate...
                        // This is a workaround to allow this code to work inside the emulator
                        // but this is not really robust
                        // TODO: Check how to handle this case properly
                        var displayMode = new DisplayMode(PixelFormat.B8G8R8A8_UNorm, gameWindow.ClientBounds.Width, gameWindow.ClientBounds.Height, new Rational(60, 1));
                        AddDevice(displayMode, deviceInfo, preferredParameters, graphicsDeviceInfos);

                        // If the profile is supported, we are just using the first best one
                        break;
                    }
                }
            }

            return graphicsDeviceInfos;
        }
示例#2
0
        public override List <GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters preferredParameters)
        {
            var graphicsDeviceInfos = base.FindBestDevices(preferredParameters);

            // Special case where the default FindBestDevices is not working
            if (graphicsDeviceInfos.Count == 0)
            {
                var graphicsAdapter = GraphicsAdapterFactory.Adapters[0];

                // Iterate on each preferred graphics profile
                foreach (var featureLevel in preferredParameters.PreferredGraphicsProfile)
                {
                    // Check if this profile is supported.
                    if (graphicsAdapter.IsProfileSupported(featureLevel))
                    {
                        var deviceInfo = new GraphicsDeviceInformation
                        {
                            Adapter                = graphicsAdapter,
                            GraphicsProfile        = featureLevel,
                            PresentationParameters =
                            {
                                MultiSampleCount     = MSAALevel.None,
                                IsFullScreen         = preferredParameters.IsFullScreen,
                                PresentationInterval = preferredParameters.SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate,
                                DeviceWindowHandle   = MainWindow.NativeWindow,
                            }
                        };

                        // Hardcoded format and refresh rate...
                        // This is a workaround to allow this code to work inside the emulator
                        // but this is not really robust
                        // TODO: Check how to handle this case properly
                        var displayMode = new DisplayMode(PixelFormat.B8G8R8A8_UNorm, gameWindow.ClientBounds.Width, gameWindow.ClientBounds.Height, new Rational(60, 1));
                        AddDevice(displayMode, deviceInfo, preferredParameters, graphicsDeviceInfos);

                        // If the profile is supported, we are just using the first best one
                        break;
                    }
                }
            }

            return(graphicsDeviceInfos);
        }
示例#3
0
        public override List <GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters preferredParameters)
        {
            var gameWindowiOS = gameWindow as GameWindowiOS;

            if (gameWindowiOS != null)
            {
                var graphicsAdapter           = GraphicsAdapterFactory.Default;
                var graphicsDeviceInfos       = new List <GraphicsDeviceInformation>();
                var preferredGraphicsProfiles = preferredParameters.PreferredGraphicsProfile;
                foreach (var featureLevel in preferredGraphicsProfiles)
                {
                    // Check if this profile is supported.
                    if (graphicsAdapter.IsProfileSupported(featureLevel))
                    {
                        // Everything is already created at this point, just transmit what has been done
                        var deviceInfo = new GraphicsDeviceInformation
                        {
                            Adapter                = GraphicsAdapterFactory.Default,
                            GraphicsProfile        = featureLevel,
                            PresentationParameters = new PresentationParameters(gameWindowiOS.ClientBounds.Width,
                                                                                gameWindowiOS.ClientBounds.Height,
                                                                                gameWindowiOS.NativeWindow)
                            {
                                // TODO: PDX-364: Transmit what was actually created
                                BackBufferFormat   = preferredParameters.PreferredBackBufferFormat,
                                DepthStencilFormat = preferredParameters.PreferredDepthStencilFormat,
                            }
                        };

                        graphicsDeviceInfos.Add(deviceInfo);

                        // If the profile is supported, we are just using the first best one
                        break;
                    }
                }

                return(graphicsDeviceInfos);
            }
            return(base.FindBestDevices(preferredParameters));
        }
示例#4
0
        private void CreateDevice(GraphicsDeviceInformation newInfo)
        {
            newInfo.PresentationParameters.IsFullScreen         = isFullScreen;
            newInfo.PresentationParameters.PresentationInterval = SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate;
            newInfo.DeviceCreationFlags = DeviceCreationFlags;

            OnPreparingDeviceSettings(this, new PreparingDeviceSettingsEventArgs(newInfo));

            // this.ValidateGraphicsDeviceInformation(newInfo);

            bool deviceRecreate = GraphicsDevice != null;

            // Notify device is resetting (usually this should result in graphics resources being destroyed)
            if (deviceRecreate)
            {
                OnDeviceResetting(this, EventArgs.Empty);
            }

            // Create (or recreate) the graphics device
            GraphicsDevice = graphicsDeviceFactory.ChangeOrCreateDevice(GraphicsDevice, newInfo);

            // Notify device is reset (usually this should result in graphics resources being recreated/reloaded)
            if (deviceRecreate)
            {
                OnDeviceReset(this, EventArgs.Empty);
            }

            GraphicsDevice.ShaderProfile = ShaderProfile;

            // TODO HANDLE Device Resetting/Reset/Lost
            //GraphicsDevice.DeviceResetting += GraphicsDevice_DeviceResetting;
            //GraphicsDevice.DeviceReset += GraphicsDevice_DeviceReset;
            //GraphicsDevice.DeviceLost += GraphicsDevice_DeviceLost;
            if (!deviceRecreate)
            {
                GraphicsDevice.Disposing += GraphicsDevice_Disposing;
            }

            OnDeviceCreated(this, EventArgs.Empty);
        }
示例#5
0
        public override List<GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters preferredParameters)
        {
            var gameWindowiOS = gameWindow as GameWindowiOS;
            if (gameWindowiOS != null)
            {
                var graphicsAdapter = GraphicsAdapterFactory.Default;
                var graphicsDeviceInfos = new List<GraphicsDeviceInformation>();
                var preferredGraphicsProfiles = preferredParameters.PreferredGraphicsProfile;
                foreach (var featureLevel in preferredGraphicsProfiles)
                {
                    // Check if this profile is supported.
                    if (graphicsAdapter.IsProfileSupported(featureLevel))
                    {
                        // Everything is already created at this point, just transmit what has been done
                        var deviceInfo = new GraphicsDeviceInformation
                        {
                            Adapter = GraphicsAdapterFactory.Default,
                            GraphicsProfile = featureLevel,
                            PresentationParameters = new PresentationParameters(gameWindowiOS.ClientBounds.Width,
                                                                                gameWindowiOS.ClientBounds.Height,
                                                                                gameWindowiOS.NativeWindow)
                            {
                                // TODO: PDX-364: Transmit what was actually created
                                BackBufferFormat = preferredParameters.PreferredBackBufferFormat,
                                DepthStencilFormat = preferredParameters.PreferredDepthStencilFormat,
                            }
                        };

                        graphicsDeviceInfos.Add(deviceInfo);

                        // If the profile is supported, we are just using the first best one
                        break;
                    }
                }

                return graphicsDeviceInfos;
            }
            return base.FindBestDevices(preferredParameters);
        }
示例#6
0
        public override List<GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters preferredParameters)
        {
            var gameWindowiOS = gameWindow as GameWindowiOS;
            if (gameWindowiOS != null)
            {
                // Unlike Desktop and WinRT, the list of best devices are completely fixed in WP8 XAML
                // So we return a single element
                var deviceInfo = new GraphicsDeviceInformation
                    {
                        Adapter = GraphicsAdapterFactory.Default,
                        GraphicsProfile = GraphicsProfile.Level_9_3,
                        PresentationParameters = new PresentationParameters(gameWindowiOS.ClientBounds.Width,
                                                                            gameWindowiOS.ClientBounds.Height,
                                                                            gameWindowiOS.NativeWindow)
                            {
                                DepthStencilFormat = PixelFormat.D16_UNorm,
                            }
                    }; 

                return new List<GraphicsDeviceInformation>() { deviceInfo };
            }
            return base.FindBestDevices(preferredParameters);
        }
示例#7
0
 public override void DeviceChanged(GraphicsDevice currentDevice, GraphicsDeviceInformation deviceInformation)
 {
     // TODO: Check when it needs to be disabled on iOS (OpenGL)?
     // Force to resize the gameWindow
     //gameWindow.Resize(deviceInformation.PresentationParameters.BackBufferWidth, deviceInformation.PresentationParameters.BackBufferHeight);
 }
示例#8
0
        public virtual GraphicsDevice ChangeOrCreateDevice(GraphicsDevice currentDevice, GraphicsDeviceInformation deviceInformation)
        {
            if (currentDevice == null)
            {
                currentDevice = CreateDevice(deviceInformation);
            }
            else
            {
                RecreateDevice(currentDevice, deviceInformation);
            }

            DeviceChanged(currentDevice, deviceInformation);

            return(currentDevice);
        }
示例#9
0
 public virtual void DeviceChanged(GraphicsDevice currentDevice, GraphicsDeviceInformation deviceInformation)
 {
     // Force to resize the gameWindow
     gameWindow.Resize(deviceInformation.PresentationParameters.BackBufferWidth, deviceInformation.PresentationParameters.BackBufferHeight);
 }
示例#10
0
        public virtual GraphicsDevice CreateDevice(GraphicsDeviceInformation deviceInformation)
        {
            var graphicsDevice = GraphicsDevice.New(deviceInformation.Adapter, deviceInformation.DeviceCreationFlags, gameWindow.NativeWindow, deviceInformation.GraphicsProfile);
            graphicsDevice.Presenter = new SwapChainGraphicsPresenter(graphicsDevice, deviceInformation.PresentationParameters);

            return graphicsDevice;
        }
示例#11
0
        protected void AddDevice(DisplayMode mode,  GraphicsDeviceInformation deviceBaseInfo, GameGraphicsParameters preferredParameters, List<GraphicsDeviceInformation> graphicsDeviceInfos)
        {
            // TODO: Temporary woraround
            if (mode == null)
                mode = new DisplayMode(PixelFormat.R8G8B8A8_UNorm, 800, 480, new Rational(60, 1));

            var deviceInfo = deviceBaseInfo.Clone();

            deviceInfo.PresentationParameters.RefreshRate = mode.RefreshRate;

            if (preferredParameters.IsFullScreen)
            {
                deviceInfo.PresentationParameters.BackBufferFormat = mode.Format;
                deviceInfo.PresentationParameters.BackBufferWidth = mode.Width;
                deviceInfo.PresentationParameters.BackBufferHeight = mode.Height;
            }
            else
            {
                deviceInfo.PresentationParameters.BackBufferFormat = preferredParameters.PreferredBackBufferFormat;
                deviceInfo.PresentationParameters.BackBufferWidth = preferredParameters.PreferredBackBufferWidth;
                deviceInfo.PresentationParameters.BackBufferHeight = preferredParameters.PreferredBackBufferHeight;
            }

            // TODO: Handle multisampling 
            deviceInfo.PresentationParameters.DepthStencilFormat = preferredParameters.PreferredDepthStencilFormat;
            deviceInfo.PresentationParameters.MultiSampleCount = MSAALevel.None;

            if (!graphicsDeviceInfos.Contains(deviceInfo))
            {
                graphicsDeviceInfos.Add(deviceInfo);
            }
        }
示例#12
0
        private void CreateDevice(GraphicsDeviceInformation newInfo)
        {
            newInfo.PresentationParameters.IsFullScreen = isFullScreen;
            newInfo.PresentationParameters.PresentationInterval = SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate;
            newInfo.DeviceCreationFlags = DeviceCreationFlags;

            OnPreparingDeviceSettings(this, new PreparingDeviceSettingsEventArgs(newInfo));

            // this.ValidateGraphicsDeviceInformation(newInfo);

            bool deviceRecreate = GraphicsDevice != null;

            // Notify device is resetting (usually this should result in graphics resources being destroyed)
            if (deviceRecreate)
                OnDeviceResetting(this, EventArgs.Empty);

            // Create (or recreate) the graphics device
            GraphicsDevice = graphicsDeviceFactory.ChangeOrCreateDevice(GraphicsDevice, newInfo);

            // Notify device is reset (usually this should result in graphics resources being recreated/reloaded)
            if (deviceRecreate)
                OnDeviceReset(this, EventArgs.Empty);

            GraphicsDevice.ShaderProfile = ShaderProfile;

            // TODO HANDLE Device Resetting/Reset/Lost
            //GraphicsDevice.DeviceResetting += GraphicsDevice_DeviceResetting;
            //GraphicsDevice.DeviceReset += GraphicsDevice_DeviceReset;
            //GraphicsDevice.DeviceLost += GraphicsDevice_DeviceLost;
            if (!deviceRecreate)
                GraphicsDevice.Disposing += GraphicsDevice_Disposing;

            OnDeviceCreated(this, EventArgs.Empty);
        }
示例#13
0
 /// <summary>
 /// Determines whether this instance is compatible with the the specified new <see cref="GraphicsDeviceInformation"/>.
 /// </summary>
 /// <param name="newDeviceInfo">The new device info.</param>
 /// <returns><c>true</c> if this instance this instance is compatible with the the specified new <see cref="GraphicsDeviceInformation"/>; otherwise, <c>false</c>.</returns>
 protected virtual bool CanResetDevice(GraphicsDeviceInformation newDeviceInfo)
 {
     // By default, a reset is compatible when we stay under the same graphics profile.
     return GraphicsDevice.Features.Profile == newDeviceInfo.GraphicsProfile;
 }
示例#14
0
 /// <summary>
 /// Determines whether this instance is compatible with the the specified new <see cref="GraphicsDeviceInformation"/>.
 /// </summary>
 /// <param name="newDeviceInfo">The new device info.</param>
 /// <returns><c>true</c> if this instance this instance is compatible with the the specified new <see cref="GraphicsDeviceInformation"/>; otherwise, <c>false</c>.</returns>
 protected virtual bool CanResetDevice(GraphicsDeviceInformation newDeviceInfo)
 {
     // By default, a reset is compatible when we stay under the same graphics profile.
     return(GraphicsDevice.Features.Profile == newDeviceInfo.GraphicsProfile);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PreparingDeviceSettingsEventArgs" /> class.
 /// </summary>
 /// <param name="graphicsDeviceInformation">The graphics device information.</param>
 public PreparingDeviceSettingsEventArgs(GraphicsDeviceInformation graphicsDeviceInformation)
 {
     GraphicsDeviceInformation = graphicsDeviceInformation;
 }
示例#16
0
 public override void DeviceChanged(GraphicsDevice currentDevice, GraphicsDeviceInformation deviceInformation)
 {
     // TODO: Check when it needs to be disabled on iOS (OpenGL)?
     // Force to resize the gameWindow
     //gameWindow.Resize(deviceInformation.PresentationParameters.BackBufferWidth, deviceInformation.PresentationParameters.BackBufferHeight);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PreparingDeviceSettingsEventArgs" /> class.
 /// </summary>
 /// <param name="graphicsDeviceInformation">The graphics device information.</param>
 public PreparingDeviceSettingsEventArgs(GraphicsDeviceInformation graphicsDeviceInformation)
 {
     GraphicsDeviceInformation = graphicsDeviceInformation;
 }
示例#18
0
        public virtual List<GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters preferredParameters)
        {
            var graphicsDeviceInfos = new List<GraphicsDeviceInformation>();

            // Iterate on each adapter
            foreach (var graphicsAdapter in GraphicsAdapterFactory.Adapters)
            {
                // Skip adapeters that don't have graphics output
                if (graphicsAdapter.Outputs.Length == 0)
                {
                    continue;
                }

                var preferredGraphicsProfiles = preferredParameters.PreferredGraphicsProfile;

                // INTEL workaround: it seems Intel driver doesn't support properly feature level 9.x. Fallback to 10.
                if (graphicsAdapter.VendorId == 0x8086)
                    preferredGraphicsProfiles = preferredGraphicsProfiles.Select(x => x < GraphicsProfile.Level_10_0 ? GraphicsProfile.Level_10_0 : x).ToArray();

                // Iterate on each preferred graphics profile
                foreach (var featureLevel in preferredGraphicsProfiles)
                {
                    // Check if this profile is supported.
                    if (graphicsAdapter.IsProfileSupported(featureLevel))
                    {
                        var deviceInfo = new GraphicsDeviceInformation
                            {
                                Adapter = graphicsAdapter,
                                GraphicsProfile = featureLevel,
                                PresentationParameters =
                                    {
                                        MultiSampleCount = MSAALevel.None,
                                        IsFullScreen = preferredParameters.IsFullScreen,
                                        PreferredFullScreenOutputIndex = preferredParameters.PreferredFullScreenOutputIndex,
                                        PresentationInterval = preferredParameters.SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate,
                                        DeviceWindowHandle = MainWindow.NativeWindow,
                                    }
                            };

                        var preferredMode = new DisplayMode(preferredParameters.PreferredBackBufferFormat,
                            preferredParameters.PreferredBackBufferWidth,
                            preferredParameters.PreferredBackBufferHeight,
                            preferredParameters.PreferredRefreshRate);

                        // if we want to switch to fullscreen, try to find only needed output, otherwise check them all
                        if (preferredParameters.IsFullScreen)
                        {
                            if (preferredParameters.PreferredFullScreenOutputIndex < graphicsAdapter.Outputs.Length)
                            {
                                var output = graphicsAdapter.Outputs[preferredParameters.PreferredFullScreenOutputIndex];
                                var displayMode = output.FindClosestMatchingDisplayMode(preferredGraphicsProfiles, preferredMode);
                                AddDevice(displayMode, deviceInfo, preferredParameters, graphicsDeviceInfos);
                            }
                        }
                        else
                        {
                            AddDevice(preferredMode, deviceInfo, preferredParameters, graphicsDeviceInfos);
                        }

                        // If the profile is supported, we are just using the first best one
                        break;
                    }
                }
            }

            return graphicsDeviceInfos;
        }
示例#19
0
        public virtual List <GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters preferredParameters)
        {
            var graphicsDeviceInfos = new List <GraphicsDeviceInformation>();

            // Iterate on each adapter
            foreach (var graphicsAdapter in GraphicsAdapterFactory.Adapters)
            {
                // Skip adapeters that don't have graphics output
                if (graphicsAdapter.Outputs.Length == 0)
                {
                    continue;
                }

                var preferredGraphicsProfiles = preferredParameters.PreferredGraphicsProfile;

                // INTEL workaround: it seems Intel driver doesn't support properly feature level 9.x. Fallback to 10.
                if (graphicsAdapter.VendorId == 0x8086)
                {
                    preferredGraphicsProfiles = preferredGraphicsProfiles.Select(x => x < GraphicsProfile.Level_10_0 ? GraphicsProfile.Level_10_0 : x).ToArray();
                }

                // Iterate on each preferred graphics profile
                foreach (var featureLevel in preferredGraphicsProfiles)
                {
                    // Check if this profile is supported.
                    if (graphicsAdapter.IsProfileSupported(featureLevel))
                    {
                        var deviceInfo = new GraphicsDeviceInformation
                        {
                            Adapter                = graphicsAdapter,
                            GraphicsProfile        = featureLevel,
                            PresentationParameters =
                            {
                                MultiSampleCount = MSAALevel.None,
                                IsFullScreen     = preferredParameters.IsFullScreen,
                                PreferredFullScreenOutputIndex = preferredParameters.PreferredFullScreenOutputIndex,
                                PresentationInterval           = preferredParameters.SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate,
                                DeviceWindowHandle             = MainWindow.NativeWindow,
                                ColorSpace                     = preferredParameters.ColorSpace
                            }
                        };

                        var preferredMode = new DisplayMode(preferredParameters.PreferredBackBufferFormat,
                                                            preferredParameters.PreferredBackBufferWidth,
                                                            preferredParameters.PreferredBackBufferHeight,
                                                            preferredParameters.PreferredRefreshRate);

                        // if we want to switch to fullscreen, try to find only needed output, otherwise check them all
                        if (preferredParameters.IsFullScreen)
                        {
                            if (preferredParameters.PreferredFullScreenOutputIndex < graphicsAdapter.Outputs.Length)
                            {
                                var output      = graphicsAdapter.Outputs[preferredParameters.PreferredFullScreenOutputIndex];
                                var displayMode = output.FindClosestMatchingDisplayMode(preferredGraphicsProfiles, preferredMode);
                                AddDevice(displayMode, deviceInfo, preferredParameters, graphicsDeviceInfos);
                            }
                        }
                        else
                        {
                            AddDevice(preferredMode, deviceInfo, preferredParameters, graphicsDeviceInfos);
                        }

                        // If the profile is supported, we are just using the first best one
                        break;
                    }
                }
            }

            return(graphicsDeviceInfos);
        }
示例#20
0
 public virtual void RecreateDevice(GraphicsDevice currentDevice, GraphicsDeviceInformation deviceInformation)
 {
     currentDevice.Recreate(deviceInformation.Adapter ?? GraphicsAdapterFactory.Default, new[] { deviceInformation.GraphicsProfile }, deviceInformation.DeviceCreationFlags, gameWindow.NativeWindow);
 }
示例#21
0
 public virtual void RecreateDevice(GraphicsDevice currentDevice, GraphicsDeviceInformation deviceInformation)
 {
     currentDevice.ColorSpace = deviceInformation.PresentationParameters.ColorSpace;
     currentDevice.Recreate(deviceInformation.Adapter ?? GraphicsAdapterFactory.Default, new[] { deviceInformation.GraphicsProfile }, deviceInformation.DeviceCreationFlags, gameWindow.NativeWindow);
 }
示例#22
0
        public virtual GraphicsDevice ChangeOrCreateDevice(GraphicsDevice currentDevice, GraphicsDeviceInformation deviceInformation)
        {
            if (currentDevice == null)
            {
                currentDevice = CreateDevice(deviceInformation);
            }
            else
            {
                RecreateDevice(currentDevice, deviceInformation);
            }

            DeviceChanged(currentDevice, deviceInformation);

            return currentDevice;
        }
示例#23
0
 public virtual void DeviceChanged(GraphicsDevice currentDevice, GraphicsDeviceInformation deviceInformation)
 {
     // Force to resize the gameWindow
     gameWindow.Resize(deviceInformation.PresentationParameters.BackBufferWidth, deviceInformation.PresentationParameters.BackBufferHeight);
 }