Modified GraphicsMode.Index to be a nullable property. Modified consuming classes to check Index.HasValue prior to first use.

This commit is contained in:
the_fiddler 2009-08-15 16:44:43 +00:00
parent b503c41bf1
commit 9a6a539d26
6 changed files with 408 additions and 333 deletions

View file

@ -1,293 +1,293 @@
#region --- License --- #region --- License ---
/* Licensed under the MIT/X11 license. /* Licensed under the MIT/X11 license.
* Copyright (c) 2006-2008 the OpenTK Team. * Copyright (c) 2006-2008 the OpenTK Team.
* This notice may not be removed from any source distribution. * This notice may not be removed from any source distribution.
* See license.txt for licensing detailed licensing details. * See license.txt for licensing detailed licensing details.
*/ */
#endregion #endregion
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using System.Diagnostics; using System.Diagnostics;
namespace OpenTK.Graphics namespace OpenTK.Graphics
{ {
/// <summary>Defines the format for graphics operations.</summary> /// <summary>Defines the format for graphics operations.</summary>
public class GraphicsMode public class GraphicsMode
{ {
ColorFormat color_format, accumulator_format; ColorFormat color_format, accumulator_format;
int depth, stencil, buffers, samples; int depth, stencil, buffers, samples;
bool stereo; bool stereo;
IntPtr? index; // The id of the pixel format or visual. IntPtr? index = null; // The id of the pixel format or visual.
static GraphicsMode defaultMode; static GraphicsMode defaultMode;
static IGraphicsMode implementation; static IGraphicsMode implementation;
static object mode_selection_lock = new object(); static object mode_selection_lock = new object();
#region --- Constructors --- #region --- Constructors ---
#region static GraphicsMode() #region static GraphicsMode()
static GraphicsMode() static GraphicsMode()
{ {
implementation = Platform.Factory.Default.CreateGraphicsMode(); implementation = Platform.Factory.Default.CreateGraphicsMode();
} }
#endregion #endregion
#region internal GraphicsMode(GraphicsMode mode) #region internal GraphicsMode(GraphicsMode mode)
internal GraphicsMode(GraphicsMode mode) internal GraphicsMode(GraphicsMode mode)
: this(mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo) { } : this(mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo) { }
#endregion #endregion
#region internal GraphicsMode((IntPtr index, ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo) #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, internal GraphicsMode(IntPtr? index, ColorFormat color, int depth, int stencil, int samples, ColorFormat accum,
int buffers, bool stereo) int buffers, bool stereo)
{ {
if (depth < 0) throw new ArgumentOutOfRangeException("depth", "Must be greater than, or equal to zero."); 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 (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 (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."); if (samples < 0) throw new ArgumentOutOfRangeException("samples", "Must be greater than, or equal to zero.");
this.Index = index; this.Index = index;
this.ColorFormat = color; this.ColorFormat = color;
this.Depth = depth; this.Depth = depth;
this.Stencil = stencil; this.Stencil = stencil;
this.Samples = samples; this.Samples = samples;
this.AccumulatorFormat = accum; this.AccumulatorFormat = accum;
this.Buffers = buffers; this.Buffers = buffers;
this.Stereo = stereo; this.Stereo = stereo;
} }
#endregion #endregion
#region public GraphicsMode() #region public GraphicsMode()
/// <summary>Constructs a new GraphicsMode with sensible default parameters.</summary> /// <summary>Constructs a new GraphicsMode with sensible default parameters.</summary>
public GraphicsMode() public GraphicsMode()
: this(Default) : this(Default)
{ } { }
#endregion #endregion
#region public GraphicsMode(ColorFormat color) #region public GraphicsMode(ColorFormat color)
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary> /// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
/// <param name="color">The ColorFormat of the color buffer.</param> /// <param name="color">The ColorFormat of the color buffer.</param>
public GraphicsMode(ColorFormat color) public GraphicsMode(ColorFormat color)
: this(color, Default.Depth, Default.Stencil, Default.Samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo) : this(color, Default.Depth, Default.Stencil, Default.Samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
{ } { }
#endregion #endregion
#region public GraphicsMode(ColorFormat color, int depth) #region public GraphicsMode(ColorFormat color, int depth)
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary> /// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
/// <param name="color">The ColorFormat of the color buffer.</param> /// <param name="color">The ColorFormat of the color buffer.</param>
/// <param name="depth">The number of bits in the depth buffer.</param> /// <param name="depth">The number of bits in the depth buffer.</param>
public GraphicsMode(ColorFormat color, int depth) public GraphicsMode(ColorFormat color, int depth)
: this(color, depth, Default.Stencil, Default.Samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo) : this(color, depth, Default.Stencil, Default.Samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
{ } { }
#endregion #endregion
#region public GraphicsMode(ColorFormat color, int depth, int stencil) #region public GraphicsMode(ColorFormat color, int depth, int stencil)
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary> /// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
/// <param name="color">The ColorFormat of the color buffer.</param> /// <param name="color">The ColorFormat of the color buffer.</param>
/// <param name="depth">The number of bits in the depth 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="stencil">The number of bits in the stencil buffer.</param>
public GraphicsMode(ColorFormat color, int depth, int stencil) public GraphicsMode(ColorFormat color, int depth, int stencil)
: this(color, depth, stencil, Default.Samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo) : this(color, depth, stencil, Default.Samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
{ } { }
#endregion #endregion
#region public GraphicsMode(ColorFormat color, int depth, int stencil, int samples) #region public GraphicsMode(ColorFormat color, int depth, int stencil, int samples)
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary> /// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
/// <param name="color">The ColorFormat of the color buffer.</param> /// <param name="color">The ColorFormat of the color buffer.</param>
/// <param name="depth">The number of bits in the depth 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="stencil">The number of bits in the stencil buffer.</param>
/// <param name="samples">The number of samples for FSAA.</param> /// <param name="samples">The number of samples for FSAA.</param>
public GraphicsMode(ColorFormat color, int depth, int stencil, int samples) public GraphicsMode(ColorFormat color, int depth, int stencil, int samples)
: this(color, depth, stencil, samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo) : this(color, depth, stencil, samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
{ } { }
#endregion #endregion
#region public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum) #region public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum)
/// <summary>Constructs a new GraphicsMode with the specified parameters.</summary> /// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
/// <param name="color">The ColorFormat of the color buffer.</param> /// <param name="color">The ColorFormat of the color buffer.</param>
/// <param name="depth">The number of bits in the depth 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="stencil">The number of bits in the stencil buffer.</param>
/// <param name="samples">The number of samples for FSAA.</param> /// <param name="samples">The number of samples for FSAA.</param>
/// <param name="accum">The ColorFormat of the accumilliary buffer.</param> /// <param name="accum">The ColorFormat of the accumilliary buffer.</param>
public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum) public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum)
: this(color, depth, stencil, samples, accum, Default.Buffers, Default.Stereo) : this(color, depth, stencil, samples, accum, Default.Buffers, Default.Stereo)
{ } { }
#endregion #endregion
#region public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers) #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> /// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
/// <param name="color">The ColorFormat of the color buffer.</param> /// <param name="color">The ColorFormat of the color buffer.</param>
/// <param name="depth">The number of bits in the depth 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="stencil">The number of bits in the stencil buffer.</param>
/// <param name="samples">The number of samples for FSAA.</param> /// <param name="samples">The number of samples for FSAA.</param>
/// <param name="accum">The ColorFormat of the accumilliary buffer.</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> /// <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) public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers)
: this(color, depth, stencil, samples, accum, buffers, Default.Stereo) : this(color, depth, stencil, samples, accum, buffers, Default.Stereo)
{ } { }
#endregion #endregion
#region public GraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo) #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> /// <summary>Constructs a new GraphicsMode with the specified parameters.</summary>
/// <param name="color">The ColorFormat of the color buffer.</param> /// <param name="color">The ColorFormat of the color buffer.</param>
/// <param name="depth">The number of bits in the depth 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="stencil">The number of bits in the stencil buffer.</param>
/// <param name="samples">The number of samples for FSAA.</param> /// <param name="samples">The number of samples for FSAA.</param>
/// <param name="accum">The ColorFormat of the accumilliary buffer.</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="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> /// <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) 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) { } : this(null, color, depth, stencil, samples, accum, buffers, stereo) { }
#endregion #endregion
#endregion #endregion
#region --- Public Methods --- #region --- Public Methods ---
#region public int ColorFormat #region public int ColorFormat
/// <summary> /// <summary>
/// Gets an OpenTK.Graphics.ColorFormat that describes the color format for this GraphicsFormat. /// Gets an OpenTK.Graphics.ColorFormat that describes the color format for this GraphicsFormat.
/// </summary> /// </summary>
public ColorFormat ColorFormat public ColorFormat ColorFormat
{ {
get { return color_format; } get { return color_format; }
private set { color_format = value; } private set { color_format = value; }
} }
#endregion #endregion
#region public int AccumulatorFormat #region public int AccumulatorFormat
/// <summary> /// <summary>
/// Gets an OpenTK.Graphics.ColorFormat that describes the accumulator format for this GraphicsFormat. /// Gets an OpenTK.Graphics.ColorFormat that describes the accumulator format for this GraphicsFormat.
/// </summary> /// </summary>
public ColorFormat AccumulatorFormat public ColorFormat AccumulatorFormat
{ {
get { return accumulator_format; } get { return accumulator_format; }
private set { accumulator_format = value; } private set { accumulator_format = value; }
} }
#endregion #endregion
#region public int Depth #region public int Depth
/// <summary> /// <summary>
/// Gets a System.Int32 that contains the bits per pixel for the depth buffer /// Gets a System.Int32 that contains the bits per pixel for the depth buffer
/// for this GraphicsFormat. /// for this GraphicsFormat.
/// </summary> /// </summary>
public int Depth public int Depth
{ {
get { return depth; } get { return depth; }
private set { depth = value; } private set { depth = value; }
} }
#endregion #endregion
#region public int Stencil #region public int Stencil
/// <summary> /// <summary>
/// Gets a System.Int32 that contains the bits per pixel for the stencil buffer /// Gets a System.Int32 that contains the bits per pixel for the stencil buffer
/// of this GraphicsFormat. /// of this GraphicsFormat.
/// </summary> /// </summary>
public int Stencil public int Stencil
{ {
get { return stencil; } get { return stencil; }
private set { stencil = value; } private set { stencil = value; }
} }
#endregion #endregion
#region public int Samples #region public int Samples
/// <summary> /// <summary>
/// Gets a System.Int32 that contains the number of FSAA samples per pixel for this GraphicsFormat. /// Gets a System.Int32 that contains the number of FSAA samples per pixel for this GraphicsFormat.
/// </summary> /// </summary>
public int Samples public int Samples
{ {
get { return samples; } get { return samples; }
private set { samples = value; } private set { samples = value; }
} }
#endregion #endregion
#region public bool Stereo #region public bool Stereo
/// <summary> /// <summary>
/// Gets a System.Boolean indicating whether this DisplayMode is stereoscopic. /// Gets a System.Boolean indicating whether this DisplayMode is stereoscopic.
/// </summary> /// </summary>
public bool Stereo public bool Stereo
{ {
get { return this.stereo; } get { return this.stereo; }
private set { this.stereo = value; } private set { this.stereo = value; }
} }
#endregion #endregion
#region public int Buffers #region public int Buffers
/// <summary> /// <summary>
/// Gets a System.Int32 containing the number of buffers associated with this /// Gets a System.Int32 containing the number of buffers associated with this
/// DisplayMode. /// DisplayMode.
/// </summary> /// </summary>
public int Buffers public int Buffers
{ {
get { return this.buffers; } get { return this.buffers; }
private set { this.buffers = value; } private set { this.buffers = value; }
} }
#endregion #endregion
#region public static GraphicsFormat Default #region public static GraphicsFormat Default
/// <summary>Returns an OpenTK.GraphicsFormat compatible with the underlying platform.</summary> /// <summary>Returns an OpenTK.GraphicsFormat compatible with the underlying platform.</summary>
public static GraphicsMode Default public static GraphicsMode Default
{ {
get get
{ {
if (defaultMode == null) if (defaultMode == null)
{ {
Debug.Print("Creating default GraphicsMode ({0}, {1}, {2}, {3}, {4}, {5}, {6}).", DisplayDevice.Default.BitsPerPixel, Debug.Print("Creating default GraphicsMode ({0}, {1}, {2}, {3}, {4}, {5}, {6}).", DisplayDevice.Default.BitsPerPixel,
16, 0, 0, 0, 2, false); 16, 0, 0, 0, 2, false);
defaultMode = new GraphicsMode(DisplayDevice.Default.BitsPerPixel, 16, 0, 0, 0, 2, false); defaultMode = new GraphicsMode(DisplayDevice.Default.BitsPerPixel, 16, 0, 0, 0, 2, false);
} }
return defaultMode; return defaultMode;
} }
} }
#endregion #endregion
#endregion #endregion
#region --- Internal Methods --- #region --- Internal Methods ---
#region internal IntPtr Index #region internal IntPtr Index
internal IntPtr Index internal IntPtr? Index
{ {
get get
{ {
@ -309,25 +309,25 @@ namespace OpenTK.Graphics
Stereo = mode.Stereo; Stereo = mode.Stereo;
} }
return index.Value; return index;
} }
set { index = value; } set { index = value; }
} }
#endregion #endregion
#endregion #endregion
#region --- Overrides --- #region --- Overrides ---
/// <summary>Returns a System.String describing the current GraphicsFormat.</summary> /// <summary>Returns a System.String describing the current GraphicsFormat.</summary>
/// <returns>! System.String describing the current GraphicsFormat.</returns> /// <returns>! System.String describing the current GraphicsFormat.</returns>
public override string ToString() public override string ToString()
{ {
return String.Format("Index: {0}, Color: {1}, Depth: {2}, Stencil: {3}, Samples: {4}, Accum: {5}, Buffers: {6}, Stereo: {7}", 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); Index, ColorFormat, Depth, Stencil, Samples, AccumulatorFormat, Buffers, Stereo);
} }
#endregion #endregion
} }
} }

