Beispiel #1
0
        internal override DisplayModeCollection GetDisplayModes()
        {
            if (supportedDisplayModes == null)
            {
                List <DisplayMode>  modes  = new List <DisplayMode>(new DisplayMode[] { GetCurrentDisplayMode(), });
                SDL.SDL_DisplayMode filler = new SDL.SDL_DisplayMode();
                int numModes = SDL.SDL_GetNumDisplayModes(0);
                for (int i = 0; i < numModes; i += 1)
                {
                    SDL.SDL_GetDisplayMode(0, i, out filler);

                    // Check for dupes caused by varying refresh rates.
                    bool dupe = false;
                    foreach (DisplayMode mode in modes)
                    {
                        if (filler.w == mode.Width && filler.h == mode.Height)
                        {
                            dupe = true;
                        }
                    }
                    if (!dupe)
                    {
                        modes.Add(
                            new DisplayMode(
                                filler.w,
                                filler.h,
                                SurfaceFormat.Color                                 // FIXME: Assumption!
                                )
                            );
                    }
                }
                supportedDisplayModes = new DisplayModeCollection(modes);
            }
            return(supportedDisplayModes);
        }
Beispiel #2
0
        private void INTERNAL_GenerateDisplayModes()
        {
            List <DisplayMode> modes = new List <DisplayMode>();

            SDL.SDL_DisplayMode filler = new SDL.SDL_DisplayMode();
            int numModes = SDL.SDL_GetNumDisplayModes(displayIndex);

            for (int i = 0; i < numModes; i += 1)
            {
                SDL.SDL_GetDisplayMode(displayIndex, i, out filler);

                // Check for dupes caused by varying refresh rates.
                bool dupe = false;
                foreach (DisplayMode mode in modes)
                {
                    if (filler.w == mode.Width && filler.h == mode.Height)
                    {
                        dupe = true;
                    }
                }
                if (!dupe)
                {
                    modes.Add(
                        new DisplayMode(
                            filler.w,
                            filler.h,
                            SurfaceFormat.Color                             // FIXME: Assumption!
                            )
                        );
                }
            }
            supportedDisplayModes = new DisplayModeCollection(modes);
        }
Beispiel #3
0
        private void ApplyResolutionSettings()
        {
            if (!_FullScreen)
            {
                if (_Width <= displayModeWidth && _Height <= displayModeHeight)
                {
                    _Device.PreferredBackBufferWidth  = _Width;
                    _Device.PreferredBackBufferHeight = _Height;
                    _Device.IsFullScreen = _FullScreen;
                    _Device.ApplyChanges();
                }
            }
            else
            {
                // If we are using full screen mode, we should check to make sure that the display
                // adapter can handle the video mode we are trying to set.  To do this, we will
                // iterate through the display modes supported by the adapter and check them against
                // the mode we want to set.
                DisplayModeCollection collection = GraphicsAdapter.DefaultAdapter.SupportedDisplayModes;
                if (GraphicsAdapter.DefaultAdapter.SupportedDisplayModes.Any(dm => (dm.Width == _Width) && (dm.Height == _Height)))
                {
                    _Device.PreferredBackBufferWidth  = _Width;
                    _Device.PreferredBackBufferHeight = _Height;
                    _Device.IsFullScreen = _FullScreen;
                    _Device.ApplyChanges();
                }
            }

            _Width  = _Device.PreferredBackBufferWidth;
            _Height = _Device.PreferredBackBufferHeight;
        }
Beispiel #4
0
        DisplayMode FindSupportedMode()
        {
            DisplayModeCollection supportedDisplayModes = d3d.Adapters[0].GetDisplayModes(Format.X8R8G8B8);
            DisplayMode           mode = supportedDisplayModes[ModeIndex];

            return(mode);
        }
