2008-02-28 16:26:51 +01:00
|
|
|
|
#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;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
2008-03-23 13:55:33 +01:00
|
|
|
|
using System.Diagnostics;
|
2008-02-28 16:26:51 +01:00
|
|
|
|
|
|
|
|
|
namespace OpenTK.Graphics
|
|
|
|
|
{
|
|
|
|
|
/// <summary>Defines the format for graphics operations.</summary>
|
|
|
|
|
public class GraphicsMode
|
|
|
|
|
{
|
2008-03-03 13:44:56 +01:00
|
|
|
|
ColorFormat color_format, accumulator_format;
|
2008-02-28 16:26:51 +01:00
|
|
|
|
int depth, stencil, buffers, samples;
|
|
|
|
|
bool stereo;
|
2008-03-03 13:44:56 +01:00
|
|
|
|
IntPtr index; // The id of the pixel format or visual.
|
|
|
|
|
|
2008-03-23 13:51:41 +01:00
|
|
|
|
static GraphicsMode defaultMode;
|
2008-03-03 13:44:56 +01:00
|
|
|
|
static IGraphicsMode implementation;
|
|
|
|
|
static object mode_selection_lock = new object();
|
2008-02-28 16:26:51 +01:00
|
|
|
|
|
|
|
|
|
#region --- Constructors ---
|
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
#region static GraphicsMode()
|
|
|
|
|
|
|
|
|
|
static GraphicsMode()
|
|
|
|
|
{
|
|
|
|
|
if (Configuration.RunningOnWindows)
|
|
|
|
|
implementation = new OpenTK.Platform.Windows.WinGraphicsMode();
|
|
|
|
|
else if (Configuration.RunningOnX11)
|
|
|
|
|
implementation = new OpenTK.Platform.X11.X11GraphicsMode();
|
|
|
|
|
else
|
|
|
|
|
throw new PlatformNotSupportedException("Please, refer to http://www.opentk.com for more information.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region internal GraphicsMode(GraphicsMode mode)
|
2008-02-28 16:26:51 +01:00
|
|
|
|
|
|
|
|
|
internal GraphicsMode(GraphicsMode mode)
|
2008-03-03 13:44:56 +01:00
|
|
|
|
: this(mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo) { }
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region internal GraphicsMode((IntPtr index, ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo)
|
|
|
|
|
|
|
|
|
|
internal GraphicsMode(IntPtr index, ColorFormat color, int depth, int stencil, int samples, ColorFormat accum,
|
|
|
|
|
int buffers, bool stereo)
|
|
|
|
|
{
|
|
|
|
|
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.");
|
|
|
|
|
if (samples < 0) throw new ArgumentOutOfRangeException("samples", "Must be greater than, or equal to zero.");
|
|
|
|
|
|
|
|
|
|
// This method will search for the closest
|
|
|
|
|
|
|
|
|
|
if (index == IntPtr.Zero)
|
|
|
|
|
{
|
|
|
|
|
GraphicsMode mode;
|
|
|
|
|
lock (mode_selection_lock)
|
|
|
|
|
{
|
|
|
|
|
mode = implementation.SelectGraphicsMode(color, depth, stencil, samples, accum, buffers, stereo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Index = mode.Index;
|
|
|
|
|
this.ColorFormat = mode.ColorFormat;
|
|
|
|
|
this.Depth = mode.Depth;
|
|
|
|
|
this.Stencil = mode.Stencil;
|
|
|
|
|
this.Samples = mode.Samples;
|
|
|
|
|
this.AccumulatorFormat = mode.AccumulatorFormat;
|
|
|
|
|
this.Buffers = mode.Buffers;
|
|
|
|
|
this.Stereo = mode.Stereo;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.Index = index;
|
|
|
|
|
this.ColorFormat = color;
|
|
|
|
|
this.Depth = depth;
|
|
|
|
|
this.Stencil = stencil;
|
|
|
|
|
this.Samples = samples;
|
|
|
|
|
this.AccumulatorFormat = accum;
|
|
|
|
|
this.Buffers = buffers;
|
|
|
|
|
this.Stereo = stereo;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-28 16:26:51 +01:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
#region public GraphicsMode()
|
2008-02-28 16:26:51 +01:00
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
/// <summary>Constructs a new GraphicsMode with sensible default parameters.</summary>
|
2008-02-28 16:26:51 +01:00
|
|
|
|
public GraphicsMode()
|
|
|
|
|
: this(Default)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
#region public GraphicsMode(ColorFormat color)
|
2008-02-28 16:26:51 +01:00
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
|
|
|
|
|
/// <param name="color">The ColorFormat of the color buffer.</param>
|
|
|
|
|
public GraphicsMode(ColorFormat color)
|
2008-02-28 16:26:51 +01:00
|
|
|
|
: this(color, Default.Depth, Default.Stencil, Default.Samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
#region public GraphicsMode(ColorFormat color, int depth)
|
2008-02-28 16:26:51 +01:00
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
|
|
|
|
|
/// <param name="color">The ColorFormat of the color buffer.</param>
|
2008-02-28 16:26:51 +01:00
|
|
|
|
/// <param name="depth">The number of bits in the depth buffer.</param>
|
2008-03-03 13:44:56 +01:00
|
|
|
|
public GraphicsMode(ColorFormat color, int depth)
|
2008-02-28 16:26:51 +01:00
|
|
|
|
: this(color, depth, Default.Stencil, Default.Samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
#region public GraphicsMode(ColorFormat color, int depth, int stencil)
|
2008-02-28 16:26:51 +01:00
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
|
|
|
|
|
/// <param name="color">The ColorFormat of the color buffer.</param>
|
2008-02-28 16:26:51 +01:00
|
|
|
|
/// <param name="depth">The number of bits in the depth buffer.</param>
|
|
|
|
|
/// <param name="stencil">The number of bits in the stencil buffer.</param>
|
2008-03-03 13:44:56 +01:00
|
|
|
|
public GraphicsMode(ColorFormat color, int depth, int stencil)
|
2008-02-28 16:26:51 +01:00
|
|
|
|
: this(color, depth, stencil, Default.Samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
#region public GraphicsMode(ColorFormat color, int depth, int stencil, int samples)
|
2008-02-28 16:26:51 +01:00
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
|
|
|
|
|
/// <param name="color">The ColorFormat of the color buffer.</param>
|
2008-02-28 16:26:51 +01:00
|
|
|
|
/// <param name="depth">The number of bits in the depth buffer.</param>
|
|
|
|
|
/// <param name="stencil">The number of bits in the stencil buffer.</param>
|
|
|
|
|
/// <param name="samples">The number of samples for FSAA.</param>
|
2008-03-03 13:44:56 +01:00
|
|
|
|
public GraphicsMode(ColorFormat color, int depth, int stencil, int samples)
|
2008-02-28 16:26:51 +01:00
|
|
|
|
: this(color, depth, stencil, samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
#region public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum)
|
2008-02-28 16:26:51 +01:00
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
|
|
|
|
|
/// <param name="color">The ColorFormat of the color buffer.</param>
|
2008-02-28 16:26:51 +01:00
|
|
|
|
/// <param name="depth">The number of bits in the depth buffer.</param>
|
|
|
|
|
/// <param name="stencil">The number of bits in the stencil buffer.</param>
|
|
|
|
|
/// <param name="samples">The number of samples for FSAA.</param>
|
2008-03-03 13:44:56 +01:00
|
|
|
|
/// <param name="accum">The ColorFormat of the accumilliary buffer.</param>
|
|
|
|
|
public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum)
|
2008-02-28 16:26:51 +01:00
|
|
|
|
: this(color, depth, stencil, samples, accum, Default.Buffers, Default.Stereo)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
#region public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers)
|
2008-02-28 16:26:51 +01:00
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
|
|
|
|
|
/// <param name="color">The ColorFormat of the color buffer.</param>
|
2008-02-28 16:26:51 +01:00
|
|
|
|
/// <param name="depth">The number of bits in the depth buffer.</param>
|
|
|
|
|
/// <param name="stencil">The number of bits in the stencil buffer.</param>
|
|
|
|
|
/// <param name="samples">The number of samples for FSAA.</param>
|
2008-03-03 13:44:56 +01:00
|
|
|
|
/// <param name="accum">The ColorFormat of the accumilliary buffer.</param>
|
2008-02-28 16:26:51 +01:00
|
|
|
|
/// <param name="buffers">The number of render buffers. Typical values include one (single-), two (double-) or three (triple-buffering).</param>
|
2008-03-03 13:44:56 +01:00
|
|
|
|
public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers)
|
2008-02-28 16:26:51 +01:00
|
|
|
|
: this(color, depth, stencil, samples, accum, buffers, Default.Stereo)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
#region public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo)
|
2008-02-28 16:26:51 +01:00
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
|
|
|
|
|
/// <param name="color">The ColorFormat of the color buffer.</param>
|
2008-02-28 16:26:51 +01:00
|
|
|
|
/// <param name="depth">The number of bits in the depth buffer.</param>
|
|
|
|
|
/// <param name="stencil">The number of bits in the stencil buffer.</param>
|
|
|
|
|
/// <param name="samples">The number of samples for FSAA.</param>
|
2008-03-03 13:44:56 +01:00
|
|
|
|
/// <param name="accum">The ColorFormat of the accumilliary buffer.</param>
|
|
|
|
|
/// <param name="stereo">Set to true for a GraphicsMode with stereographic capabilities.</param>
|
2008-02-28 16:26:51 +01:00
|
|
|
|
/// <param name="buffers">The number of render buffers. Typical values include one (single-), two (double-) or three (triple-buffering).</param>
|
2008-03-03 13:44:56 +01:00
|
|
|
|
public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo)
|
|
|
|
|
: this(IntPtr.Zero, color, depth, stencil, samples, accum, buffers, stereo) { }
|
2008-02-28 16:26:51 +01:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region --- Public Methods ---
|
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
#region public int ColorFormat
|
2008-02-28 16:26:51 +01:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2008-03-03 13:44:56 +01:00
|
|
|
|
/// Gets an OpenTK.Graphics.ColorFormat that describes the color format for this GraphicsFormat.
|
2008-02-28 16:26:51 +01:00
|
|
|
|
/// </summary>
|
2008-03-03 13:44:56 +01:00
|
|
|
|
public ColorFormat ColorFormat
|
2008-02-28 16:26:51 +01:00
|
|
|
|
{
|
|
|
|
|
get { return color_format; }
|
|
|
|
|
private set { color_format = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public int AccumulatorFormat
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2008-03-03 13:44:56 +01:00
|
|
|
|
/// Gets an OpenTK.Graphics.ColorFormat that describes the accumulator format for this GraphicsFormat.
|
2008-02-28 16:26:51 +01:00
|
|
|
|
/// </summary>
|
2008-03-03 13:44:56 +01:00
|
|
|
|
public ColorFormat AccumulatorFormat
|
2008-02-28 16:26:51 +01:00
|
|
|
|
{
|
|
|
|
|
get { return accumulator_format; }
|
|
|
|
|
private set { accumulator_format = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public int Depth
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a System.Int32 that contains the bits per pixel for the depth buffer
|
|
|
|
|
/// for this GraphicsFormat.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int Depth
|
|
|
|
|
{
|
|
|
|
|
get { return depth; }
|
|
|
|
|
private set { depth = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public int Stencil
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a System.Int32 that contains the bits per pixel for the stencil buffer
|
|
|
|
|
/// of this GraphicsFormat.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int Stencil
|
|
|
|
|
{
|
|
|
|
|
get { return stencil; }
|
|
|
|
|
private set { stencil = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
#region public int Samples
|
|
|
|
|
|
2008-02-28 16:26:51 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a System.Int32 that contains the number of FSAA samples per pixel for this GraphicsFormat.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int Samples
|
|
|
|
|
{
|
|
|
|
|
get { return samples; }
|
|
|
|
|
private set { samples = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
#endregion
|
|
|
|
|
|
2008-02-28 16:26:51 +01:00
|
|
|
|
#region public bool Stereo
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a System.Boolean indicating whether this DisplayMode is stereoscopic.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool Stereo
|
|
|
|
|
{
|
|
|
|
|
get { return this.stereo; }
|
|
|
|
|
private set { this.stereo = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public int Buffers
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a System.Int32 containing the number of buffers associated with this
|
|
|
|
|
/// DisplayMode.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int Buffers
|
|
|
|
|
{
|
|
|
|
|
get { return this.buffers; }
|
|
|
|
|
private set { this.buffers = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public static GraphicsFormat Default
|
|
|
|
|
|
|
|
|
|
/// <summary>Returns an OpenTK.GraphicsFormat compatible with the underlying platform.</summary>
|
|
|
|
|
public static GraphicsMode Default
|
|
|
|
|
{
|
2008-03-23 13:51:41 +01:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (defaultMode == null)
|
2008-03-23 13:55:33 +01:00
|
|
|
|
{
|
|
|
|
|
Debug.Print("Creating default GraphicsMode ({0}, {1}, {2}, {3}, {4}, {5}, {6}).", DisplayDevice.Default.BitsPerPixel,
|
|
|
|
|
16, 0, 0, 0, 2, false);
|
2008-03-23 13:51:41 +01:00
|
|
|
|
defaultMode = new GraphicsMode(DisplayDevice.Default.BitsPerPixel, 16, 0, 0, 0, 2, false);
|
2008-03-23 13:55:33 +01:00
|
|
|
|
}
|
2008-03-23 13:51:41 +01:00
|
|
|
|
return defaultMode;
|
|
|
|
|
}
|
2008-02-28 16:26:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2008-03-03 13:44:56 +01:00
|
|
|
|
#region --- Internal Methods ---
|
|
|
|
|
|
|
|
|
|
#region internal IntPtr Index
|
|
|
|
|
|
|
|
|
|
internal IntPtr Index
|
|
|
|
|
{
|
|
|
|
|
get { return index; }
|
|
|
|
|
set { index = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2008-02-28 16:26:51 +01:00
|
|
|
|
#region --- Overrides ---
|
|
|
|
|
|
|
|
|
|
/// <summary>Returns a System.String describing the current GraphicsFormat.</summary>
|
|
|
|
|
/// <returns>! System.String describing the current GraphicsFormat.</returns>
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
2008-03-03 13:44:56 +01:00
|
|
|
|
return String.Format("Index: {0}, Color: {1}, Depth: {2}, Stencil: {3}, Samples: {4}, Accum: {5}, Buffers: {6}, Stereo: {7}",
|
|
|
|
|
Index, ColorFormat, Depth, Stereo, Samples, AccumulatorFormat, Buffers, Stereo);
|
2008-02-28 16:26:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|