#region --- License --- /* Licensed under the MIT/X11 license. * Copyright (c) 2006-2008 the OpenTK Team. * This notice may not be removed from any source distribution. * See license.txt for licensing detailed licensing details. */ #endregion using System; namespace OpenTK.Graphics { /// Defines the format for graphics operations. public class GraphicsMode : IEquatable { static GraphicsMode defaultMode; /// Constructs a new GraphicsMode with the specified parameters. /// Platform specific context index. /// The ColorFormat of the color buffer. /// The number of bits in the depth buffer. /// The number of bits in the stencil buffer. /// The number of render buffers. Typical values include one (single-), two (double-) or three (triple-buffering). internal GraphicsMode(IntPtr? index, ColorFormat color, int depth, int stencil, int buffers) { if (depth < 0) throw new ArgumentOutOfRangeException("depth", "Must be greater than, or equal to zero."); if (stencil < 0) throw new ArgumentOutOfRangeException("stencil", "Must be greater than, or equal to zero."); if (buffers <= 0) throw new ArgumentOutOfRangeException("buffers", "Must be greater than zero."); Index = index; ColorFormat = color; Depth = depth; Stencil = stencil; Buffers = buffers; } /// Gets a nullable value, indicating the platform-specific index for this GraphicsMode. public IntPtr? Index; // The id of the pixel format or visual. /// The OpenTK.Graphics.ColorFormat that describes the color format for this GraphicsFormat. public ColorFormat ColorFormat; /// The bits per pixel for the depth buffer for this GraphicsFormat. public int Depth; /// The bits per pixel for the stencil buffer of this GraphicsFormat. public int Stencil; /// The number of buffers associated with this DisplayMode. public int Buffers; /// Returns an OpenTK.GraphicsFormat compatible with the underlying platform. public static GraphicsMode Default { get { if (defaultMode == null) { Debug.Print( "Creating default GraphicsMode ({0}, {1}, {2}, {3}).", DisplayDevice.Default.BitsPerPixel, 24, 0, 2 ); defaultMode = new GraphicsMode( null, DisplayDevice.Default.BitsPerPixel, 24, 0, 2 ); } return defaultMode; } } /// Returns a System.String describing the current GraphicsFormat. /// System.String describing the current GraphicsFormat. public override string ToString() { return String.Format("Index: {0}, Color: {1}, Depth: {2}, Stencil: {3}, Buffers: {4}", Index, ColorFormat, Depth, Stencil, Buffers); } /// Returns the hashcode for this instance. /// A hashcode for this instance. public override int GetHashCode() { return Index.GetHashCode(); } /// Indicates whether obj is equal to this instance. /// An object instance to compare for equality. /// True, if obj equals this instance; false otherwise. public override bool Equals(object obj) { return (obj is GraphicsMode) && Equals((GraphicsMode)obj); } /// Indicates whether other represents the same mode as this instance. /// The GraphicsMode to compare to. /// True, if other is equal to this instance; false otherwise. public bool Equals(GraphicsMode other) { return Index.HasValue && Index == other.Index; } } }