Beispiel #5
0
        public void Load(ControlScene scene)
        {
            _labelFullScreen = new Label("Full screen", new Vector2(Program.Game.Resolution.X / 2.0f, Program.Game.Resolution.Y / 2.0f),
                                         Program.Game.Font1);

            _activeFullScreen = new RadioButton(Program.Game.IsFullScreen, Program.Game.Galka, Program.Game.Ramka, Program.Game.Font1,
                                                new Rectangle(Program.Game.Resolution.X / 2 + (int)Program.Game.Font1.MeasureString("Full screen").X + 16,
                                                              Program.Game.Resolution.Y / 2 - 16, 32, 32));
            _scene     = scene;
            _colection = Program.Game.GraphicsDevice.Adapter.SupportedDisplayModes;
            _disp      = _colection.ToList();
            _displayMode.Clear();
            while (_disp[0].Width != 800 || _disp[0].Height != 600)
            {
                _disp.RemoveAt(0);
            }
            for (var i = 0; i < _disp.Count; i++)
            {
                var    j   = i;
                var    a   = _disp[i].Width.ToString(CultureInfo.CurrentCulture) + "x" + _disp[i].Height;
                Button but = new Button(Program.Game.Button, Program.Game.Font1, new Rectangle(200, Program.Game.Resolution.Y / 2 + 20 * i, 200, 20), a);
                but.OnClicked += (_, _a) =>
                {
                    Console.WriteLine(_displayMode[j].Text);
                    Console.WriteLine(_disp[j].ToString());
                    Program.Game.DisplayMode = _disp[j];
                    Load(_scene);
                };
                _displayMode.Add(but);
            }
        }
        public override ScreenMode[] EnumScreenModes()
        {
            List <ScreenMode> modes = new List <ScreenMode>();

            foreach (var fmt in probeScreenFormats)
            {
                DisplayModeCollection dxmodes = mDirect3Dobject.Adapters[0].GetDisplayModes(fmt);
                ConvertDisplayModesToScreenModes(modes, dxmodes);
            }

            return(modes.ToArray());
        }
Beispiel #7
0
        private void adapterComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            int nSelectedAdapter           = adapterComboBox.SelectedIndex;
            AdapterListCollection adapList = Microsoft.DirectX.Direct3D.Manager.Adapters;

            DisplayModeCollection disMods = adapList[nSelectedAdapter].SupportedDisplayModes;

            string[] strResolutions = new string[disMods.Count];

            m_nHeight        = new int[disMods.Count];
            m_nWidth         = new int[disMods.Count];
            m_nDisplayFormat = new int[disMods.Count];

            IEnumerator disModEnum   = (IEnumerator)disMods.GetEnumerator();
            int         i            = 0;
            int         nSelected    = 0;
            int         nSavedWidth  = 0;
            int         nSavedHeight = 0;
            int         nSavedFormat = 0;

            try
            {
                RegistryKey adapKey = Registry.CurrentUser.OpenSubKey("Software\\netPongClient\\Adapter");
                if (adapKey != null)
                {
                    nSavedWidth  = (int)adapKey.GetValue("Width", 0);
                    nSavedHeight = (int)adapKey.GetValue("Height", 0);
                    nSavedFormat = (int)adapKey.GetValue("Format", 0);
                }
            }
            catch (Exception)
            {
            }

            while (disModEnum.MoveNext())
            {
                DisplayMode disMod = ((DisplayMode)disModEnum.Current);
                if ((nSavedWidth == disMod.Width) && (nSavedHeight == disMod.Height) && (nSavedFormat == (int)disMod.Format))
                {
                    nSelected = i;
                }

                m_nHeight[i]        = disMod.Height;
                m_nWidth[i]         = disMod.Width;
                m_nDisplayFormat[i] = (int)disMod.Format;
                strResolutions[i]   = disMod.Width + " x " + disMod.Height + " " + disMod.Format.ToString() + " ( " + disMod.RefreshRate + " Hz )";
                i++;
            }

            resolutionComboBox.Items.Clear();
            resolutionComboBox.Items.AddRange(strResolutions);
            resolutionComboBox.SelectedIndex = nSelected;
        }
Beispiel #8
0
        //
        // GetGraphicsAdapters
        //

        private static GraphicsAdapter[] GetGraphicsAdaptersImpl()
        {
            var bounds    = GameRunner.Singleton.ClientBounds;
            var modesList = new List <DisplayMode>();
            var theMode   = new DisplayMode(bounds.Width, bounds.Height, SurfaceFormat.Color);

            modesList.Add(theMode);
            var modesCollection = new DisplayModeCollection(modesList);
            var name            = "Android Surface";
            var theAdapter      = new GraphicsAdapter(modesCollection, name, name);

            return(new GraphicsAdapter[] { (GraphicsAdapter)(object)theAdapter });
        }
Beispiel #9
0
        public List <Settings.Resolution> GetResolutions()
        {
            List <Settings.Resolution> result = new List <Settings.Resolution>();
            DisplayModeCollection      dmc    = GraphicsAdapter.DefaultAdapter.SupportedDisplayModes;

            foreach (DisplayMode dm in dmc)
            {
                Settings.Resolution resolution = new Settings.Resolution(dm.Width, dm.Height);
                if (!result.Contains(resolution) && resolution.Width >= 800 && resolution.Height >= 600)
                {
                    result.Add(resolution);
                }
            }

            return(result);
        }