View file

@ -29,14 +29,15 @@ using System;
using OpenTK.Graphics; using OpenTK.Graphics;
using System.Diagnostics; using System.Diagnostics;
using OpenTK.Platform.Windows;
namespace OpenTK.Platform.Egl namespace OpenTK.Platform.Egl
{ {
class EglContext : IGraphicsContext class EglContext : IGraphicsContext, IGraphicsContextInternal
{ {
#region Fields #region Fields
EglWindowInfo window; EglWindowInfo WindowInfo;
EGLContext context; EGLContext context;
GraphicsMode mode; GraphicsMode mode;
bool vsync = true; // Default vsync value is defined as 1 (true) in EGL. 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; 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) if (window.Surface.Handle == EGLSurface.None.Handle)
window.CreateWindowSurface(config); 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); MakeCurrent(window);
} }
@ -73,14 +83,18 @@ namespace OpenTK.Platform.Egl
public void SwapBuffers() public void SwapBuffers()
{ {
Egl.SwapBuffers(window.Display, window.Surface); Egl.SwapBuffers(WindowInfo.Display, WindowInfo.Surface);
} }
public void MakeCurrent(IWindowInfo window) public void MakeCurrent(IWindowInfo window)
{ {
EglWindowInfo egl = (EglWindowInfo)window; // Ignore 'window', unless it actually is an EGL window. In other words,
Egl.MakeCurrent(egl.Display, egl.Surface, egl.Surface, context); // trying to make the EglContext current on a non-EGL window will do,
this.window = egl; // 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 public bool IsCurrent
@ -100,10 +114,10 @@ namespace OpenTK.Platform.Egl
} }
set set
{ {
if (Egl.SwapInterval(window.Display, value ? 1 : 0)) if (Egl.SwapInterval(WindowInfo.Display, value ? 1 : 0))
vsync = value; vsync = value;
else 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) if (manual)
{ {
Egl.MakeCurrent(window.Display, window.Surface, window.Surface, EGLContext.None); Egl.MakeCurrent(WindowInfo.Display, WindowInfo.Surface, WindowInfo.Surface, EGLContext.None);
Egl.DestroyContext(window.Display, context); Egl.DestroyContext(WindowInfo.Display, context);
} }
else else
{ {
@ -164,5 +178,42 @@ namespace OpenTK.Platform.Egl
} }
#endregion #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
} }
} }

