Modified GraphicsMode.Index to be a nullable property. Modified consuming classes to check Index.HasValue prior to first use.
This commit is contained in:
parent
b503c41bf1
commit
9a6a539d26
6 changed files with 408 additions and 333 deletions
|
@ -1,293 +1,293 @@
|
|||
#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;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
/// <summary>Defines the format for graphics operations.</summary>
|
||||
public class GraphicsMode
|
||||
{
|
||||
ColorFormat color_format, accumulator_format;
|
||||
int depth, stencil, buffers, samples;
|
||||
bool stereo;
|
||||
IntPtr? index; // The id of the pixel format or visual.
|
||||
|
||||
static GraphicsMode defaultMode;
|
||||
static IGraphicsMode implementation;
|
||||
static object mode_selection_lock = new object();
|
||||
|
||||
#region --- Constructors ---
|
||||
|
||||
#region static GraphicsMode()
|
||||
|
||||
static GraphicsMode()
|
||||
{
|
||||
implementation = Platform.Factory.Default.CreateGraphicsMode();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region internal GraphicsMode(GraphicsMode mode)
|
||||
|
||||
internal GraphicsMode(GraphicsMode mode)
|
||||
: 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.Index = index;
|
||||
this.ColorFormat = color;
|
||||
this.Depth = depth;
|
||||
this.Stencil = stencil;
|
||||
this.Samples = samples;
|
||||
this.AccumulatorFormat = accum;
|
||||
this.Buffers = buffers;
|
||||
this.Stereo = stereo;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsMode()
|
||||
|
||||
/// <summary>Constructs a new GraphicsMode with sensible default parameters.</summary>
|
||||
public GraphicsMode()
|
||||
: this(Default)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsMode(ColorFormat color)
|
||||
|
||||
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
public GraphicsMode(ColorFormat color)
|
||||
: this(color, Default.Depth, Default.Stencil, Default.Samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsMode(ColorFormat color, int depth)
|
||||
|
||||
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <param name="depth">The number of bits in the depth buffer.</param>
|
||||
public GraphicsMode(ColorFormat color, int depth)
|
||||
: this(color, depth, Default.Stencil, Default.Samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsMode(ColorFormat color, int depth, int stencil)
|
||||
|
||||
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <param name="depth">The number of bits in the depth buffer.</param>
|
||||
/// <param name="stencil">The number of bits in the stencil buffer.</param>
|
||||
public GraphicsMode(ColorFormat color, int depth, int stencil)
|
||||
: this(color, depth, stencil, Default.Samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsMode(ColorFormat color, int depth, int stencil, int samples)
|
||||
|
||||
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <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>
|
||||
public GraphicsMode(ColorFormat color, int depth, int stencil, int samples)
|
||||
: this(color, depth, stencil, samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum)
|
||||
|
||||
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <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>
|
||||
/// <param name="accum">The ColorFormat of the accumilliary buffer.</param>
|
||||
public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum)
|
||||
: this(color, depth, stencil, samples, accum, Default.Buffers, Default.Stereo)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers)
|
||||
|
||||
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <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>
|
||||
/// <param name="accum">The ColorFormat of the accumilliary buffer.</param>
|
||||
/// <param name="buffers">The number of render buffers. Typical values include one (single-), two (double-) or three (triple-buffering).</param>
|
||||
public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers)
|
||||
: this(color, depth, stencil, samples, accum, buffers, Default.Stereo)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo)
|
||||
|
||||
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <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>
|
||||
/// <param name="accum">The ColorFormat of the accumilliary buffer.</param>
|
||||
/// <param name="stereo">Set to true for a GraphicsMode with stereographic capabilities.</param>
|
||||
/// <param name="buffers">The number of render buffers. Typical values include one (single-), two (double-) or three (triple-buffering).</param>
|
||||
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) { }
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Public Methods ---
|
||||
|
||||
#region public int ColorFormat
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Graphics.ColorFormat that describes the color format for this GraphicsFormat.
|
||||
/// </summary>
|
||||
public ColorFormat ColorFormat
|
||||
{
|
||||
get { return color_format; }
|
||||
private set { color_format = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public int AccumulatorFormat
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Graphics.ColorFormat that describes the accumulator format for this GraphicsFormat.
|
||||
/// </summary>
|
||||
public ColorFormat AccumulatorFormat
|
||||
{
|
||||
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
|
||||
|
||||
#region public int Samples
|
||||
|
||||
/// <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; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#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
|
||||
{
|
||||
get
|
||||
{
|
||||
if (defaultMode == null)
|
||||
{
|
||||
Debug.Print("Creating default GraphicsMode ({0}, {1}, {2}, {3}, {4}, {5}, {6}).", DisplayDevice.Default.BitsPerPixel,
|
||||
16, 0, 0, 0, 2, false);
|
||||
defaultMode = new GraphicsMode(DisplayDevice.Default.BitsPerPixel, 16, 0, 0, 0, 2, false);
|
||||
}
|
||||
return defaultMode;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Internal Methods ---
|
||||
|
||||
#region internal IntPtr Index
|
||||
|
||||
internal IntPtr Index
|
||||
#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;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
/// <summary>Defines the format for graphics operations.</summary>
|
||||
public class GraphicsMode
|
||||
{
|
||||
ColorFormat color_format, accumulator_format;
|
||||
int depth, stencil, buffers, samples;
|
||||
bool stereo;
|
||||
IntPtr? index = null; // The id of the pixel format or visual.
|
||||
|
||||
static GraphicsMode defaultMode;
|
||||
static IGraphicsMode implementation;
|
||||
static object mode_selection_lock = new object();
|
||||
|
||||
#region --- Constructors ---
|
||||
|
||||
#region static GraphicsMode()
|
||||
|
||||
static GraphicsMode()
|
||||
{
|
||||
implementation = Platform.Factory.Default.CreateGraphicsMode();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region internal GraphicsMode(GraphicsMode mode)
|
||||
|
||||
internal GraphicsMode(GraphicsMode mode)
|
||||
: 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.Index = index;
|
||||
this.ColorFormat = color;
|
||||
this.Depth = depth;
|
||||
this.Stencil = stencil;
|
||||
this.Samples = samples;
|
||||
this.AccumulatorFormat = accum;
|
||||
this.Buffers = buffers;
|
||||
this.Stereo = stereo;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsMode()
|
||||
|
||||
/// <summary>Constructs a new GraphicsMode with sensible default parameters.</summary>
|
||||
public GraphicsMode()
|
||||
: this(Default)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsMode(ColorFormat color)
|
||||
|
||||
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
public GraphicsMode(ColorFormat color)
|
||||
: this(color, Default.Depth, Default.Stencil, Default.Samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsMode(ColorFormat color, int depth)
|
||||
|
||||
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <param name="depth">The number of bits in the depth buffer.</param>
|
||||
public GraphicsMode(ColorFormat color, int depth)
|
||||
: this(color, depth, Default.Stencil, Default.Samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsMode(ColorFormat color, int depth, int stencil)
|
||||
|
||||
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <param name="depth">The number of bits in the depth buffer.</param>
|
||||
/// <param name="stencil">The number of bits in the stencil buffer.</param>
|
||||
public GraphicsMode(ColorFormat color, int depth, int stencil)
|
||||
: this(color, depth, stencil, Default.Samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsMode(ColorFormat color, int depth, int stencil, int samples)
|
||||
|
||||
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <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>
|
||||
public GraphicsMode(ColorFormat color, int depth, int stencil, int samples)
|
||||
: this(color, depth, stencil, samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum)
|
||||
|
||||
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <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>
|
||||
/// <param name="accum">The ColorFormat of the accumilliary buffer.</param>
|
||||
public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum)
|
||||
: this(color, depth, stencil, samples, accum, Default.Buffers, Default.Stereo)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers)
|
||||
|
||||
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <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>
|
||||
/// <param name="accum">The ColorFormat of the accumilliary buffer.</param>
|
||||
/// <param name="buffers">The number of render buffers. Typical values include one (single-), two (double-) or three (triple-buffering).</param>
|
||||
public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers)
|
||||
: this(color, depth, stencil, samples, accum, buffers, Default.Stereo)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo)
|
||||
|
||||
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <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>
|
||||
/// <param name="accum">The ColorFormat of the accumilliary buffer.</param>
|
||||
/// <param name="stereo">Set to true for a GraphicsMode with stereographic capabilities.</param>
|
||||
/// <param name="buffers">The number of render buffers. Typical values include one (single-), two (double-) or three (triple-buffering).</param>
|
||||
public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo)
|
||||
: this(null, color, depth, stencil, samples, accum, buffers, stereo) { }
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Public Methods ---
|
||||
|
||||
#region public int ColorFormat
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Graphics.ColorFormat that describes the color format for this GraphicsFormat.
|
||||
/// </summary>
|
||||
public ColorFormat ColorFormat
|
||||
{
|
||||
get { return color_format; }
|
||||
private set { color_format = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public int AccumulatorFormat
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Graphics.ColorFormat that describes the accumulator format for this GraphicsFormat.
|
||||
/// </summary>
|
||||
public ColorFormat AccumulatorFormat
|
||||
{
|
||||
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
|
||||
|
||||
#region public int Samples
|
||||
|
||||
/// <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; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#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
|
||||
{
|
||||
get
|
||||
{
|
||||
if (defaultMode == null)
|
||||
{
|
||||
Debug.Print("Creating default GraphicsMode ({0}, {1}, {2}, {3}, {4}, {5}, {6}).", DisplayDevice.Default.BitsPerPixel,
|
||||
16, 0, 0, 0, 2, false);
|
||||
defaultMode = new GraphicsMode(DisplayDevice.Default.BitsPerPixel, 16, 0, 0, 0, 2, false);
|
||||
}
|
||||
return defaultMode;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Internal Methods ---
|
||||
|
||||
#region internal IntPtr Index
|
||||
|
||||
internal IntPtr? Index
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -309,25 +309,25 @@ namespace OpenTK.Graphics
|
|||
Stereo = mode.Stereo;
|
||||
}
|
||||
|
||||
return index.Value;
|
||||
}
|
||||
set { index = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Overrides ---
|
||||
|
||||
/// <summary>Returns a System.String describing the current GraphicsFormat.</summary>
|
||||
/// <returns>! System.String describing the current GraphicsFormat.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("Index: {0}, Color: {1}, Depth: {2}, Stencil: {3}, Samples: {4}, Accum: {5}, Buffers: {6}, Stereo: {7}",
|
||||
Index, ColorFormat, Depth, Stencil, Samples, AccumulatorFormat, Buffers, Stereo);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
set { index = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Overrides ---
|
||||
|
||||
/// <summary>Returns a System.String describing the current GraphicsFormat.</summary>
|
||||
/// <returns>! System.String describing the current GraphicsFormat.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("Index: {0}, Color: {1}, Depth: {2}, Stencil: {3}, Samples: {4}, Accum: {5}, Buffers: {6}, Stereo: {7}",
|
||||
Index, ColorFormat, Depth, Stencil, Samples, AccumulatorFormat, Buffers, Stereo);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,14 +29,15 @@ using System;
|
|||
|
||||
using OpenTK.Graphics;
|
||||
using System.Diagnostics;
|
||||
using OpenTK.Platform.Windows;
|
||||
|
||||
namespace OpenTK.Platform.Egl
|
||||
{
|
||||
class EglContext : IGraphicsContext
|
||||
class EglContext : IGraphicsContext, IGraphicsContextInternal
|
||||
{
|
||||
#region Fields
|
||||
|
||||
EglWindowInfo window;
|
||||
EglWindowInfo WindowInfo;
|
||||
EGLContext context;
|
||||
GraphicsMode mode;
|
||||
bool vsync = true; // Default vsync value is defined as 1 (true) in EGL.
|
||||
|
@ -56,14 +57,23 @@ namespace OpenTK.Platform.Egl
|
|||
|
||||
EglContext shared = (EglContext)sharedContext;
|
||||
|
||||
Egl.Initialize(window.Display, out major, out minor);
|
||||
int dummy_major, dummy_minor;
|
||||
if (!Egl.Initialize(window.Display, out dummy_major, out dummy_minor))
|
||||
throw new GraphicsContextException(String.Format("Failed to initialize EGL, error {0}.", Egl.GetError()));
|
||||
|
||||
EGLConfig config = new EGLConfig(mode.Index);
|
||||
WindowInfo = window;
|
||||
|
||||
mode = new EglGraphicsMode().SelectGraphicsMode(mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo);
|
||||
if (!mode.Index.HasValue)
|
||||
throw new GraphicsModeException("Invalid or unsupported GraphicsMode.");
|
||||
EGLConfig config = new EGLConfig(mode.Index.Value);
|
||||
|
||||
if (window.Surface.Handle == EGLSurface.None.Handle)
|
||||
window.CreateWindowSurface(config);
|
||||
|
||||
context = Egl.CreateContext(window.Display, config, shared.context, null);
|
||||
int[] attrib_list = new int[] { Egl.CONTEXT_CLIENT_VERSION, major, Egl.NONE };
|
||||
context = Egl.CreateContext(window.Display, config, shared != null ? shared.context : EGLContext.None, attrib_list);
|
||||
|
||||
MakeCurrent(window);
|
||||
}
|
||||
|
||||
|
@ -73,14 +83,18 @@ namespace OpenTK.Platform.Egl
|
|||
|
||||
public void SwapBuffers()
|
||||
{
|
||||
Egl.SwapBuffers(window.Display, window.Surface);
|
||||
Egl.SwapBuffers(WindowInfo.Display, WindowInfo.Surface);
|
||||
}
|
||||
|
||||
public void MakeCurrent(IWindowInfo window)
|
||||
{
|
||||
EglWindowInfo egl = (EglWindowInfo)window;
|
||||
Egl.MakeCurrent(egl.Display, egl.Surface, egl.Surface, context);
|
||||
this.window = egl;
|
||||
// Ignore 'window', unless it actually is an EGL window. In other words,
|
||||
// trying to make the EglContext current on a non-EGL window will do,
|
||||
// nothing (the EglContext will remain current on the previous EGL window
|
||||
// or the window it was constructed on (which may not be EGL)).
|
||||
if (window is EglWindowInfo)
|
||||
WindowInfo = (EglWindowInfo)window;
|
||||
Egl.MakeCurrent(WindowInfo.Display, WindowInfo.Surface, WindowInfo.Surface, context);
|
||||
}
|
||||
|
||||
public bool IsCurrent
|
||||
|
@ -100,10 +114,10 @@ namespace OpenTK.Platform.Egl
|
|||
}
|
||||
set
|
||||
{
|
||||
if (Egl.SwapInterval(window.Display, value ? 1 : 0))
|
||||
if (Egl.SwapInterval(WindowInfo.Display, value ? 1 : 0))
|
||||
vsync = value;
|
||||
else
|
||||
Debug.Print("[Warning] Egl.SwapInterval({0}, {1}) failed.", window.Display, value);
|
||||
Debug.Print("[Warning] Egl.SwapInterval({0}, {1}) failed.", WindowInfo.Display, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,8 +161,8 @@ namespace OpenTK.Platform.Egl
|
|||
{
|
||||
if (manual)
|
||||
{
|
||||
Egl.MakeCurrent(window.Display, window.Surface, window.Surface, EGLContext.None);
|
||||
Egl.DestroyContext(window.Display, context);
|
||||
Egl.MakeCurrent(WindowInfo.Display, WindowInfo.Surface, WindowInfo.Surface, EGLContext.None);
|
||||
Egl.DestroyContext(WindowInfo.Display, context);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -164,5 +178,42 @@ namespace OpenTK.Platform.Egl
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IGraphicsContextInternal Members
|
||||
|
||||
public IGraphicsContext Implementation
|
||||
{
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
public void LoadAll()
|
||||
{
|
||||
// Todo: enable those
|
||||
//OpenTK.Graphics.ES10.ES.LoadAll();
|
||||
OpenTK.Graphics.ES11.GL.LoadAll();
|
||||
//OpenTK.Graphics.ES20.ES.LoadAll();
|
||||
}
|
||||
|
||||
public ContextHandle Context
|
||||
{
|
||||
get { return new ContextHandle(context.Handle.Value); }
|
||||
}
|
||||
|
||||
public void RegisterForDisposal(IDisposable resource)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void DisposeResources()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IntPtr GetAddress(string function)
|
||||
{
|
||||
return Egl.GetProcAddress(function);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -429,9 +429,26 @@ namespace OpenTK.Platform.MacOS
|
|||
throw new Exception("The method or operation is not implemented.");
|
||||
}
|
||||
|
||||
private const string Library = "libdl.dylib";
|
||||
|
||||
[DllImport(Library, EntryPoint = "NSIsSymbolNameDefined")]
|
||||
private static extern bool NSIsSymbolNameDefined(string s);
|
||||
[DllImport(Library, EntryPoint = "NSLookupAndBindSymbol")]
|
||||
private static extern IntPtr NSLookupAndBindSymbol(string s);
|
||||
[DllImport(Library, EntryPoint = "NSAddressOfSymbol")]
|
||||
private static extern IntPtr NSAddressOfSymbol(IntPtr symbol);
|
||||
|
||||
IntPtr IGraphicsContextInternal.GetAddress(string function)
|
||||
{
|
||||
throw new Exception("The method or operation is not implemented.");
|
||||
string fname = "_" + function;
|
||||
if (!NSIsSymbolNameDefined(fname))
|
||||
return IntPtr.Zero;
|
||||
|
||||
IntPtr symbol = NSLookupAndBindSymbol(fname);
|
||||
if (symbol != IntPtr.Zero)
|
||||
symbol = NSAddressOfSymbol(symbol);
|
||||
|
||||
return symbol;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -314,15 +314,16 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
void SetGraphicsModePFD(GraphicsMode mode, WinWindowInfo window)
|
||||
{
|
||||
if (mode.Index == IntPtr.Zero) throw new ArgumentException(
|
||||
"mode", "The Index (pixel format) of the GraphicsMode is not set.");
|
||||
if (!mode.Index.HasValue)
|
||||
throw new GraphicsModeException("Invalid or unsupported GraphicsMode.");
|
||||
|
||||
if (window == null) throw new ArgumentNullException("window", "Must point to a valid window.");
|
||||
|
||||
PixelFormatDescriptor pfd = new PixelFormatDescriptor();
|
||||
Functions.DescribePixelFormat(window.DeviceContext, (int)mode.Index,
|
||||
Functions.DescribePixelFormat(window.DeviceContext, (int)mode.Index.Value,
|
||||
API.PixelFormatDescriptorSize, ref pfd);
|
||||
Debug.WriteLine(mode.Index.ToString());
|
||||
if (!Functions.SetPixelFormat(window.DeviceContext, (int)mode.Index, ref pfd))
|
||||
if (!Functions.SetPixelFormat(window.DeviceContext, (int)mode.Index.Value, ref pfd))
|
||||
throw new GraphicsContextException(String.Format(
|
||||
"Requested GraphicsMode not available. SetPixelFormat error: {0}", Marshal.GetLastWin32Error()));
|
||||
}
|
||||
|
|
|
@ -24,13 +24,16 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
internal X11GLControl(GraphicsMode mode, Control control)
|
||||
{
|
||||
if (!mode.Index.HasValue)
|
||||
throw new GraphicsModeException("Invalid GraphicsMode.");
|
||||
|
||||
this.mode = mode;
|
||||
this.control = control;
|
||||
|
||||
X11WindowInfo window = (X11WindowInfo)this.WindowInfo;
|
||||
|
||||
XVisualInfo info = new XVisualInfo();
|
||||
info.VisualID = mode.Index;
|
||||
|
||||
info.VisualID = mode.Index.Value;
|
||||
int dummy;
|
||||
window.VisualInfo = (XVisualInfo)Marshal.PtrToStructure(
|
||||
Functions.XGetVisualInfo(window.Display, XVisualInfoMask.ID, ref info, out dummy), typeof(XVisualInfo));
|
||||
|
|
|
@ -124,7 +124,10 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
lock (API.Lock)
|
||||
{
|
||||
info.VisualID = mode.Index;
|
||||
if (!mode.Index.HasValue)
|
||||
throw new GraphicsModeException("Invalid or unsupported GraphicsMode.");
|
||||
|
||||
info.VisualID = mode.Index.Value;
|
||||
int dummy;
|
||||
window.VisualInfo = (XVisualInfo)Marshal.PtrToStructure(
|
||||
Functions.XGetVisualInfo(window.Display, XVisualInfoMask.ID, ref info, out dummy), typeof(XVisualInfo));
|
||||
|
|
Loading…
Reference in a new issue