Beispiel #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="D3D10GraphicsAdapter"/> class.
        /// </summary>
        /// <param name="graphicsDevice">The graphics device.</param>
        /// <param name="factory">The DXGI factory.</param>
        /// <param name="adapterIndex">Index of the adapter.</param>
        internal D3D10GraphicsAdapter(D3D.Device graphicsDevice, DXGI.Factory factory, int adapterIndex)
        {
            _graphicsDevice = graphicsDevice;
            _adapterIndex   = adapterIndex;

            List <DisplayMode> modes = new List <DisplayMode>();

            DXGI.Adapter adapter = factory.GetAdapter(adapterIndex);
            if (adapter != null)
            {
                DXGI.AdapterDescription adDesc = adapter.Description;
                _desc        = adDesc.Description;
                _devId       = adDesc.DeviceId;
                _rev         = adDesc.Revision;
                _subsystemId = adDesc.SubsystemId;
                _vendorId    = adDesc.VendorId;

                DXGI.Output output = adapter.GetOutput(0);
                if (output != null)
                {
                    foreach (SurfaceFormat format in Enum.GetValues(typeof(SurfaceFormat)))
                    {
                        try {
                            System.Collections.ObjectModel.ReadOnlyCollection <DXGI.ModeDescription> modeList = output.GetDisplayModeList(D3D10Helper.ToD3DSurfaceFormat(format), 0);
                            if (modeList == null)
                            {
                                continue;
                            }
                            foreach (DXGI.ModeDescription modeDesc in modeList)
                            {
                                DisplayMode displayMode = new DisplayMode(modeDesc.Width, modeDesc.Height, format);
                                if (!modes.Contains(displayMode))
                                {
                                    modes.Add(displayMode);
                                }
                            }
                        } catch (Exception e) {
                            String s = e.StackTrace;
                            continue;
                        }
                    }
                    _displayModes = new DisplayModeCollection(modes);
                    output.Dispose();
                }
                adapter.Dispose();
            }
        }
Beispiel #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XNAGraphicsAdapter"/> class.
        /// </summary>
        /// <param name="graphicsDevice">The graphics device.</param>
        /// <param name="adapter">The adapter.</param>
        /// <param name="adapterIndex">Index of the adapter.</param>
        internal XNAGraphicsAdapter(XFG.GraphicsDevice graphicsDevice, XFG.GraphicsAdapter adapter, int adapterIndex)
        {
            _graphicsDevice = graphicsDevice;
            _adapter        = adapter;
            _adapterIndex   = adapterIndex;

            List <DisplayMode> list = new List <DisplayMode>();

            foreach (XFG.DisplayMode mode in adapter.SupportedDisplayModes)
            {
                DisplayMode display = new DisplayMode(mode.Width, mode.Height, XNAHelper.FromXNASurfaceFormat(mode.Format));
                if (list.Contains(display))
                {
                    list.Add(display);
                }
            }
            _displayModes = new DisplayModeCollection(list);

            _supportedTextureFormats = new List <XFG.SurfaceFormat>(new XFG.SurfaceFormat[] {
                XFG.SurfaceFormat.Color, XFG.SurfaceFormat.Bgr565, XFG.SurfaceFormat.Bgra5551,
                XFG.SurfaceFormat.Bgra4444, XFG.SurfaceFormat.NormalizedByte2, XFG.SurfaceFormat.NormalizedByte4,
                XFG.SurfaceFormat.Dxt1, XFG.SurfaceFormat.Dxt3, XFG.SurfaceFormat.Dxt5
            });

            if (graphicsDevice.GraphicsProfile == XFG.GraphicsProfile.HiDef)
            {
                _supportedVertexTextureFormats = new List <XFG.SurfaceFormat>(new XFG.SurfaceFormat[] {
                    XFG.SurfaceFormat.Single, XFG.SurfaceFormat.Vector4, XFG.SurfaceFormat.Vector2,
                    XFG.SurfaceFormat.HalfVector2, XFG.SurfaceFormat.HalfVector4, XFG.SurfaceFormat.HalfSingle
                });

                _supportedTextureFormats.AddRange(new XFG.SurfaceFormat[] {
                    XFG.SurfaceFormat.Alpha8, XFG.SurfaceFormat.Rg32, XFG.SurfaceFormat.Rgba64,
                    XFG.SurfaceFormat.Rgba1010102, XFG.SurfaceFormat.Single, XFG.SurfaceFormat.Vector2,
                    XFG.SurfaceFormat.Vector4, XFG.SurfaceFormat.HalfSingle, XFG.SurfaceFormat.HalfVector2,
                    XFG.SurfaceFormat.HalfVector4
                });
            }
        }
