diff --git a/Source/OpenTK/ColorMode.cs b/Source/OpenTK/ColorMode.cs
index e69715ed..69014eda 100644
--- a/Source/OpenTK/ColorMode.cs
+++ b/Source/OpenTK/ColorMode.cs
@@ -5,7 +5,6 @@
#endregion
using System;
-using System.Drawing;
using System.Globalization;
namespace OpenTK
@@ -15,7 +14,7 @@ namespace OpenTK
/// A ColorMode contains Red, Green, Blue and Alpha components that descibe
/// the allocated bits per pixel for the corresponding color.
///
- public class ColorMode
+ public sealed class ColorMode
{
byte red, green, blue, alpha;
bool isIndexed = false;
@@ -29,6 +28,8 @@ namespace OpenTK
/// The bits per pixel sum for the Red, Green, Blue and Alpha color channels.
public ColorMode(int bpp)
{
+ if (bpp < 0)
+ throw new ArgumentOutOfRangeException("bpp", "Must be greater or equal to zero.");
Red = Green = Blue = Alpha = 0;
BitsPerPixel = bpp;
@@ -77,6 +78,8 @@ namespace OpenTK
/// Bits per pixel for the Alpha color channel.
public ColorMode(int red, int green, int blue, int alpha)
{
+ if (red < 0 || green < 0 || blue < 0 || alpha < 0)
+ throw new ArgumentOutOfRangeException("Arguments must be greater or equal to zero.");
Red = (byte)red;
Green = (byte)green;
Blue = (byte)blue;
@@ -105,6 +108,25 @@ namespace OpenTK
#endregion
+ #region --- Operator Overloads ---
+
+ ///
+ /// Converts the specified bpp into a new ColorMode.
+ ///
+ /// The bits per pixel to convert.
+ /// A ColorMode with the specified bits per pixel.
+ public static implicit operator ColorMode(int bpp)
+ {
+ return new ColorMode(bpp);
+ }
+
+ //public static implicit operator int(ColorMode mode)
+ //{
+ // return mode.BitsPerPixel;
+ //}
+
+ #endregion
+
#region --- Overrides ---
public override bool Equals(object obj)
diff --git a/Source/OpenTK/DisplayMode.cs b/Source/OpenTK/DisplayMode.cs
index 184b0241..65ec6249 100644
--- a/Source/OpenTK/DisplayMode.cs
+++ b/Source/OpenTK/DisplayMode.cs
@@ -14,14 +14,17 @@ using System.Globalization;
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;
+ private ColorMode color_format, auxilliary_color_format;
- private int depthBits, stencilBits, auxBits;
+ private int depthBits, stencilBits;
private float refreshRate;
private bool vsync;
@@ -33,12 +36,73 @@ namespace OpenTK
#region --- Constructors ---
+ ///
+ /// Constructs a new DisplayMode from the given DisplayMode.
+ ///
+ ///
public DisplayMode(DisplayMode mode)
- : this(mode.Width, mode.Height, mode.Color, mode.DepthBits, mode.StencilBits, mode.AuxBits, mode.Buffers,
- mode.Fullscreen, mode.Stereo, mode.Vsync, mode.RefreshRate)
+ : 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.
///
@@ -53,6 +117,7 @@ namespace OpenTK
/// 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)
{
@@ -69,63 +134,14 @@ namespace OpenTK
this.RefreshRate = refresh;
}
-
- ///
- /// Constructs a new DisplayMode from the specified parameters.
- ///
- /// The Width of the DisplayMode, in pixels.
- /// The Height of the DisplayMode, in pixels.
- /// The number of bits in 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.
- public DisplayMode(int width, int height, int 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 = new ColorMode(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 with default values.
- ///
- public DisplayMode()
- : this(0, 0, new ColorMode(32), 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.
+ [Obsolete]
public DisplayMode(int width, int height)
- : this(width, height, new ColorMode(32), 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 number of bits in the color buffer.
- public DisplayMode(int width, int height, int color)
- : this(width, height, new ColorMode(color), 16, 0, 0, 0, false, false, false, 0.0f)
+ : this(width, height, Display.PrimaryDisplay.BitsPerPixel, 16, 0, 0, 0, false, false, false, 0.0f)
{
}
@@ -135,23 +151,12 @@ namespace OpenTK
/// 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 number of bits in the color buffer.
- /// The number of bits in the depth buffer.
- public DisplayMode(int width, int height, int color, int depth)
- : this(width, height, new ColorMode(color), depth, 0, 0, 0, false, false, false, 0.0f)
- {
- }
-
///
/// Constructs a new DisplayMode.
///
@@ -159,24 +164,12 @@ namespace OpenTK
/// 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 number of bits in the color buffer.
- /// The number of bits in the depth buffer.
- /// True for a fullscreen DisplayMode, false otherwise.
- public DisplayMode(int width, int height, int color, int depth, bool fullscreen)
- : this(width, height, color, depth, 0, 0, 0, fullscreen, false, false, 0.0f)
- {
- }
-
///
/// Constructs a new DisplayMode.
///
@@ -185,6 +178,7 @@ namespace OpenTK
/// 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)
{
@@ -192,8 +186,125 @@ namespace OpenTK
#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
///
@@ -234,77 +345,49 @@ namespace OpenTK
#endregion
- #region public ColorDepth Color
-
- public ColorMode Color
- {
- get { return this.color; }
- set { this.color = value; }
- }
-
- #endregion
-
+ [Obsolete("Use DisplayMode.Depth instead.")]
public int DepthBits
{
get { return this.depthBits; }
- set { this.depthBits = value; }
+ internal set { this.depthBits = value; }
}
+ [Obsolete("Use DisplayMode.Stencil instead.")]
public int StencilBits
{
get { return this.stencilBits; }
- set { this.stencilBits = value; }
+ internal set { this.stencilBits = value; }
}
+ [Obsolete("Use DisplayMode.AuxilliaryColorFormat instead.")]
public int AuxBits
{
- get { return this.auxBits; }
- set { this.auxBits = value; }
- }
-
- public bool Stereo
- {
- get { return this.stereo; }
- set { this.stereo = value; }
- }
-
- public bool Fullscreen
- {
- get { return this.fullscreen; }
- set { this.fullscreen = value; }
- }
-
- public bool Vsync
- {
- get { return this.vsync; }
- set { this.vsync = value; }
- }
-
- public int Buffers
- {
- get { return this.buffers; }
- set { this.buffers = value; }
- }
-
- public float RefreshRate
- {
- get { return this.refreshRate; }
- set { this.refreshRate = value; }
+ 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(
- CultureInfo.CurrentCulture,
- "{0}x{1}, rgba: {2}, depth: {3}, refresh {4}Hz",
- Width, Height,
+ 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 { }
diff --git a/Source/OpenTK/Graphics/Display.cs b/Source/OpenTK/Graphics/Display.cs
index 35508392..fc13d3c9 100644
--- a/Source/OpenTK/Graphics/Display.cs
+++ b/Source/OpenTK/Graphics/Display.cs
@@ -71,7 +71,7 @@ namespace OpenTK.Graphics
public int BitsPerPixel { get { return bits_per_pixel; } }
/// Gets a System.Boolean that indicates whether this Display is the primary Display in systems with multiple Displays.
- public bool Primary { get { return primary; } }
+ public bool IsPrimary { get { return primary; } }
///
/// Gets an array of OpenTK.Display objects, which describe all available display devices.