From 0d659c6e742976dca426f344c3b7f064ee2b2a92 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Sun, 4 May 2008 16:25:00 +0000 Subject: [PATCH] Modified the SelectResolution to never fail, even if the specified resolution is not supported. In this case, it will return the current resolution. --- Source/OpenTK/Graphics/DisplayDevice.cs | 46 +++++++++++++++++++------ 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/Source/OpenTK/Graphics/DisplayDevice.cs b/Source/OpenTK/Graphics/DisplayDevice.cs index 047f2e42..eeda0124 100644 --- a/Source/OpenTK/Graphics/DisplayDevice.cs +++ b/Source/OpenTK/Graphics/DisplayDevice.cs @@ -144,19 +144,23 @@ namespace OpenTK.Graphics /// The refresh rate of the requested resolution in Herz. /// The requested DisplayResolution or null if the parameters cannot be met. /// - /// A parameter set to 0 will not be used in the search (e.g. if refreshRate is 0, any refresh rate will be considered valid). - /// This function generates garbage. + /// If a matching resolution is not found, this function will retry ignoring the specified refresh rate, + /// bits per pixel and resolution, in this order. If a matching resolution still doesn't exist, this function will + /// return the current resolution. + /// A parameter set to 0 or negative numbers will not be used in the search (e.g. if refreshRate is 0, + /// any refresh rate will be considered valid). + /// This function allocates memory. /// public DisplayResolution SelectResolution(int width, int height, int bitsPerPixel, float refreshRate) { - return available_resolutions.Find(delegate(DisplayResolution test) - { - return - ((width > 0 && width == test.Width) || width == 0) && - ((height > 0 && height == test.Height) || height == 0) && - ((bitsPerPixel > 0 && bitsPerPixel == test.BitsPerPixel) || bitsPerPixel == 0) && - ((refreshRate > 0 && System.Math.Abs(refreshRate - test.RefreshRate) < 1.0) || refreshRate == 0); - }); + DisplayResolution resolution = FindResolution(width, height, bitsPerPixel, refreshRate); + if (resolution == null) + resolution = FindResolution(width, height, bitsPerPixel, 0); + if (resolution == null) + resolution = FindResolution(width, height, 0, 0); + if (resolution == null) + return current_resolution; + return resolution; } #endregion @@ -208,7 +212,7 @@ namespace OpenTK.Graphics #endregion - #region public void ChangeResolution(DisplayResolution resolution) + #region public void ChangeResolution(int width, int height, int bitsPerPixel, float refreshRate) /// Changes the resolution of the DisplayDevice. /// The new width of the DisplayDevice. @@ -273,6 +277,26 @@ namespace OpenTK.Graphics #endregion + #region --- Private Methods --- + + #region DisplayResolution FindResolution(int width, int height, int bitsPerPixel, float refreshRate) + + DisplayResolution FindResolution(int width, int height, int bitsPerPixel, float refreshRate) + { + return available_resolutions.Find(delegate(DisplayResolution test) + { + return + ((width > 0 && width == test.Width) || width == 0) && + ((height > 0 && height == test.Height) || height == 0) && + ((bitsPerPixel > 0 && bitsPerPixel == test.BitsPerPixel) || bitsPerPixel == 0) && + ((refreshRate > 0 && System.Math.Abs(refreshRate - test.RefreshRate) < 1.0) || refreshRate == 0); + }); + } + + #endregion + + #endregion + #region --- Overrides --- #region public override string ToString()