#region --- License --- /* Copyright (c) 2006, 2007 Stefanos Apostolopoulos * See license.txt for license info */ #endregion #region --- Using directives --- using System; using System.Drawing; using System.Globalization; #endregion namespace OpenTK { using OpenTK.Graphics; /// Defines the display mode for a render window. public sealed class DisplayMode { #region --- Private Variables --- private int width, height; private ColorMode color_format, auxilliary_color_format; private int depthBits, stencilBits; private float refreshRate; private bool vsync; private bool fullscreen; private int buffers; private bool stereo; #endregion #region --- Constructors --- /// /// Constructs a new DisplayMode from the given DisplayMode. /// /// public DisplayMode(DisplayMode mode) : this(mode.ColorFormat, mode.Depth, mode.Stencil, mode.AuxilliaryColorFormat, mode.Buffers, mode.Stereo) { } /// Constructs a new DisplayMode with sensible default parameters. public DisplayMode() : this(Display.PrimaryDisplay.BitsPerPixel, 16, 0, 0, 2, false) { } /// Constructs a new DisplayMode with the specified parameters. /// The ColorMode of the color buffer. public DisplayMode(ColorMode color) : this(color, 16, 0, 0, 2, false) { } /// Constructs a new DisplayMode with the specified parameters. /// The ColorMode of the color buffer. /// The number of bits in the depth buffer. public DisplayMode(ColorMode color, int depth) : this(color, depth, 0, 0, 2, false) { } /// Constructs a new DisplayMode with the specified parameters. /// The ColorMode of the color buffer. /// The number of bits in the depth buffer. /// The number of bits in the stencil buffer. public DisplayMode(ColorMode color, int depth, int stencil) : this(color, depth, stencil, 0, 2, false) { } /// Constructs a new DisplayMode with the specified parameters. /// The ColorMode of the color buffer. /// The number of bits in the depth buffer. /// The number of bits in the stencil buffer. /// The ColorMode of the auxilliary buffer. public DisplayMode(ColorMode color, int depth, int stencil, ColorMode aux) : this(color, depth, stencil, aux, 2, false) { } /// Constructs a new DisplayMode with the specified parameters. /// The ColorMode of the color buffer. /// The number of bits in the depth buffer. /// The number of bits in the stencil buffer. /// The ColorMode of the auxilliary buffer. /// The number of render buffers. Typical values include one (single-), two (double-) or three (triple-buffering). public DisplayMode(ColorMode color, int depth, int stencil, ColorMode aux, int buffers) : this(color, depth, stencil, aux, buffers, false) { } /// Constructs a new DisplayMode with the specified parameters. /// The ColorMode of the color buffer. /// The number of bits in the depth buffer. /// The number of bits in the stencil buffer. /// The ColorMode of the auxilliary buffer. /// Set to true for a DisplayMode with stereographic capabilities. /// The number of render buffers. Typical values include one (single-), two (double-) or three (triple-buffering). public DisplayMode(ColorMode color, int depth, int stencil, ColorMode aux, int buffers, bool stereo) { this.ColorFormat = color; this.Depth = depth; this.Stencil = stencil; this.AuxilliaryColorFormat = aux; this.Buffers = buffers; this.Stereo = stereo; } #region Obsolete Constructors /// /// Constructs a new DisplayMode from the specified parameters. /// /// The Width of the DisplayMode, in pixels. /// The Height of the DisplayMode, in pixels. /// The ColorMode of the color buffer. /// The number of bits in the depth buffer. /// The number of bits in the stencil buffer. /// The number of bits in the auxilliary buffer. /// Set to true for a fullscreen DisplayMode. /// Set to true for a DisplayMode with stereographic capabilities. /// The number of render buffers. Typical values include one (single-), two (double-) or three (triple-buffering). /// Set to true to sync the updates to the screen refresh rate. /// The desired RefreshRate. Taken into account only for Fullscreen DisplayModes. [Obsolete] public DisplayMode(int width, int height, ColorMode color, int depth, int stencil, int aux, int buffers, bool fullscreen, bool stereo, bool vsync, float refresh) { this.Width = width; this.Height = height; this.Color = color; this.DepthBits = depth; this.StencilBits = stencil; this.AuxBits = aux; this.Buffers = buffers; this.Fullscreen = fullscreen; this.Stereo = stereo; this.Vsync = vsync; this.RefreshRate = refresh; } /// /// Constructs a new DisplayMode. /// /// The Width of the DisplayMode in pixels. /// The Height of the DisplayMode in pixels. [Obsolete] public DisplayMode(int width, int height) : this(width, height, Display.PrimaryDisplay.BitsPerPixel, 16, 0, 0, 0, false, false, false, 0.0f) { } /// /// Constructs a new DisplayMode. /// /// The Width of the DisplayMode in pixels. /// The Height of the DisplayMode in pixels. /// The ColorMode of the color buffer. [Obsolete] public DisplayMode(int width, int height, ColorMode color) : this(width, height, color, 16, 0, 0, 0, false, false, false, 0.0f) { } /// /// Constructs a new DisplayMode. /// /// The Width of the DisplayMode in pixels. /// The Height of the DisplayMode in pixels. /// The ColorMode of the color buffer. /// The number of bits in the depth buffer. [Obsolete] public DisplayMode(int width, int height, ColorMode color, int depth) : this(width, height, color, depth, 0, 0, 0, false, false, false, 0.0f) { } /// /// Constructs a new DisplayMode. /// /// The Width of the DisplayMode in pixels. /// The Height of the DisplayMode in pixels. /// The ColorMode of the color buffer. /// The number of bits in the depth buffer. /// True for a fullscreen DisplayMode, false otherwise. [Obsolete] public DisplayMode(int width, int height, ColorMode color, int depth, bool fullscreen) : this(width, height, color, depth, 0, 0, 0, fullscreen, false, false, 0.0f) { } #endregion #endregion #region --- Public Properties --- #region public int ColorFormat /// /// Gets an OpenTK.Graphics.ColorMode that describes the color format of this DisplayMode. /// public ColorMode ColorFormat { get { return color_format; } private set { color_format = value; } } #endregion #region public int AuxilliaryColorFormat /// /// Gets an OpenTK.Graphics.ColorMode that describes the color format of this DisplayMode. /// public ColorMode AuxilliaryColorFormat { get { return auxilliary_color_format; } private set { auxilliary_color_format = value; } } #endregion #region public int Depth /// /// Gets a System.Int32 that contains the bits per pixel for the depth buffer /// of this DisplayMode. /// public int Depth { get { return depthBits; } private set { depthBits = value; } } #endregion #region public int Stencil /// /// Gets a System.Int32 that contains the bits per pixel for the stencil buffer /// of this DisplayMode. /// public int Stencil { get { return stencilBits; } private set { stencilBits = value; } } #endregion #region public bool Stereo /// /// Gets a System.Boolean indicating whether this DisplayMode is stereoscopic. /// public bool Stereo { get { return this.stereo; } private set { this.stereo = value; } } #endregion #region public int Buffers /// /// Gets a System.Int32 containing the number of buffers associated with this /// DisplayMode. /// public int Buffers { get { return this.buffers; } private set { this.buffers = value; } } #endregion #region Obsolete Properties [Obsolete("Use GameWindow.Fullscreen instead.")] public bool Fullscreen { get { return this.fullscreen; } internal set { this.fullscreen = value; } } [Obsolete("Use GraphicsContext.VSync, GLControl.VSync or GameWindow.VSync instead.")] public bool Vsync { get { return this.vsync; } internal set { this.vsync = value; } } [Obsolete("Use OpenTK.Graphics.Display.RefreshRate instead.")] public float RefreshRate { get { return this.refreshRate; } private set { this.refreshRate = value; } } #region public ColorDepth Color [Obsolete("Use DisplayMode.ColorFormat instead.")] public ColorMode Color { get { return this.color_format; } internal set { this.color_format = value; } } #endregion #region public int Height /// /// Gets or sets the Height of the DisplayMode. Height is the vertical span measured in pixels. /// [Obsolete("Use GameWindow.Height or GLControl.Height instead.")] public int Height { get { return height; } set { if (value > 0 /* && (value < Screen[0].Height) */) { height = value; } } } #endregion #region public int Width /// /// Gets or sets the Width of the DisplayMode. Width is the horizontal span measured in pixels. /// [Obsolete("Use GameWindow.Width or GLControl.Width instead.")] public int Width { get { return width; } set { if (value > 0) { width = value; } } } #endregion [Obsolete("Use DisplayMode.Depth instead.")] public int DepthBits { get { return this.depthBits; } internal set { this.depthBits = value; } } [Obsolete("Use DisplayMode.Stencil instead.")] public int StencilBits { get { return this.stencilBits; } internal set { this.stencilBits = value; } } [Obsolete("Use DisplayMode.AuxilliaryColorFormat instead.")] public int AuxBits { get { return this.AuxilliaryColorFormat.BitsPerPixel; } internal set { this.AuxilliaryColorFormat = value; } } #endregion #endregion #region --- Overrides --- /// /// Describes this DisplayMode instance. /// /// Returns a System.String that describes this DisplayMode instance. public override string ToString() { return string.Format("Display Mode: {0}, depth: {1}, stencil {2}, aux {3} refresh {4}Hz", Color.ToString(), DepthBits, StencilBits, AuxBits, RefreshRate ); } #endregion } public class DisplayModeMatchOptions { } }