View file

@ -429,9 +429,26 @@ namespace OpenTK.Platform.MacOS
throw new Exception("The method or operation is not implemented."); 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) 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 #endregion

View file

@ -314,15 +314,16 @@ namespace OpenTK.Platform.Windows
void SetGraphicsModePFD(GraphicsMode mode, WinWindowInfo window) void SetGraphicsModePFD(GraphicsMode mode, WinWindowInfo window)
{ {
if (mode.Index == IntPtr.Zero) throw new ArgumentException( if (!mode.Index.HasValue)
"mode", "The Index (pixel format) of the GraphicsMode is not set."); throw new GraphicsModeException("Invalid or unsupported GraphicsMode.");
if (window == null) throw new ArgumentNullException("window", "Must point to a valid window."); if (window == null) throw new ArgumentNullException("window", "Must point to a valid window.");
PixelFormatDescriptor pfd = new PixelFormatDescriptor(); PixelFormatDescriptor pfd = new PixelFormatDescriptor();
Functions.DescribePixelFormat(window.DeviceContext, (int)mode.Index, Functions.DescribePixelFormat(window.DeviceContext, (int)mode.Index.Value,
API.PixelFormatDescriptorSize, ref pfd); API.PixelFormatDescriptorSize, ref pfd);
Debug.WriteLine(mode.Index.ToString()); 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( throw new GraphicsContextException(String.Format(
"Requested GraphicsMode not available. SetPixelFormat error: {0}", Marshal.GetLastWin32Error())); "Requested GraphicsMode not available. SetPixelFormat error: {0}", Marshal.GetLastWin32Error()));
} }