Beispiel #12
0
        public override ScreenMode[] EnumScreenModes()
        {
            List <ScreenMode> modes = new List <ScreenMode>();

            DisplayModeCollection dxmodes = Direct3D.Manager.Adapters[0].SupportedDisplayModes;

            foreach (DisplayMode mode in dxmodes)
            {
                int bits;

                switch (mode.Format)
                {
                case Format.A8B8G8R8:
                case Format.X8B8G8R8:
                case Format.X8R8G8B8:
                case Format.A8R8G8B8:
                    bits = 32;
                    break;

                case Format.R8G8B8:
                    bits = 24;
                    break;

                case Format.R5G6B5:
                case Format.X4R4G4B4:
                case Format.X1R5G5B5:
                    bits = 16;
                    break;

                default:
                    continue;
                }

                modes.Add(new ScreenMode(mode.Width, mode.Height, bits));
            }

            return(modes.ToArray());
        }
        private void SelectBestDisplayMode(PresentParameters present, int bpp)
        {
            Format fmt = GetDisplayModeTrialPixelFormat(bpp);

            DisplayModeCollection modes = mDirect3Dobject.Adapters[0].GetDisplayModes(fmt);

            DisplayMode selected = new DisplayMode();
            int         diff     = 0;

            foreach (DisplayMode mode in modes)
            {
                if (mode.Width < present.BackBufferWidth)
                {
                    continue;
                }

                if (mode.Height < present.BackBufferHeight)
                {
                    continue;
                }

                int thisDiff = Math.Abs(present.BackBufferWidth - mode.Width)
                               + Math.Abs(present.BackBufferHeight - mode.Height);

                int bits = 0;

                switch (mode.Format)
                {
                case Format.A8B8G8R8:
                case Format.X8B8G8R8:
                    thisDiff += 10;
                    goto case Format.X8R8G8B8;

                case Format.X8R8G8B8:
                case Format.A8R8G8B8:
                    bits = 32;
                    break;

                case Format.R5G6B5:
                case Format.X4R4G4B4:
                case Format.X1R5G5B5:
                    bits = 16;
                    break;

                default:
                    System.Diagnostics.Debug.Print("Unknown backbuffer format {0}.", mode.Format);
                    continue;
                }

                thisDiff += Math.Abs(bits - bpp);

                // first mode by default, or any mode which is a better match.
                if (selected.Height == 0 || thisDiff < diff)
                {
                    selected = mode;
                    diff     = thisDiff;
                }
            }


            present.BackBufferFormat = selected.Format;
            present.BackBufferWidth  = selected.Width;
            present.BackBufferHeight = selected.Height;
            //present.FullScreenRefreshRateInHz = selected.RefreshRate;
        }
Beispiel #14
0
        private void ReloadDisplayOptions()
        {
            bool applyChanges = false;

            DisplayModeCollection displayModes = Graphics.GraphicsDevice.Adapter.SupportedDisplayModes;

            // Windowed/Borderless/Fullscreen
            if (CVars.Get <bool>("display_fullscreen"))
            {
                if (!Graphics.IsFullScreen)
                {
                    if (CVars.Get <int>("display_fullscreen_width") < 0 || CVars.Get <int>("display_fullscreen_height") < 0)
                    {
                        CVars.Get <int>("display_fullscreen_width")  = Graphics.GraphicsDevice.Adapter.CurrentDisplayMode.Width;
                        CVars.Get <int>("display_fullscreen_height") = Graphics.GraphicsDevice.Adapter.CurrentDisplayMode.Height;
                        CVars.Save();
                    }

                    Graphics.PreferredBackBufferWidth  = CVars.Get <int>("display_fullscreen_width");
                    Graphics.PreferredBackBufferHeight = CVars.Get <int>("display_fullscreen_height");

                    Graphics.IsFullScreen       = true;
                    Graphics.HardwareModeSwitch = true;
                    applyChanges = true;
                }

                CVars.Get <bool>("display_borderless") = false;
                CVars.Get <bool>("display_windowed")   = false;
                CVars.Save();
            }
            else if (CVars.Get <bool>("display_borderless"))
            {
                if (!Graphics.IsFullScreen)
                {
                    Graphics.IsFullScreen       = true;
                    Graphics.HardwareModeSwitch = false;
                    applyChanges = true;
                }

                CVars.Get <bool>("display_windowed") = false;
                CVars.Save();
            }
            else
            {
                if (Graphics.IsFullScreen)
                {
                    Graphics.IsFullScreen = false;
                }
                Graphics.HardwareModeSwitch = false;
                applyChanges = true;

                CVars.Get <bool>("display_windowed") = true;
                CVars.Save();
            }

            // V-sync
            if (Graphics.SynchronizeWithVerticalRetrace
                != CVars.Get <bool>("display_vsync"))
            {
                Graphics.SynchronizeWithVerticalRetrace = CVars.Get <bool>("display_vsync");
                applyChanges = true;
            }

            if (applyChanges)
            {
                Graphics.ApplyChanges();
            }
        }