View file

@ -24,13 +24,16 @@ namespace OpenTK.Platform.X11
internal X11GLControl(GraphicsMode mode, Control control) internal X11GLControl(GraphicsMode mode, Control control)
{ {
if (!mode.Index.HasValue)
throw new GraphicsModeException("Invalid GraphicsMode.");
this.mode = mode; this.mode = mode;
this.control = control; this.control = control;
X11WindowInfo window = (X11WindowInfo)this.WindowInfo; X11WindowInfo window = (X11WindowInfo)this.WindowInfo;
XVisualInfo info = new XVisualInfo(); XVisualInfo info = new XVisualInfo();
info.VisualID = mode.Index;
info.VisualID = mode.Index.Value;
int dummy; int dummy;
window.VisualInfo = (XVisualInfo)Marshal.PtrToStructure( window.VisualInfo = (XVisualInfo)Marshal.PtrToStructure(
Functions.XGetVisualInfo(window.Display, XVisualInfoMask.ID, ref info, out dummy), typeof(XVisualInfo)); Functions.XGetVisualInfo(window.Display, XVisualInfoMask.ID, ref info, out dummy), typeof(XVisualInfo));

View file

@ -124,7 +124,10 @@ namespace OpenTK.Platform.X11
lock (API.Lock) 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; int dummy;
window.VisualInfo = (XVisualInfo)Marshal.PtrToStructure( window.VisualInfo = (XVisualInfo)Marshal.PtrToStructure(
Functions.XGetVisualInfo(window.Display, XVisualInfoMask.ID, ref info, out dummy), typeof(XVisualInfo)); Functions.XGetVisualInfo(window.Display, XVisualInfoMask.ID, ref info, out dummy), typeof(XVisualInfo));