mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-24 02:25:28 +00:00
Major update: fixed context construction on X11.
Fixed vsync on X11. Updated GraphicsContext interface, for better extensibility. Some public functions were moved to IGraphicsContextInternal. Renamed DisplayDevice.PrimaryDisplay to DisplayDevice.Default. Updated and documented new GameWindow constructors. Improved GameWindow.Exit, added GameWindow.ExitAsync() and improved error handling. Improved GraphicsContext and NativeGLWindow APIs (construction in constructor). Made ContextHandle public.
This commit is contained in:
parent
084a561ba8
commit
e10d37418f
|
@ -4,7 +4,7 @@ using System.Text;
|
|||
|
||||
namespace OpenTK
|
||||
{
|
||||
internal class ContextHandle : /*System.Runtime.InteropServices.SafeHandle,*/ IComparable<ContextHandle>
|
||||
public class ContextHandle : /*System.Runtime.InteropServices.SafeHandle,*/ IComparable<ContextHandle>
|
||||
{
|
||||
IntPtr handle;
|
||||
public IntPtr Handle { get { return handle; } }
|
||||
|
|
|
@ -81,7 +81,7 @@ namespace OpenTK
|
|||
/// <param name="width">The Width of the DisplayMode in pixels.</param>
|
||||
/// <param name="height">The Height of the DisplayMode in pixels.</param>
|
||||
public DisplayMode(int width, int height)
|
||||
: this(width, height, DisplayDevice.PrimaryDisplay.BitsPerPixel, 16, 0, 0, 2, false, false, false, 0.0f)
|
||||
: this(width, height, DisplayDevice.Default.BitsPerPixel, 16, 0, 0, 2, false, false, false, 0.0f)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -125,12 +125,12 @@ namespace OpenTK
|
|||
|
||||
#region --- Public Properties ---
|
||||
#if false
|
||||
#region public int ColorFormat
|
||||
#region public int ColorDepth
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Graphics.ColorMode that describes the color format of this DisplayMode.
|
||||
/// </summary>
|
||||
public ColorMode ColorFormat
|
||||
public ColorMode ColorDepth
|
||||
{
|
||||
get { return color_format; }
|
||||
private set { color_format = value; }
|
||||
|
@ -138,12 +138,12 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
#region public int AuxilliaryColorFormat
|
||||
#region public int AuxilliaryColorDepth
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Graphics.ColorMode that describes the color format of this DisplayMode.
|
||||
/// </summary>
|
||||
public ColorMode AuxilliaryColorFormat
|
||||
public ColorMode AuxilliaryColorDepth
|
||||
{
|
||||
get { return auxilliary_color_format; }
|
||||
private set { auxilliary_color_format = value; }
|
||||
|
@ -296,7 +296,7 @@ namespace OpenTK
|
|||
internal set { this.stencilBits = value; }
|
||||
}
|
||||
|
||||
[Obsolete("Use GraphicsMode.AuxilliaryColorFormat instead.")]
|
||||
[Obsolete("Use GraphicsMode.AuxilliaryColorDepth instead.")]
|
||||
public int AuxBits
|
||||
{
|
||||
get { return this.auxilliary_color_format.BitsPerPixel; }
|
||||
|
|
|
@ -14,6 +14,7 @@ using System.Windows.Forms;
|
|||
|
||||
using OpenTK.Platform;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
|
@ -223,7 +224,26 @@ namespace OpenTK
|
|||
/// </remarks>
|
||||
public GraphicsMode GraphicsMode
|
||||
{
|
||||
get { return (Context as IGLContextInternal).GraphicsMode; }
|
||||
get { return (Context as IGraphicsContextInternal).GraphicsMode; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public Bitmap GrabScreenshot()
|
||||
|
||||
/// <summary>Grabs a screenshot of the frontbuffer contents.</summary>
|
||||
/// <returns>A System.Drawing.Bitmap, containing the contents of the frontbuffer.</returns>
|
||||
public Bitmap GrabScreenshot()
|
||||
{
|
||||
Bitmap bmp = new Bitmap(this.ClientSize.Width, this.ClientSize.Height);
|
||||
System.Drawing.Imaging.BitmapData data =
|
||||
bmp.LockBits(this.ClientRectangle, System.Drawing.Imaging.ImageLockMode.WriteOnly,
|
||||
System.Drawing.Imaging.PixelFormat.Format24bppRgb);
|
||||
GL.ReadPixels(0, 0, this.ClientSize.Width, this.ClientSize.Height, PixelFormat.Bgr, PixelType.UnsignedByte,
|
||||
data.Scan0);
|
||||
bmp.UnlockBits(data);
|
||||
bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -98,24 +98,78 @@ namespace OpenTK
|
|||
|
||||
#region --- Contructors ---
|
||||
|
||||
public GameWindow() : this("OpenTK Game Window", 640, 480, null, GraphicsMode.Default) { }
|
||||
#region public GameWindow()
|
||||
|
||||
public GameWindow(string title) : this(title, 640, 480, null, GraphicsMode.Default) { }
|
||||
/// <summary>Constructs a new GameWindow with sensible default attributes..</summary>
|
||||
public GameWindow()
|
||||
: this(640, 480, GraphicsMode.Default, "OpenTK Game Window", 0, DisplayDevice.Default) { }
|
||||
|
||||
public GameWindow(string title, int width, int height)
|
||||
: this(title, width, height, null, GraphicsMode.Default) { }
|
||||
#endregion
|
||||
|
||||
public GameWindow(string title, int width, int height, GraphicsMode format)
|
||||
: this(title, width, height, null, format) { }
|
||||
#region public GameWindow(int width, int height)
|
||||
|
||||
public GameWindow(string title, DisplayResolution resolution)
|
||||
: this(title, resolution.Width, resolution.Height, resolution, GraphicsMode.Default) { }
|
||||
/// <summary>Constructs a new GameWindow with the specified attributes.</summary>
|
||||
/// <param name="width">The width of the GameWindow in pixels.</param>
|
||||
/// <param name="height">The height of the GameWindow in pixels.</param>
|
||||
public GameWindow(int width, int height)
|
||||
: this(width, height, GraphicsMode.Default, "OpenTK Game Window", 0, DisplayDevice.Default) { }
|
||||
|
||||
public GameWindow(string title, DisplayResolution resolution, GraphicsMode format)
|
||||
: this(title, resolution.Width, resolution.Height, resolution, format) { }
|
||||
#endregion
|
||||
|
||||
GameWindow(string title, int width, int height, DisplayResolution resolution, GraphicsMode format)
|
||||
#region public GameWindow(int width, int height, GraphicsMode mode)
|
||||
|
||||
/// <summary>Constructs a new GameWindow with the specified attributes.</summary>
|
||||
/// <param name="width">The width of the GameWindow in pixels.</param>
|
||||
/// <param name="height">The height of the GameWindow in pixels.</param>
|
||||
/// <param name="mode">The OpenTK.Graphics.GraphicsMode of the GameWindow.</param>
|
||||
public GameWindow(int width, int height, GraphicsMode mode)
|
||||
: this(width, height, mode, "OpenTK Game Window", 0, DisplayDevice.Default) { }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GameWindow(int width, int height, GraphicsMode mode, string title)
|
||||
|
||||
/// <summary>Constructs a new GameWindow with the specified attributes.</summary>
|
||||
/// <param name="width">The width of the GameWindow in pixels.</param>
|
||||
/// <param name="height">The height of the GameWindow in pixels.</param>
|
||||
/// <param name="mode">The OpenTK.Graphics.GraphicsMode of the GameWindow.</param>
|
||||
/// <param name="title">The title of the GameWindow.</param>
|
||||
public GameWindow(int width, int height, GraphicsMode mode, string title)
|
||||
: this(width, height, mode, title, 0, DisplayDevice.Default) { }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GameWindow(int width, int height, GraphicsMode mode, string title, GameWindowFlags options)
|
||||
|
||||
/// <summary>Constructs a new GameWindow with the specified attributes.</summary>
|
||||
/// <param name="width">The width of the GameWindow in pixels.</param>
|
||||
/// <param name="height">The height of the GameWindow in pixels.</param>
|
||||
/// <param name="mode">The OpenTK.Graphics.GraphicsMode of the GameWindow.</param>
|
||||
/// <param name="title">The title of the GameWindow.</param>
|
||||
/// <param name="options">GameWindow options regarding window appearance and behavior.</param>
|
||||
public GameWindow(int width, int height, GraphicsMode mode, string title, GameWindowFlags options)
|
||||
: this(width, height, mode, title, options, DisplayDevice.Default) { }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GameWindow(int width, int height, GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device)
|
||||
|
||||
/// <summary>Constructs a new GameWindow with the specified attributes.</summary>
|
||||
/// <param name="width">The width of the GameWindow in pixels.</param>
|
||||
/// <param name="height">The height of the GameWindow in pixels.</param>
|
||||
/// <param name="mode">The OpenTK.Graphics.GraphicsMode of the GameWindow.</param>
|
||||
/// <param name="title">The title of the GameWindow.</param>
|
||||
/// <param name="options">GameWindow options regarding window appearance and behavior.</param>
|
||||
/// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the GameWindow in.</param>
|
||||
public GameWindow(int width, int height, GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device)
|
||||
{
|
||||
if (width <= 0) throw new ArgumentOutOfRangeException("width", "Must be greater than zero.");
|
||||
if (height <= 0) throw new ArgumentOutOfRangeException("width", "Must be greater than zero.");
|
||||
if (mode == null)
|
||||
mode = GraphicsMode.Default;
|
||||
if (device == null)
|
||||
device = DisplayDevice.Default;
|
||||
|
||||
if (Configuration.RunningOnWindows)
|
||||
glWindow = new OpenTK.Platform.Windows.WinGLNative();
|
||||
else if (Configuration.RunningOnX11)
|
||||
|
@ -126,37 +180,44 @@ namespace OpenTK
|
|||
|
||||
glWindow.Destroy += glWindow_Destroy;
|
||||
|
||||
// TODO: GraphicsContext is created inside this call.
|
||||
glWindow.CreateWindow(width, height);//, format, out glContext);
|
||||
try
|
||||
{
|
||||
this.glContext = new GraphicsContext(format, this.WindowInfo);
|
||||
glWindow.CreateWindow(width, height, mode, out glContext);
|
||||
Debug.Print("1");
|
||||
glContext.MakeCurrent();
|
||||
Debug.Print("2");
|
||||
(glContext as IGraphicsContextInternal).LoadAll();
|
||||
Debug.Print("3");
|
||||
}
|
||||
catch (GraphicsContextException e)
|
||||
//catch (GraphicsContextException e)
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Print(e.ToString());
|
||||
glWindow.DestroyWindow();
|
||||
throw;
|
||||
}
|
||||
|
||||
this.Title = title;
|
||||
|
||||
if (resolution != null)
|
||||
|
||||
if ((options & GameWindowFlags.Fullscreen) != 0)
|
||||
{
|
||||
DisplayDevice.PrimaryDisplay.ChangeResolution(resolution);
|
||||
device.ChangeResolution(width, height, mode.ColorDepth.BitsPerPixel, 0);
|
||||
this.Fullscreen = true;
|
||||
}
|
||||
|
||||
|
||||
this.VSync = VSyncMode.On; //VSyncMode.Adaptive;
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new GameWindow, and opens a render window with the specified DisplayMode.
|
||||
/// </summary>
|
||||
/// <param name="mode">The DisplayMode of the GameWindow.</param>
|
||||
[Obsolete]
|
||||
public GameWindow(DisplayMode mode)
|
||||
: this("OpenTK Game Window", mode.Width, mode.Height,
|
||||
mode.Fullscreen ? DisplayDevice.PrimaryDisplay.SelectResolution(
|
||||
mode.Width, mode.Height, mode.Color.BitsPerPixel, 0) : null, mode.ToGraphicsMode()) { }
|
||||
: this(mode.Width, mode.Height, mode.ToGraphicsMode(), "OpenTK Game Window", mode.Fullscreen ? GameWindowFlags.Fullscreen : 0) { }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new GameWindow with the specified title, and opens a render window with the
|
||||
|
@ -166,9 +227,13 @@ namespace OpenTK
|
|||
/// <param name="title">The Title of the GameWindow.</param>
|
||||
[Obsolete]
|
||||
public GameWindow(DisplayMode mode, string title)
|
||||
: this(title, mode.Width, mode.Height, mode.ToGraphicsMode())
|
||||
{
|
||||
}
|
||||
: this(mode.Width, mode.Height, mode.ToGraphicsMode(), title, mode.Fullscreen ? GameWindowFlags.Fullscreen : 0) { }
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Private Methods ---
|
||||
|
||||
#region void glWindow_Destroy(object sender, EventArgs e)
|
||||
|
||||
void glWindow_Destroy(object sender, EventArgs e)
|
||||
{
|
||||
|
@ -178,7 +243,27 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
#region --- INativeGLWindow Members ---
|
||||
#region void ExitInternal()
|
||||
|
||||
/// <internal />
|
||||
/// <summary>Stops the main loop.</summary>
|
||||
void ExitInternal()
|
||||
{
|
||||
//Debug.Print("Firing GameWindowExitException");
|
||||
throw new GameWindowExitException();
|
||||
}
|
||||
|
||||
void CallExitInternal(GameWindow sender, UpdateFrameEventArgs e)
|
||||
{
|
||||
UpdateFrame -= CallExitInternal;
|
||||
sender.ExitInternal();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Public Methods ---
|
||||
|
||||
#region public virtual void Exit()
|
||||
|
||||
|
@ -223,24 +308,6 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
#region void ExitInternal()
|
||||
|
||||
/// <internal />
|
||||
/// <summary>Stops the main loop.</summary>
|
||||
void ExitInternal()
|
||||
{
|
||||
//Debug.Print("Firing GameWindowExitException");
|
||||
throw new GameWindowExitException();
|
||||
}
|
||||
|
||||
void CallExitInternal(GameWindow sender, UpdateFrameEventArgs e)
|
||||
{
|
||||
UpdateFrame -= CallExitInternal;
|
||||
sender.ExitInternal();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public bool IsIdle
|
||||
|
||||
/// <summary>
|
||||
|
@ -342,7 +409,7 @@ namespace OpenTK
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#if false
|
||||
|
||||
#region public IInputDriver InputDriver
|
||||
|
@ -379,10 +446,6 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Public Methods ---
|
||||
|
||||
#region void Run()
|
||||
|
||||
/// <summary>
|
||||
|
@ -446,15 +509,15 @@ namespace OpenTK
|
|||
//sleep_granularity = System.Math.Round(1000.0 * update_watch.Elapsed.TotalSeconds / test_times, MidpointRounding.AwayFromZero) / 1000.0;
|
||||
//update_watch.Reset(); // We don't want to affect the first UpdateFrame!
|
||||
|
||||
//try
|
||||
//{
|
||||
OnLoadInternal(EventArgs.Empty);
|
||||
//}
|
||||
//catch (Exception e)
|
||||
//{
|
||||
// Trace.WriteLine(String.Format("OnLoad failed: {0}", e.ToString()));
|
||||
// return;
|
||||
//}
|
||||
try
|
||||
{
|
||||
OnLoadInternal(EventArgs.Empty);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Trace.WriteLine(String.Format("OnLoad failed: {0}", e.ToString()));
|
||||
return;
|
||||
}
|
||||
|
||||
//Debug.Print("Elevating priority.");
|
||||
//Thread.CurrentThread.Priority = ThreadPriority.AboveNormal;
|
||||
|
@ -678,6 +741,7 @@ namespace OpenTK
|
|||
/// <param name="e"></param>
|
||||
private void OnLoadInternal(EventArgs e)
|
||||
{
|
||||
Debug.Print("Firing internal load event.");
|
||||
if (MustResize)
|
||||
{
|
||||
resizeEventArgs.Width = glWindow.Width;
|
||||
|
@ -1152,7 +1216,7 @@ namespace OpenTK
|
|||
/// <param name="e">Contains information about the Resize event.</param>
|
||||
private void OnResizeInternal(ResizeEventArgs e)
|
||||
{
|
||||
Debug.Print("Firing GameWindow.Resize event: {0}.", e.ToString());
|
||||
Debug.Print("Firing internal resize event: {0}.", e.ToString());
|
||||
|
||||
this.width = e.Width;
|
||||
this.height = e.Height;
|
||||
|
@ -1377,4 +1441,16 @@ Alternatively, you can disable the ""Just my code"" debugging mode (""Tools->Opt
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public enum GameWindowFlags
|
||||
|
||||
/// <summary>Enumerates available GameWindow construction options.</summary>
|
||||
[Flags]
|
||||
public enum GameWindowFlags
|
||||
{
|
||||
/// <summary>Indicates that the GameWindow should cover the whole screen.</summary>
|
||||
Fullscreen = 1,
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
|
@ -182,15 +182,12 @@ namespace OpenTK.Graphics
|
|||
#region public void ChangeResolution(DisplayResolution resolution)
|
||||
|
||||
/// <summary>Changes the resolution of the DisplayDevice.</summary>
|
||||
/// <param name="width">The new width of the DisplayDevice.</param>
|
||||
/// <param name="height">The new height of the DisplayDevice.</param>
|
||||
/// <param name="bitsPerPixel">The new bits per pixel of the DisplayDevice.</param>
|
||||
/// <param name="refreshRate">The new refresh rate of the DisplayDevice.</param>
|
||||
/// <param name="resolution">The resolution to set. <see cref="DisplayDevice.SelectResolution"/></param>
|
||||
/// <exception cref="GraphicsModeException">Thrown if the requested resolution could not be set.</exception>
|
||||
public void ChangeResolution(DisplayResolution resolution)
|
||||
{
|
||||
if (resolution == null)
|
||||
throw new ArgumentNullException("resulotion", "Must be a valid resolution.");
|
||||
throw new ArgumentNullException("resolution", "Must be a valid resolution.");
|
||||
if (resolution == current_resolution)
|
||||
return;
|
||||
|
||||
|
@ -210,6 +207,21 @@ namespace OpenTK.Graphics
|
|||
|
||||
#endregion
|
||||
|
||||
#region public void ChangeResolution(DisplayResolution resolution)
|
||||
|
||||
/// <summary>Changes the resolution of the DisplayDevice.</summary>
|
||||
/// <param name="width">The new width of the DisplayDevice.</param>
|
||||
/// <param name="height">The new height of the DisplayDevice.</param>
|
||||
/// <param name="bitsPerPixel">The new bits per pixel of the DisplayDevice.</param>
|
||||
/// <param name="refreshRate">The new refresh rate of the DisplayDevice.</param>
|
||||
/// <exception cref="GraphicsModeException">Thrown if the requested resolution could not be set.</exception>
|
||||
public void ChangeResolution(int width, int height, int bitsPerPixel, float refreshRate)
|
||||
{
|
||||
this.ChangeResolution(this.SelectResolution(width, height, bitsPerPixel, refreshRate));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void RestoreResolution()
|
||||
|
||||
/// <summary>Restores the original resolution of the DisplayDevice.</summary>
|
||||
|
@ -251,10 +263,10 @@ namespace OpenTK.Graphics
|
|||
|
||||
#endregion
|
||||
|
||||
#region public static DisplayDevice PrimaryDisplay
|
||||
#region public static DisplayDevice Default
|
||||
|
||||
/// <summary>Gets the primary display of this system.</summary>
|
||||
public static DisplayDevice PrimaryDisplay { get { return primary_display; } }
|
||||
/// <summary>Gets the default (primary) display of this system.</summary>
|
||||
public static DisplayDevice Default { get { return primary_display; } }
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
|
||||
using OpenTK.Platform;
|
||||
|
||||
|
@ -17,33 +18,45 @@ namespace OpenTK.Graphics
|
|||
/// <summary>
|
||||
/// Represents and provides methods to manipulate an OpenGL render context.
|
||||
/// </summary>
|
||||
public sealed class GraphicsContext : IGraphicsContext, IGLContextInternal, IGLContextCreationHack
|
||||
public sealed class GraphicsContext : IGraphicsContext, IGraphicsContextInternal, IGLContextCreationHack
|
||||
{
|
||||
IGraphicsContext implementation; // The actual render context implementation for the underlying platform.
|
||||
List<IDisposable> dispose_queue = new List<IDisposable>();
|
||||
bool disposed;
|
||||
|
||||
static bool share_contexts = true;
|
||||
static bool direct_rendering = true;
|
||||
static object context_lock = new object();
|
||||
// Maps OS-specific context handles to GraphicsContext weak references.
|
||||
static Dictionary<ContextHandle, WeakReference> available_contexts =
|
||||
new Dictionary<ContextHandle, WeakReference>(); // Contains all available OpenGL contexts.
|
||||
new Dictionary<ContextHandle, WeakReference>();
|
||||
|
||||
#region public GraphicsContext(DisplayMode mode, IWindowInfo window)
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new GraphicsContext with the specified DisplayMode, and bound to the specified IWindowInfo.
|
||||
/// </summary>
|
||||
/// <summary>This method is obsolete.</summary>
|
||||
/// <param name="mode"></param>
|
||||
/// <param name="window"></param>
|
||||
public GraphicsContext(DisplayMode mode, IWindowInfo window)
|
||||
: this(mode.ToGraphicsMode(), window)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsContext(GraphicsMode format, IWindowInfo window)
|
||||
|
||||
/// <summary>Constructs a new GraphicsContext with the specified format, and attaches it to the specified window.</summary>
|
||||
/// <param name="format">The OpenTK.Graphics.GraphicsMode of the GraphicsContext.</param>
|
||||
/// <param name="window">The OpenTK.Platform.IWindowInfo to attach the GraphicsContext to.</param>
|
||||
public GraphicsContext(GraphicsMode format, IWindowInfo window)
|
||||
{
|
||||
//if (available_contexts.Count == 0)
|
||||
// available_contexts.Add(IntPtr.Zero, new WeakReference(null));
|
||||
IGraphicsContext share = null;
|
||||
if (window == null) throw new ArgumentNullException("window", "Must point to a valid window.");
|
||||
|
||||
Debug.Print("Creating GraphicsContext.");
|
||||
Debug.Indent();
|
||||
Debug.Print("GraphicsMode: {0}", format);
|
||||
Debug.Print("IWindowInfo: {0}", window);
|
||||
|
||||
IGraphicsContext shareContext = null;
|
||||
if (GraphicsContext.ShareContexts)
|
||||
{
|
||||
lock (context_lock)
|
||||
|
@ -51,18 +64,22 @@ namespace OpenTK.Graphics
|
|||
// A small hack to create a shared context with the first available context.
|
||||
foreach (WeakReference r in GraphicsContext.available_contexts.Values)
|
||||
{
|
||||
share = (IGraphicsContext)r.Target;
|
||||
shareContext = (IGraphicsContext)r.Target;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Configuration.RunningOnWindows)
|
||||
implementation = new OpenTK.Platform.Windows.WinGLContext(format, window, share);
|
||||
implementation = new OpenTK.Platform.Windows.WinGLContext(format, window, shareContext);
|
||||
else if (Configuration.RunningOnX11)
|
||||
implementation = new OpenTK.Platform.X11.X11GLContext();
|
||||
implementation = new OpenTK.Platform.X11.X11GLContext(format, window, shareContext, DirectRendering);
|
||||
else
|
||||
throw new PlatformNotSupportedException("Your platform is not supported currently. Please, refer to http://www.opentk.com for more information.");
|
||||
throw new PlatformNotSupportedException(
|
||||
"Your platform is not currently supported. Please, check http://www.opentk.com for an updated version.");
|
||||
|
||||
available_contexts.Add((this as IGraphicsContextInternal).Context, new WeakReference(this));
|
||||
//(implementation as IGraphicsContextInternal).LoadAll();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -77,7 +94,7 @@ namespace OpenTK.Graphics
|
|||
void ContextDestroyed(IGraphicsContext context, EventArgs e)
|
||||
{
|
||||
this.Destroy -= ContextDestroyed;
|
||||
available_contexts.Remove(((IGLContextInternal)this).Context);
|
||||
available_contexts.Remove(((IGraphicsContextInternal)this).Context);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -97,10 +114,12 @@ namespace OpenTK.Graphics
|
|||
get
|
||||
{
|
||||
if (available_contexts.Count > 0)
|
||||
return (GraphicsContext)available_contexts[GetCurrentContext()].Target;
|
||||
//return (GraphicsContext)available_contexts[((IGLContextInternal)available_contexts[IntPtr.Zero].Target).GetCurrentContext()].Target;
|
||||
{
|
||||
ContextHandle handle = GetCurrentContext();
|
||||
if (handle.Handle != IntPtr.Zero)
|
||||
return (GraphicsContext)available_contexts[handle].Target;
|
||||
}
|
||||
return null;
|
||||
//return (GraphicsContext)available_contexts[StaticGetCurrentContext().ToInt64()].Target;
|
||||
}
|
||||
set
|
||||
{
|
||||
|
@ -115,7 +134,7 @@ namespace OpenTK.Graphics
|
|||
|
||||
#region public static bool ShareContexts
|
||||
|
||||
/// <summary>Gets or sets a System.Boolean, indicating whether GLContexts are shared</summary>
|
||||
/// <summary>Gets or sets a System.Boolean, indicating whether GraphicsContext resources are shared</summary>
|
||||
/// <remarks>
|
||||
/// <para>If ShareContexts is true, new GLContexts will share resources. If this value is
|
||||
/// false, new GLContexts will not share resources.</para>
|
||||
|
@ -125,6 +144,27 @@ namespace OpenTK.Graphics
|
|||
|
||||
#endregion
|
||||
|
||||
#region public static bool DirectRendering
|
||||
|
||||
/// <summary>Gets or sets a System.Boolean, indicating whether GraphicsContexts will perform direct rendering.</summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// If DirectRendering is true, new contexts will be constructed with direct rendering capabilities, if possible.
|
||||
/// If DirectRendering is false, new contexts will be constructed with indirect rendering capabilities.
|
||||
/// </para>
|
||||
/// <para>This property does not affect existing GraphicsContexts, unless they are recreated.</para>
|
||||
/// <para>
|
||||
/// This property is ignored on Operating Systems without support for indirect rendering, like Windows and OS X.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public static bool DirectRendering
|
||||
{
|
||||
get { return direct_rendering; }
|
||||
set { direct_rendering = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public static AvailableDisplayFormats
|
||||
|
||||
|
||||
|
@ -171,10 +211,10 @@ namespace OpenTK.Graphics
|
|||
/// <seealso cref="CreateContext(bool)"/>
|
||||
public void CreateContext(bool direct, IGraphicsContext source)
|
||||
{
|
||||
implementation.CreateContext(direct, source);
|
||||
this.Destroy += ContextDestroyed;
|
||||
|
||||
available_contexts.Add((this as IGLContextInternal).Context, new WeakReference(this));
|
||||
available_contexts.Add((this as IGraphicsContextInternal).Context, new WeakReference(this));
|
||||
|
||||
//OpenTK.Graphics.OpenGL.GL.Clear(OpenTK.Graphics.OpenGL.ClearBufferMask.ColorBufferBit);
|
||||
//if (StaticGetCurrentContext == null)
|
||||
// StaticGetCurrentContext = implementation.GetCurrentContext;
|
||||
|
@ -227,29 +267,37 @@ namespace OpenTK.Graphics
|
|||
|
||||
#region --- IGLContextInternal Members ---
|
||||
|
||||
/// <summary>
|
||||
/// Gets a handle to the OpenGL rendering context.
|
||||
/// </summary>
|
||||
ContextHandle IGLContextInternal.Context
|
||||
#region void LoadAll()
|
||||
|
||||
void IGraphicsContextInternal.LoadAll()
|
||||
{
|
||||
get { return ((IGLContextInternal)implementation).Context; }
|
||||
(implementation as IGraphicsContextInternal).LoadAll();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <internal />
|
||||
/// <summary>Gets a handle to the OpenGL rendering context.</summary>
|
||||
ContextHandle IGraphicsContextInternal.Context
|
||||
{
|
||||
get { return ((IGraphicsContextInternal)implementation).Context; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the IWindowInfo describing the window associated with this context.
|
||||
/// </summary>
|
||||
IWindowInfo IGLContextInternal.Info
|
||||
IWindowInfo IGraphicsContextInternal.Info
|
||||
{
|
||||
get { return (implementation as IGLContextInternal).Info; }
|
||||
get { return (implementation as IGraphicsContextInternal).Info; }
|
||||
//internal set { (implementation as IGLContextInternal).Info = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the DisplayMode of the context.
|
||||
/// </summary>
|
||||
GraphicsMode IGLContextInternal.GraphicsMode
|
||||
GraphicsMode IGraphicsContextInternal.GraphicsMode
|
||||
{
|
||||
get { return (implementation as IGLContextInternal).GraphicsMode; }
|
||||
get { return (implementation as IGraphicsContextInternal).GraphicsMode; }
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
|
@ -266,7 +314,7 @@ namespace OpenTK.Graphics
|
|||
/// Registers an OpenGL resource for disposal.
|
||||
/// </summary>
|
||||
/// <param name="resource">The OpenGL resource to dispose.</param>
|
||||
void IGLContextInternal.RegisterForDisposal(IDisposable resource)
|
||||
void IGraphicsContextInternal.RegisterForDisposal(IDisposable resource)
|
||||
{
|
||||
GC.KeepAlive(resource);
|
||||
dispose_queue.Add(resource);
|
||||
|
@ -275,7 +323,7 @@ namespace OpenTK.Graphics
|
|||
/// <summary>
|
||||
/// Disposes all registered OpenGL resources.
|
||||
/// </summary>
|
||||
void IGLContextInternal.DisposeResources()
|
||||
void IGraphicsContextInternal.DisposeResources()
|
||||
{
|
||||
foreach (IDisposable resource in dispose_queue)
|
||||
resource.Dispose();
|
||||
|
@ -287,9 +335,9 @@ namespace OpenTK.Graphics
|
|||
/// Returns the display modes supported by the current opengl context.
|
||||
/// </summary>
|
||||
/// <returns>An IEnumerable containing all supported display modes.</returns>
|
||||
IEnumerable<DisplayMode> IGLContextInternal.GetDisplayModes()
|
||||
IEnumerable<DisplayMode> IGraphicsContextInternal.GetDisplayModes()
|
||||
{
|
||||
return (implementation as IGLContextInternal).GetDisplayModes();
|
||||
return (implementation as IGraphicsContextInternal).GetDisplayModes();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -301,9 +349,9 @@ namespace OpenTK.Graphics
|
|||
/// available in the current opengl context.
|
||||
/// </returns>
|
||||
/// <see cref="Marshal.GetDelegateForFunctionPointer"/>
|
||||
IntPtr IGLContextInternal.GetAddress(string function)
|
||||
IntPtr IGraphicsContextInternal.GetAddress(string function)
|
||||
{
|
||||
return (implementation as IGLContextInternal).GetAddress(function);
|
||||
return (implementation as IGraphicsContextInternal).GetAddress(function);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace OpenTK.Graphics
|
|||
/// <summary>Constructs a new GraphicsFormat from the given GraphicsFormat.</summary>
|
||||
/// <param name="mode"></param>
|
||||
internal GraphicsMode(GraphicsMode mode)
|
||||
: this(mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo) { }
|
||||
: this(mode.ColorDepth, mode.Depth, mode.Stencil, mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo) { }
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -40,20 +40,20 @@ namespace OpenTK.Graphics
|
|||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsFormat(ColorFormat color)
|
||||
#region public GraphicsFormat(ColorDepth color)
|
||||
|
||||
/// <summary>Constructs a new GraphicsFormat with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <param name="color">The ColorDepth of the color buffer.</param>
|
||||
public GraphicsMode(ColorDepth color)
|
||||
: this(color, Default.Depth, Default.Stencil, Default.Samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsFormat(ColorFormat color, int depth)
|
||||
#region public GraphicsFormat(ColorDepth color, int depth)
|
||||
|
||||
/// <summary>Constructs a new GraphicsFormat with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <param name="color">The ColorDepth of the color buffer.</param>
|
||||
/// <param name="depth">The number of bits in the depth buffer.</param>
|
||||
public GraphicsMode(ColorDepth color, int depth)
|
||||
: this(color, depth, Default.Stencil, Default.Samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
|
||||
|
@ -61,10 +61,10 @@ namespace OpenTK.Graphics
|
|||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsFormat(ColorFormat color, int depth, int stencil)
|
||||
#region public GraphicsFormat(ColorDepth color, int depth, int stencil)
|
||||
|
||||
/// <summary>Constructs a new GraphicsFormat with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <param name="color">The ColorDepth 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(ColorDepth color, int depth, int stencil)
|
||||
|
@ -73,10 +73,10 @@ namespace OpenTK.Graphics
|
|||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsFormat(ColorFormat color, int depth, int stencil, int samples)
|
||||
#region public GraphicsFormat(ColorDepth color, int depth, int stencil, int samples)
|
||||
|
||||
/// <summary>Constructs a new GraphicsFormat with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <param name="color">The ColorDepth 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>
|
||||
|
@ -86,28 +86,28 @@ namespace OpenTK.Graphics
|
|||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsFormat(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum)
|
||||
#region public GraphicsFormat(ColorDepth color, int depth, int stencil, int samples, ColorDepth accum)
|
||||
|
||||
/// <summary>Constructs a new GraphicsFormat with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <param name="color">The ColorDepth 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="accum">The ColorDepth of the accumilliary buffer.</param>
|
||||
public GraphicsMode(ColorDepth color, int depth, int stencil, int samples, ColorDepth accum)
|
||||
: this(color, depth, stencil, samples, accum, Default.Buffers, Default.Stereo)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsFormat(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers)
|
||||
#region public GraphicsFormat(ColorDepth color, int depth, int stencil, int samples, ColorDepth accum, int buffers)
|
||||
|
||||
/// <summary>Constructs a new GraphicsFormat with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <param name="color">The ColorDepth 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="accum">The ColorDepth 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(ColorDepth color, int depth, int stencil, int samples, ColorDepth accum, int buffers)
|
||||
: this(color, depth, stencil, samples, accum, buffers, Default.Stereo)
|
||||
|
@ -115,14 +115,14 @@ namespace OpenTK.Graphics
|
|||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsFormat(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo)
|
||||
#region public GraphicsFormat(ColorDepth color, int depth, int stencil, int samples, ColorDepth accum, int buffers, bool stereo)
|
||||
|
||||
/// <summary>Constructs a new GraphicsFormat with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <param name="color">The ColorDepth 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="accum">The ColorDepth of the accumilliary buffer.</param>
|
||||
/// <param name="stereo">Set to true for a GraphicsFormat 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(ColorDepth color, int depth, int stencil, int samples, ColorDepth accum, int buffers, bool stereo)
|
||||
|
@ -132,7 +132,7 @@ namespace OpenTK.Graphics
|
|||
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.ColorFormat = color;
|
||||
this.ColorDepth = color;
|
||||
this.Depth = depth;
|
||||
this.Stencil = stencil;
|
||||
this.AccumulatorFormat = accum;
|
||||
|
@ -146,12 +146,12 @@ namespace OpenTK.Graphics
|
|||
|
||||
#region --- Public Methods ---
|
||||
|
||||
#region public int ColorFormat
|
||||
#region public int ColorDepth
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Graphics.ColorFormat that describes the color format for this GraphicsFormat.
|
||||
/// Gets an OpenTK.Graphics.ColorDepth that describes the color format for this GraphicsFormat.
|
||||
/// </summary>
|
||||
public ColorDepth ColorFormat
|
||||
public ColorDepth ColorDepth
|
||||
{
|
||||
get { return color_format; }
|
||||
private set { color_format = value; }
|
||||
|
@ -162,7 +162,7 @@ namespace OpenTK.Graphics
|
|||
#region public int AccumulatorFormat
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Graphics.ColorFormat that describes the accumulator format for this GraphicsFormat.
|
||||
/// Gets an OpenTK.Graphics.ColorDepth that describes the accumulator format for this GraphicsFormat.
|
||||
/// </summary>
|
||||
public ColorDepth AccumulatorFormat
|
||||
{
|
||||
|
@ -241,7 +241,7 @@ namespace OpenTK.Graphics
|
|||
/// <summary>Returns an OpenTK.GraphicsFormat compatible with the underlying platform.</summary>
|
||||
public static GraphicsMode Default
|
||||
{
|
||||
get { return new GraphicsMode(DisplayDevice.PrimaryDisplay.BitsPerPixel, 16, 0, 0, 0, 2, false); }
|
||||
get { return new GraphicsMode(DisplayDevice.Default.BitsPerPixel, 16, 0, 0, 0, 2, false); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -255,7 +255,7 @@ namespace OpenTK.Graphics
|
|||
public override string ToString()
|
||||
{
|
||||
return String.Format("Color: {0}, Depth: {1}, Stencil: {2}, Samples: {3}, Accum: {4}, Buffers: {5}, Stereo: {6}",
|
||||
ColorFormat, Depth, Stereo, Samples, AccumulatorFormat, Buffers, Stereo);
|
||||
ColorDepth, Depth, Stereo, Samples, AccumulatorFormat, Buffers, Stereo);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -19,15 +19,6 @@ namespace OpenTK.Graphics
|
|||
/// </summary>
|
||||
public interface IGraphicsContext : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates an OpenGL context with the specified direct/indirect rendering mode and sharing state with the
|
||||
/// specified IGraphicsContext.
|
||||
/// </summary>
|
||||
/// <param name="direct">Set to true for direct rendering or false otherwise.</param>
|
||||
/// <param name="source">The source IGraphicsContext to share state from.</param>.
|
||||
/// <seealso cref="CreateContext(bool)"/>
|
||||
void CreateContext(bool direct, IGraphicsContext source);
|
||||
|
||||
/// <summary>Swaps buffers, presenting the rendered scene to the user.</summary>
|
||||
void SwapBuffers();
|
||||
|
||||
|
@ -66,8 +57,23 @@ namespace OpenTK.Graphics
|
|||
// Functions for internal use by OpenTK.
|
||||
// TODO: RegisterForDisposal/DisposeResources for 0.3.15 (GC & OpenGL)
|
||||
// TODO: Remove or move GetDisplayModes to another class.
|
||||
internal interface IGLContextInternal
|
||||
/// <summary>
|
||||
/// Provides methods to create new GraphicsContexts. Should only be used for extending OpenTK.
|
||||
/// </summary>
|
||||
public interface IGraphicsContextInternal
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates an OpenGL context with the specified direct/indirect rendering mode and sharing state with the
|
||||
/// specified IGraphicsContext.
|
||||
/// </summary>
|
||||
/// <param name="direct">Set to true for direct rendering or false otherwise.</param>
|
||||
/// <param name="source">The source IGraphicsContext to share state from.</param>.
|
||||
/// <seealso cref="CreateContext(bool)"/>
|
||||
//void CreateContext(bool direct, IGraphicsContext source);
|
||||
|
||||
/// <summary>Prepares the entry points for OpenGL.</summary>
|
||||
void LoadAll();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a handle to the OpenGL rendering context.
|
||||
/// </summary>
|
||||
|
|
|
@ -4368,13 +4368,13 @@ namespace OpenTK.Graphics.OpenGL
|
|||
}
|
||||
|
||||
public static
|
||||
void CopyPixel(Int32 x, Int32 y, Int32 width, Int32 height, OpenTK.Graphics.OpenGL.PixelCopyType type)
|
||||
void CopyPixels(Int32 x, Int32 y, Int32 width, Int32 height, OpenTK.Graphics.OpenGL.PixelCopyType type)
|
||||
{
|
||||
Delegates.glCopyPixels((Int32)x, (Int32)y, (Int32)width, (Int32)height, (OpenTK.Graphics.OpenGL.PixelCopyType)type);
|
||||
}
|
||||
|
||||
public static
|
||||
void ReadPixel(Int32 x, Int32 y, Int32 width, Int32 height, OpenTK.Graphics.OpenGL.PixelFormat format, OpenTK.Graphics.OpenGL.PixelType type, [Out] IntPtr pixels)
|
||||
void ReadPixels(Int32 x, Int32 y, Int32 width, Int32 height, OpenTK.Graphics.OpenGL.PixelFormat format, OpenTK.Graphics.OpenGL.PixelType type, [Out] IntPtr pixels)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
|
@ -4383,7 +4383,7 @@ namespace OpenTK.Graphics.OpenGL
|
|||
}
|
||||
|
||||
public static
|
||||
void ReadPixel(Int32 x, Int32 y, Int32 width, Int32 height, OpenTK.Graphics.OpenGL.PixelFormat format, OpenTK.Graphics.OpenGL.PixelType type, [In, Out] object pixels)
|
||||
void ReadPixels(Int32 x, Int32 y, Int32 width, Int32 height, OpenTK.Graphics.OpenGL.PixelFormat format, OpenTK.Graphics.OpenGL.PixelType type, [In, Out] object pixels)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
|
@ -4400,7 +4400,7 @@ namespace OpenTK.Graphics.OpenGL
|
|||
}
|
||||
|
||||
public static
|
||||
void DrawPixel(Int32 width, Int32 height, OpenTK.Graphics.OpenGL.PixelFormat format, OpenTK.Graphics.OpenGL.PixelType type, IntPtr pixels)
|
||||
void DrawPixels(Int32 width, Int32 height, OpenTK.Graphics.OpenGL.PixelFormat format, OpenTK.Graphics.OpenGL.PixelType type, IntPtr pixels)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
|
@ -4409,7 +4409,7 @@ namespace OpenTK.Graphics.OpenGL
|
|||
}
|
||||
|
||||
public static
|
||||
void DrawPixel(Int32 width, Int32 height, OpenTK.Graphics.OpenGL.PixelFormat format, OpenTK.Graphics.OpenGL.PixelType type, [In, Out] object pixels)
|
||||
void DrawPixels(Int32 width, Int32 height, OpenTK.Graphics.OpenGL.PixelFormat format, OpenTK.Graphics.OpenGL.PixelType type, [In, Out] object pixels)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -198,8 +198,10 @@ namespace OpenTK.Graphics.OpenGL
|
|||
//TODO: Route GameWindow context creation through GraphicsContext.
|
||||
//if (GraphicsContext.CurrentContext == null)
|
||||
// throw new InvalidOperationException("You must create an OpenGL context before using the GL class.");
|
||||
|
||||
OpenTK.Platform.Utilities.LoadExtensions(glClass);
|
||||
if (GraphicsContext.CurrentContext != null)
|
||||
OpenTK.Platform.Utilities.LoadExtensions(glClass);
|
||||
else
|
||||
throw new InvalidOperationException("No GraphicsContext available in the calling thread.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -332,16 +334,16 @@ namespace OpenTK.Graphics.OpenGL
|
|||
|
||||
#endregion
|
||||
|
||||
#region public static bool SupportsFunction(Type function)
|
||||
#region static bool SupportsFunction(Type function)
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a given OpenGL function is supported by the current context
|
||||
/// </summary>
|
||||
/// <param name="function">The name of the OpenGL function (e.g. glShaderSource)</param>
|
||||
/// <param name="extension">The name of the extension catagory (e.g. ARB, EXT, ATI, ...)</param>
|
||||
/// <param name="method">The System.Reflection.MethodInfo of the OpenGL function.</param>
|
||||
/// <returns>True if the function is supported, false otherwise</returns>
|
||||
public static bool SupportsFunction(MethodInfo method)
|
||||
static bool SupportsFunction(MethodInfo method)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
lock (gl_lock)
|
||||
{
|
||||
/*
|
||||
|
|
|
@ -20,8 +20,7 @@ namespace OpenTK.Platform
|
|||
/// </summary>
|
||||
internal interface INativeGLWindow : IResizable, IDisposable
|
||||
{
|
||||
//void CreateWindow(int width, int height, DisplayMode mode, out IGraphicsContext context);
|
||||
void CreateWindow(int width, int height);//, GraphicsMode mode, out IGraphicsContext context);
|
||||
void CreateWindow(int width, int height, GraphicsMode mode, out IGraphicsContext context);
|
||||
void DestroyWindow();
|
||||
void ProcessEvents();
|
||||
void PointToClient(ref System.Drawing.Point p);
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace OpenTK.Platform.Windows
|
|||
/// Provides methods to create and control an opengl context on the Windows platform.
|
||||
/// This class supports OpenTK, and is not intended for use by OpenTK programs.
|
||||
/// </summary>
|
||||
internal sealed class WinGLContext : IGraphicsContext, IGLContextInternal, IGLContextCreationHack
|
||||
internal sealed class WinGLContext : IGraphicsContext, IGraphicsContextInternal, IGLContextCreationHack
|
||||
{
|
||||
IntPtr deviceContext;
|
||||
ContextHandle renderContext;
|
||||
|
@ -60,7 +60,7 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
GraphicsMode SelectFormat(GraphicsMode format)
|
||||
{
|
||||
using (WinGLNative native = new WinGLNative(16, 16))
|
||||
using (WinGLNative native = new WinGLNative())
|
||||
//using (WinGLContext context = new WinGLContext(format, native.WindowInfo, null))
|
||||
{
|
||||
// Find the best multisampling mode.
|
||||
|
@ -90,18 +90,10 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
Debug.WriteLine(String.Format("done! (id: {0})", renderContext));
|
||||
|
||||
Wgl.Imports.MakeCurrent(deviceContext, renderContext);
|
||||
Wgl.LoadAll();
|
||||
GL.LoadAll();
|
||||
Glu.LoadAll();
|
||||
|
||||
vsync_supported = Wgl.Arb.SupportsExtension(this, "WGL_EXT_swap_control") &&
|
||||
Wgl.Load("wglGetSwapIntervalEXT") && Wgl.Load("wglSwapIntervalEXT");
|
||||
|
||||
if (sharedContext != null)
|
||||
{
|
||||
Debug.Print("Sharing state with context {0}", sharedContext.ToString());
|
||||
Wgl.Imports.ShareLists(renderContext, (sharedContext as IGLContextInternal).Context);
|
||||
Wgl.Imports.ShareLists(renderContext, (sharedContext as IGraphicsContextInternal).Context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,9 +194,23 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#region --- IGLContextInternal Members ---
|
||||
|
||||
#region void LoadAll()
|
||||
|
||||
void IGraphicsContextInternal.LoadAll()
|
||||
{
|
||||
Wgl.LoadAll();
|
||||
GL.LoadAll();
|
||||
Glu.LoadAll();
|
||||
|
||||
vsync_supported = Wgl.Arb.SupportsExtension(this, "WGL_EXT_swap_control") &&
|
||||
Wgl.Load("wglGetSwapIntervalEXT") && Wgl.Load("wglSwapIntervalEXT");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ContextHandle IGLContextInternal.Context
|
||||
|
||||
ContextHandle IGLContextInternal.Context
|
||||
ContextHandle IGraphicsContextInternal.Context
|
||||
{
|
||||
get { return renderContext; }
|
||||
}
|
||||
|
@ -213,7 +219,7 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#region IWindowInfo IGLContextInternal.Info
|
||||
|
||||
IWindowInfo IGLContextInternal.Info
|
||||
IWindowInfo IGraphicsContextInternal.Info
|
||||
{
|
||||
get { return (IWindowInfo)windowInfo; }
|
||||
}
|
||||
|
@ -222,7 +228,7 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#region GraphicsMode IGLContextInternal.GraphicsMode
|
||||
|
||||
GraphicsMode IGLContextInternal.GraphicsMode
|
||||
GraphicsMode IGraphicsContextInternal.GraphicsMode
|
||||
{
|
||||
get { return format; }
|
||||
}
|
||||
|
@ -249,7 +255,7 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#region void IGLContextInternal.RegisterForDisposal(IDisposable resource)
|
||||
|
||||
void IGLContextInternal.RegisterForDisposal(IDisposable resource)
|
||||
void IGraphicsContextInternal.RegisterForDisposal(IDisposable resource)
|
||||
{
|
||||
throw new NotSupportedException("Use OpenTK.GraphicsContext instead.");
|
||||
}
|
||||
|
@ -258,7 +264,7 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#region void IGLContextInternal.DisposeResources()
|
||||
|
||||
void IGLContextInternal.DisposeResources()
|
||||
void IGraphicsContextInternal.DisposeResources()
|
||||
{
|
||||
throw new NotSupportedException("Use OpenTK.GraphicsContext instead.");
|
||||
}
|
||||
|
@ -283,14 +289,14 @@ namespace OpenTK.Platform.Windows
|
|||
pixelFormat.Flags =
|
||||
PixelFormatDescriptorFlags.SUPPORT_OPENGL |
|
||||
PixelFormatDescriptorFlags.DRAW_TO_WINDOW;
|
||||
pixelFormat.ColorBits = (byte)(format.ColorFormat.Red + format.ColorFormat.Green + format.ColorFormat.Blue);
|
||||
pixelFormat.ColorBits = (byte)(format.ColorDepth.Red + format.ColorDepth.Green + format.ColorDepth.Blue);
|
||||
|
||||
pixelFormat.PixelType = format.ColorFormat.IsIndexed ? PixelType.INDEXED : PixelType.RGBA;
|
||||
pixelFormat.PixelType = format.ColorDepth.IsIndexed ? PixelType.INDEXED : PixelType.RGBA;
|
||||
pixelFormat.PixelType = PixelType.RGBA;
|
||||
pixelFormat.RedBits = (byte)format.ColorFormat.Red;
|
||||
pixelFormat.GreenBits = (byte)format.ColorFormat.Green;
|
||||
pixelFormat.BlueBits = (byte)format.ColorFormat.Blue;
|
||||
pixelFormat.AlphaBits = (byte)format.ColorFormat.Alpha;
|
||||
pixelFormat.RedBits = (byte)format.ColorDepth.Red;
|
||||
pixelFormat.GreenBits = (byte)format.ColorDepth.Green;
|
||||
pixelFormat.BlueBits = (byte)format.ColorDepth.Blue;
|
||||
pixelFormat.AlphaBits = (byte)format.ColorDepth.Alpha;
|
||||
|
||||
if (format.AccumulatorFormat.BitsPerPixel > 0)
|
||||
{
|
||||
|
@ -488,7 +494,7 @@ namespace OpenTK.Platform.Windows
|
|||
/// <returns>A System.String describing this OpenGL context.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return (this as IGLContextInternal).Context.ToString();
|
||||
return (this as IGraphicsContextInternal).Context.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -63,15 +63,6 @@ namespace OpenTK.Platform.Windows
|
|||
Debug.Print("Native window driver: {0}", this.ToString());
|
||||
}
|
||||
|
||||
/// <internal />
|
||||
/// <summary>Constructs a new win32 top-level window with the specified size.</summary>
|
||||
internal WinGLNative(int width, int height)
|
||||
: this()
|
||||
{
|
||||
this.CreateWindow(width, height);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region protected override void WndProc(ref Message m)
|
||||
|
@ -320,9 +311,9 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#endregion
|
||||
|
||||
#region public void CreateWindow(int width, int height)
|
||||
#region public void CreateWindow(int width, int height, GraphicsMode mode, out IGraphicsContext context)
|
||||
|
||||
public void CreateWindow(int width, int height)//, GraphicsMode format, out IGraphicsContext context)
|
||||
public void CreateWindow(int width, int height, GraphicsMode mode, out IGraphicsContext context)
|
||||
{
|
||||
Debug.Print("Creating native window.");
|
||||
Debug.Indent();
|
||||
|
@ -380,13 +371,7 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
Functions.SetWindowPos(this.Handle, WindowPlacementOptions.TOP, Left, Top, cp.Width, cp.Height, SetWindowPosFlags.SHOWWINDOW);
|
||||
|
||||
//context = new GraphicsContext(mode, window);
|
||||
//context.CreateContext();
|
||||
|
||||
//context = new WinGLContext();
|
||||
//(context as IGLContextCreationHack).SetWindowHandle(window.Handle);
|
||||
//(context as IGLContextCreationHack).SelectDisplayMode(mode, window);
|
||||
//context.CreateContext(true, null);
|
||||
context = new GraphicsContext(mode, window);
|
||||
|
||||
Debug.Unindent();
|
||||
}
|
||||
|
|
|
@ -561,7 +561,7 @@ XF86VidModeGetGammaRampSize(
|
|||
#region internal class XVisualInfo
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public class XVisualInfo
|
||||
public struct XVisualInfo
|
||||
{
|
||||
public IntPtr visual;
|
||||
public VisualID visualid;
|
||||
|
|
|
@ -325,5 +325,9 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
[DllImport("libX11")]
|
||||
public extern static void XPeekEvent(IntPtr display, ref XEvent xevent);
|
||||
|
||||
[DllImport("libX11")]
|
||||
public static extern IntPtr XGetVisualInfo(IntPtr display, IntPtr vinfo_mask, ref XVisualInfo vinfo_template,
|
||||
out int nitems_return);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ using System.Collections.Generic;
|
|||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
#pragma warning disable 1591
|
||||
|
||||
namespace OpenTK.Platform.X11
|
||||
{
|
||||
#region Types
|
||||
|
@ -40,248 +42,244 @@ namespace OpenTK.Platform.X11
|
|||
using System.Security;
|
||||
#endregion
|
||||
|
||||
#region Enums
|
||||
|
||||
public enum GLXAttribute : int
|
||||
{
|
||||
TRANSPARENT_BLUE_VALUE_EXT = 0x27,
|
||||
GRAY_SCALE = 0x8006,
|
||||
RGBA_TYPE = 0x8014,
|
||||
TRANSPARENT_RGB_EXT = 0x8008,
|
||||
ACCUM_BLUE_SIZE = 16,
|
||||
SHARE_CONTEXT_EXT = 0x800A,
|
||||
STEREO = 6,
|
||||
ALPHA_SIZE = 11,
|
||||
FLOAT_COMPONENTS_NV = 0x20B0,
|
||||
NONE = 0x8000,
|
||||
DEPTH_SIZE = 12,
|
||||
TRANSPARENT_INDEX_VALUE_EXT = 0x24,
|
||||
MAX_PBUFFER_WIDTH_SGIX = 0x8016,
|
||||
GREEN_SIZE = 9,
|
||||
X_RENDERABLE_SGIX = 0x8012,
|
||||
LARGEST_PBUFFER = 0x801C,
|
||||
DONT_CARE = unchecked((int)0xFFFFFFFF),
|
||||
TRANSPARENT_ALPHA_VALUE_EXT = 0x28,
|
||||
PSEUDO_COLOR_EXT = 0x8004,
|
||||
USE_GL = 1,
|
||||
SAMPLE_BUFFERS_SGIS = 100000,
|
||||
TRANSPARENT_GREEN_VALUE_EXT = 0x26,
|
||||
HYPERPIPE_ID_SGIX = 0x8030,
|
||||
COLOR_INDEX_TYPE_SGIX = 0x8015,
|
||||
SLOW_CONFIG = 0x8001,
|
||||
PRESERVED_CONTENTS = 0x801B,
|
||||
ACCUM_RED_SIZE = 14,
|
||||
EVENT_MASK = 0x801F,
|
||||
VISUAL_ID_EXT = 0x800B,
|
||||
EVENT_MASK_SGIX = 0x801F,
|
||||
SLOW_VISUAL_EXT = 0x8001,
|
||||
TRANSPARENT_GREEN_VALUE = 0x26,
|
||||
MAX_PBUFFER_WIDTH = 0x8016,
|
||||
DIRECT_COLOR_EXT = 0x8003,
|
||||
VISUAL_ID = 0x800B,
|
||||
ACCUM_GREEN_SIZE = 15,
|
||||
DRAWABLE_TYPE_SGIX = 0x8010,
|
||||
SCREEN_EXT = 0x800C,
|
||||
SAMPLES = 100001,
|
||||
HEIGHT = 0x801E,
|
||||
TRANSPARENT_INDEX_VALUE = 0x24,
|
||||
SAMPLE_BUFFERS_ARB = 100000,
|
||||
PBUFFER = 0x8023,
|
||||
RGBA_TYPE_SGIX = 0x8014,
|
||||
MAX_PBUFFER_HEIGHT = 0x8017,
|
||||
FBCONFIG_ID_SGIX = 0x8013,
|
||||
DRAWABLE_TYPE = 0x8010,
|
||||
SCREEN = 0x800C,
|
||||
RED_SIZE = 8,
|
||||
VISUAL_SELECT_GROUP_SGIX = 0x8028,
|
||||
VISUAL_CAVEAT_EXT = 0x20,
|
||||
PSEUDO_COLOR = 0x8004,
|
||||
PBUFFER_HEIGHT = 0x8040,
|
||||
STATIC_GRAY = 0x8007,
|
||||
PRESERVED_CONTENTS_SGIX = 0x801B,
|
||||
RGBA_FLOAT_TYPE_ARB = 0x20B9,
|
||||
TRANSPARENT_RED_VALUE = 0x25,
|
||||
TRANSPARENT_ALPHA_VALUE = 0x28,
|
||||
WINDOW = 0x8022,
|
||||
X_RENDERABLE = 0x8012,
|
||||
STENCIL_SIZE = 13,
|
||||
TRANSPARENT_RGB = 0x8008,
|
||||
LARGEST_PBUFFER_SGIX = 0x801C,
|
||||
STATIC_GRAY_EXT = 0x8007,
|
||||
TRANSPARENT_BLUE_VALUE = 0x27,
|
||||
DIGITAL_MEDIA_PBUFFER_SGIX = 0x8024,
|
||||
BLENDED_RGBA_SGIS = 0x8025,
|
||||
NON_CONFORMANT_VISUAL_EXT = 0x800D,
|
||||
COLOR_INDEX_TYPE = 0x8015,
|
||||
TRANSPARENT_RED_VALUE_EXT = 0x25,
|
||||
GRAY_SCALE_EXT = 0x8006,
|
||||
WINDOW_SGIX = 0x8022,
|
||||
X_VISUAL_TYPE = 0x22,
|
||||
MAX_PBUFFER_HEIGHT_SGIX = 0x8017,
|
||||
DOUBLEBUFFER = 5,
|
||||
OPTIMAL_PBUFFER_WIDTH_SGIX = 0x8019,
|
||||
X_VISUAL_TYPE_EXT = 0x22,
|
||||
WIDTH_SGIX = 0x801D,
|
||||
STATIC_COLOR_EXT = 0x8005,
|
||||
BUFFER_SIZE = 2,
|
||||
DIRECT_COLOR = 0x8003,
|
||||
MAX_PBUFFER_PIXELS = 0x8018,
|
||||
NONE_EXT = 0x8000,
|
||||
HEIGHT_SGIX = 0x801E,
|
||||
RENDER_TYPE = 0x8011,
|
||||
FBCONFIG_ID = 0x8013,
|
||||
TRANSPARENT_INDEX_EXT = 0x8009,
|
||||
TRANSPARENT_INDEX = 0x8009,
|
||||
TRANSPARENT_TYPE_EXT = 0x23,
|
||||
ACCUM_ALPHA_SIZE = 17,
|
||||
PBUFFER_SGIX = 0x8023,
|
||||
MAX_PBUFFER_PIXELS_SGIX = 0x8018,
|
||||
OPTIMAL_PBUFFER_HEIGHT_SGIX = 0x801A,
|
||||
DAMAGED = 0x8020,
|
||||
SAVED_SGIX = 0x8021,
|
||||
TRANSPARENT_TYPE = 0x23,
|
||||
MULTISAMPLE_SUB_RECT_WIDTH_SGIS = 0x8026,
|
||||
NON_CONFORMANT_CONFIG = 0x800D,
|
||||
BLUE_SIZE = 10,
|
||||
TRUE_COLOR_EXT = 0x8002,
|
||||
SAMPLES_SGIS = 100001,
|
||||
SAMPLES_ARB = 100001,
|
||||
TRUE_COLOR = 0x8002,
|
||||
RGBA = 4,
|
||||
AUX_BUFFERS = 7,
|
||||
SAMPLE_BUFFERS = 100000,
|
||||
SAVED = 0x8021,
|
||||
MULTISAMPLE_SUB_RECT_HEIGHT_SGIS = 0x8027,
|
||||
DAMAGED_SGIX = 0x8020,
|
||||
STATIC_COLOR = 0x8005,
|
||||
PBUFFER_WIDTH = 0x8041,
|
||||
WIDTH = 0x801D,
|
||||
LEVEL = 3,
|
||||
CONFIG_CAVEAT = 0x20,
|
||||
RENDER_TYPE_SGIX = 0x8011,
|
||||
}
|
||||
|
||||
public enum GLXHyperpipeAttrib : int
|
||||
{
|
||||
PIPE_RECT_LIMITS_SGIX = 0x00000002,
|
||||
PIPE_RECT_SGIX = 0x00000001,
|
||||
HYPERPIPE_STEREO_SGIX = 0x00000003,
|
||||
HYPERPIPE_PIXEL_AVERAGE_SGIX = 0x00000004,
|
||||
}
|
||||
|
||||
public enum GLXStringName : int
|
||||
{
|
||||
EXTENSIONS = 0x3,
|
||||
VERSION = 0x2,
|
||||
VENDOR = 0x1,
|
||||
}
|
||||
|
||||
public enum GLXEventMask : int
|
||||
{
|
||||
PBUFFER_CLOBBER_MASK = 0x08000000,
|
||||
BUFFER_CLOBBER_MASK_SGIX = 0x08000000,
|
||||
}
|
||||
|
||||
public enum GLXRenderTypeMask : int
|
||||
{
|
||||
COLOR_INDEX_BIT_SGIX = 0x00000002,
|
||||
RGBA_BIT = 0x00000001,
|
||||
RGBA_FLOAT_BIT_ARB = 0x00000004,
|
||||
RGBA_BIT_SGIX = 0x00000001,
|
||||
COLOR_INDEX_BIT = 0x00000002,
|
||||
}
|
||||
|
||||
public enum GLXHyperpipeTypeMask : int
|
||||
{
|
||||
HYPERPIPE_RENDER_PIPE_SGIX = 0x00000002,
|
||||
HYPERPIPE_DISPLAY_PIPE_SGIX = 0x00000001,
|
||||
}
|
||||
|
||||
public enum GLXPbufferClobberMask : int
|
||||
{
|
||||
ACCUM_BUFFER_BIT_SGIX = 0x00000080,
|
||||
FRONT_LEFT_BUFFER_BIT = 0x00000001,
|
||||
BACK_RIGHT_BUFFER_BIT = 0x00000008,
|
||||
FRONT_RIGHT_BUFFER_BIT_SGIX = 0x00000002,
|
||||
STENCIL_BUFFER_BIT_SGIX = 0x00000040,
|
||||
SAMPLE_BUFFERS_BIT_SGIX = 0x00000100,
|
||||
STENCIL_BUFFER_BIT = 0x00000040,
|
||||
BACK_RIGHT_BUFFER_BIT_SGIX = 0x00000008,
|
||||
BACK_LEFT_BUFFER_BIT_SGIX = 0x00000004,
|
||||
AUX_BUFFERS_BIT = 0x00000010,
|
||||
DEPTH_BUFFER_BIT_SGIX = 0x00000020,
|
||||
ACCUM_BUFFER_BIT = 0x00000080,
|
||||
AUX_BUFFERS_BIT_SGIX = 0x00000010,
|
||||
DEPTH_BUFFER_BIT = 0x00000020,
|
||||
FRONT_LEFT_BUFFER_BIT_SGIX = 0x00000001,
|
||||
BACK_LEFT_BUFFER_BIT = 0x00000004,
|
||||
FRONT_RIGHT_BUFFER_BIT = 0x00000002,
|
||||
}
|
||||
|
||||
public enum GLXHyperpipeMisc : int
|
||||
{
|
||||
HYPERPIPE_PIPE_NAME_LENGTH_SGIX = 80,
|
||||
}
|
||||
|
||||
public enum GLXErrorCode : int
|
||||
{
|
||||
BAD_CONTEXT = 5,
|
||||
NO_EXTENSION = 3,
|
||||
BAD_HYPERPIPE_SGIX = 92,
|
||||
BAD_ENUM = 7,
|
||||
BAD_SCREEN = 1,
|
||||
BAD_VALUE = 6,
|
||||
BAD_ATTRIBUTE = 2,
|
||||
BAD_VISUAL = 4,
|
||||
BAD_HYPERPIPE_CONFIG_SGIX = 91,
|
||||
}
|
||||
|
||||
public enum GLXSyncType : int
|
||||
{
|
||||
SYNC_SWAP_SGIX = 0x00000001,
|
||||
SYNC_FRAME_SGIX = 0x00000000,
|
||||
}
|
||||
|
||||
public enum GLXDrawableTypeMask : int
|
||||
{
|
||||
WINDOW_BIT = 0x00000001,
|
||||
PIXMAP_BIT = 0x00000002,
|
||||
PBUFFER_BIT_SGIX = 0x00000004,
|
||||
PBUFFER_BIT = 0x00000004,
|
||||
WINDOW_BIT_SGIX = 0x00000001,
|
||||
PIXMAP_BIT_SGIX = 0x00000002,
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Provides access to GLX functions.
|
||||
/// </summary>
|
||||
partial class Glx
|
||||
{
|
||||
#region Enums
|
||||
|
||||
public struct Enums
|
||||
{
|
||||
public enum GLXAttribute : int
|
||||
{
|
||||
TRANSPARENT_BLUE_VALUE_EXT = 0x27,
|
||||
GRAY_SCALE = 0x8006,
|
||||
RGBA_TYPE = 0x8014,
|
||||
TRANSPARENT_RGB_EXT = 0x8008,
|
||||
ACCUM_BLUE_SIZE = 16,
|
||||
SHARE_CONTEXT_EXT = 0x800A,
|
||||
STEREO = 6,
|
||||
ALPHA_SIZE = 11,
|
||||
FLOAT_COMPONENTS_NV = 0x20B0,
|
||||
NONE = 0x8000,
|
||||
DEPTH_SIZE = 12,
|
||||
TRANSPARENT_INDEX_VALUE_EXT = 0x24,
|
||||
MAX_PBUFFER_WIDTH_SGIX = 0x8016,
|
||||
GREEN_SIZE = 9,
|
||||
X_RENDERABLE_SGIX = 0x8012,
|
||||
LARGEST_PBUFFER = 0x801C,
|
||||
DONT_CARE = unchecked((int)0xFFFFFFFF),
|
||||
TRANSPARENT_ALPHA_VALUE_EXT = 0x28,
|
||||
PSEUDO_COLOR_EXT = 0x8004,
|
||||
USE_GL = 1,
|
||||
SAMPLE_BUFFERS_SGIS = 100000,
|
||||
TRANSPARENT_GREEN_VALUE_EXT = 0x26,
|
||||
HYPERPIPE_ID_SGIX = 0x8030,
|
||||
COLOR_INDEX_TYPE_SGIX = 0x8015,
|
||||
SLOW_CONFIG = 0x8001,
|
||||
PRESERVED_CONTENTS = 0x801B,
|
||||
ACCUM_RED_SIZE = 14,
|
||||
EVENT_MASK = 0x801F,
|
||||
VISUAL_ID_EXT = 0x800B,
|
||||
EVENT_MASK_SGIX = 0x801F,
|
||||
SLOW_VISUAL_EXT = 0x8001,
|
||||
TRANSPARENT_GREEN_VALUE = 0x26,
|
||||
MAX_PBUFFER_WIDTH = 0x8016,
|
||||
DIRECT_COLOR_EXT = 0x8003,
|
||||
VISUAL_ID = 0x800B,
|
||||
ACCUM_GREEN_SIZE = 15,
|
||||
DRAWABLE_TYPE_SGIX = 0x8010,
|
||||
SCREEN_EXT = 0x800C,
|
||||
SAMPLES = 100001,
|
||||
HEIGHT = 0x801E,
|
||||
TRANSPARENT_INDEX_VALUE = 0x24,
|
||||
SAMPLE_BUFFERS_ARB = 100000,
|
||||
PBUFFER = 0x8023,
|
||||
RGBA_TYPE_SGIX = 0x8014,
|
||||
MAX_PBUFFER_HEIGHT = 0x8017,
|
||||
FBCONFIG_ID_SGIX = 0x8013,
|
||||
DRAWABLE_TYPE = 0x8010,
|
||||
SCREEN = 0x800C,
|
||||
RED_SIZE = 8,
|
||||
VISUAL_SELECT_GROUP_SGIX = 0x8028,
|
||||
VISUAL_CAVEAT_EXT = 0x20,
|
||||
PSEUDO_COLOR = 0x8004,
|
||||
PBUFFER_HEIGHT = 0x8040,
|
||||
STATIC_GRAY = 0x8007,
|
||||
PRESERVED_CONTENTS_SGIX = 0x801B,
|
||||
RGBA_FLOAT_TYPE_ARB = 0x20B9,
|
||||
TRANSPARENT_RED_VALUE = 0x25,
|
||||
TRANSPARENT_ALPHA_VALUE = 0x28,
|
||||
WINDOW = 0x8022,
|
||||
X_RENDERABLE = 0x8012,
|
||||
STENCIL_SIZE = 13,
|
||||
TRANSPARENT_RGB = 0x8008,
|
||||
LARGEST_PBUFFER_SGIX = 0x801C,
|
||||
STATIC_GRAY_EXT = 0x8007,
|
||||
TRANSPARENT_BLUE_VALUE = 0x27,
|
||||
DIGITAL_MEDIA_PBUFFER_SGIX = 0x8024,
|
||||
BLENDED_RGBA_SGIS = 0x8025,
|
||||
NON_CONFORMANT_VISUAL_EXT = 0x800D,
|
||||
COLOR_INDEX_TYPE = 0x8015,
|
||||
TRANSPARENT_RED_VALUE_EXT = 0x25,
|
||||
GRAY_SCALE_EXT = 0x8006,
|
||||
WINDOW_SGIX = 0x8022,
|
||||
X_VISUAL_TYPE = 0x22,
|
||||
MAX_PBUFFER_HEIGHT_SGIX = 0x8017,
|
||||
DOUBLEBUFFER = 5,
|
||||
OPTIMAL_PBUFFER_WIDTH_SGIX = 0x8019,
|
||||
X_VISUAL_TYPE_EXT = 0x22,
|
||||
WIDTH_SGIX = 0x801D,
|
||||
STATIC_COLOR_EXT = 0x8005,
|
||||
BUFFER_SIZE = 2,
|
||||
DIRECT_COLOR = 0x8003,
|
||||
MAX_PBUFFER_PIXELS = 0x8018,
|
||||
NONE_EXT = 0x8000,
|
||||
HEIGHT_SGIX = 0x801E,
|
||||
RENDER_TYPE = 0x8011,
|
||||
FBCONFIG_ID = 0x8013,
|
||||
TRANSPARENT_INDEX_EXT = 0x8009,
|
||||
TRANSPARENT_INDEX = 0x8009,
|
||||
TRANSPARENT_TYPE_EXT = 0x23,
|
||||
ACCUM_ALPHA_SIZE = 17,
|
||||
PBUFFER_SGIX = 0x8023,
|
||||
MAX_PBUFFER_PIXELS_SGIX = 0x8018,
|
||||
OPTIMAL_PBUFFER_HEIGHT_SGIX = 0x801A,
|
||||
DAMAGED = 0x8020,
|
||||
SAVED_SGIX = 0x8021,
|
||||
TRANSPARENT_TYPE = 0x23,
|
||||
MULTISAMPLE_SUB_RECT_WIDTH_SGIS = 0x8026,
|
||||
NON_CONFORMANT_CONFIG = 0x800D,
|
||||
BLUE_SIZE = 10,
|
||||
TRUE_COLOR_EXT = 0x8002,
|
||||
SAMPLES_SGIS = 100001,
|
||||
SAMPLES_ARB = 100001,
|
||||
TRUE_COLOR = 0x8002,
|
||||
RGBA = 4,
|
||||
AUX_BUFFERS = 7,
|
||||
SAMPLE_BUFFERS = 100000,
|
||||
SAVED = 0x8021,
|
||||
MULTISAMPLE_SUB_RECT_HEIGHT_SGIS = 0x8027,
|
||||
DAMAGED_SGIX = 0x8020,
|
||||
STATIC_COLOR = 0x8005,
|
||||
PBUFFER_WIDTH = 0x8041,
|
||||
WIDTH = 0x801D,
|
||||
LEVEL = 3,
|
||||
CONFIG_CAVEAT = 0x20,
|
||||
RENDER_TYPE_SGIX = 0x8011,
|
||||
}
|
||||
|
||||
public enum GLXHyperpipeAttrib : int
|
||||
{
|
||||
PIPE_RECT_LIMITS_SGIX = 0x00000002,
|
||||
PIPE_RECT_SGIX = 0x00000001,
|
||||
HYPERPIPE_STEREO_SGIX = 0x00000003,
|
||||
HYPERPIPE_PIXEL_AVERAGE_SGIX = 0x00000004,
|
||||
}
|
||||
|
||||
public enum GLXStringName : int
|
||||
{
|
||||
EXTENSIONS = 0x3,
|
||||
VERSION = 0x2,
|
||||
VENDOR = 0x1,
|
||||
}
|
||||
|
||||
public enum GLXEventMask : int
|
||||
{
|
||||
PBUFFER_CLOBBER_MASK = 0x08000000,
|
||||
BUFFER_CLOBBER_MASK_SGIX = 0x08000000,
|
||||
}
|
||||
|
||||
public enum GLXRenderTypeMask : int
|
||||
{
|
||||
COLOR_INDEX_BIT_SGIX = 0x00000002,
|
||||
RGBA_BIT = 0x00000001,
|
||||
RGBA_FLOAT_BIT_ARB = 0x00000004,
|
||||
RGBA_BIT_SGIX = 0x00000001,
|
||||
COLOR_INDEX_BIT = 0x00000002,
|
||||
}
|
||||
|
||||
public enum GLXHyperpipeTypeMask : int
|
||||
{
|
||||
HYPERPIPE_RENDER_PIPE_SGIX = 0x00000002,
|
||||
HYPERPIPE_DISPLAY_PIPE_SGIX = 0x00000001,
|
||||
}
|
||||
|
||||
public enum GLXPbufferClobberMask : int
|
||||
{
|
||||
ACCUM_BUFFER_BIT_SGIX = 0x00000080,
|
||||
FRONT_LEFT_BUFFER_BIT = 0x00000001,
|
||||
BACK_RIGHT_BUFFER_BIT = 0x00000008,
|
||||
FRONT_RIGHT_BUFFER_BIT_SGIX = 0x00000002,
|
||||
STENCIL_BUFFER_BIT_SGIX = 0x00000040,
|
||||
SAMPLE_BUFFERS_BIT_SGIX = 0x00000100,
|
||||
STENCIL_BUFFER_BIT = 0x00000040,
|
||||
BACK_RIGHT_BUFFER_BIT_SGIX = 0x00000008,
|
||||
BACK_LEFT_BUFFER_BIT_SGIX = 0x00000004,
|
||||
AUX_BUFFERS_BIT = 0x00000010,
|
||||
DEPTH_BUFFER_BIT_SGIX = 0x00000020,
|
||||
ACCUM_BUFFER_BIT = 0x00000080,
|
||||
AUX_BUFFERS_BIT_SGIX = 0x00000010,
|
||||
DEPTH_BUFFER_BIT = 0x00000020,
|
||||
FRONT_LEFT_BUFFER_BIT_SGIX = 0x00000001,
|
||||
BACK_LEFT_BUFFER_BIT = 0x00000004,
|
||||
FRONT_RIGHT_BUFFER_BIT = 0x00000002,
|
||||
}
|
||||
|
||||
public enum GLXHyperpipeMisc : int
|
||||
{
|
||||
HYPERPIPE_PIPE_NAME_LENGTH_SGIX = 80,
|
||||
}
|
||||
|
||||
public enum GLXErrorCode : int
|
||||
{
|
||||
BAD_CONTEXT = 5,
|
||||
NO_EXTENSION = 3,
|
||||
BAD_HYPERPIPE_SGIX = 92,
|
||||
BAD_ENUM = 7,
|
||||
BAD_SCREEN = 1,
|
||||
BAD_VALUE = 6,
|
||||
BAD_ATTRIBUTE = 2,
|
||||
BAD_VISUAL = 4,
|
||||
BAD_HYPERPIPE_CONFIG_SGIX = 91,
|
||||
}
|
||||
|
||||
public enum GLXSyncType : int
|
||||
{
|
||||
SYNC_SWAP_SGIX = 0x00000001,
|
||||
SYNC_FRAME_SGIX = 0x00000000,
|
||||
}
|
||||
|
||||
public enum GLXDrawableTypeMask : int
|
||||
{
|
||||
WINDOW_BIT = 0x00000001,
|
||||
PIXMAP_BIT = 0x00000002,
|
||||
PBUFFER_BIT_SGIX = 0x00000004,
|
||||
PBUFFER_BIT = 0x00000004,
|
||||
WINDOW_BIT_SGIX = 0x00000001,
|
||||
PIXMAP_BIT_SGIX = 0x00000002,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GLX functions
|
||||
|
||||
[DllImport(Library, EntryPoint = "glXQueryExtension")]
|
||||
public static extern bool QueryExtension(IntPtr dpy, ref int errorBase, ref int eventBase);
|
||||
|
||||
[DllImport(Library, EntryPoint = "glXQueryExtensionsString")]
|
||||
static extern IntPtr QueryExtensionsStringInternal(IntPtr dpy, int screen);
|
||||
|
||||
public static string QueryExtensionsString(IntPtr dpy, int screen)
|
||||
{
|
||||
return Marshal.PtrToStringAnsi(QueryExtensionsStringInternal(dpy, screen));
|
||||
}
|
||||
|
||||
[DllImport(Library, EntryPoint = "glXCreateContext")]
|
||||
public static extern IntPtr CreateContext(IntPtr dpy, IntPtr vis, IntPtr shareList, bool direct);
|
||||
|
||||
public static IntPtr CreateContext(IntPtr dpy, XVisualInfo vis, IntPtr shareList, bool direct)
|
||||
{
|
||||
GCHandle h0 = GCHandle.Alloc(vis, GCHandleType.Pinned);
|
||||
|
||||
try
|
||||
{
|
||||
return CreateContext(dpy, h0.AddrOfPinnedObject(), shareList, direct);
|
||||
}
|
||||
finally
|
||||
{
|
||||
h0.Free();
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport(Library, EntryPoint = "glXCreateContext")]
|
||||
public static extern IntPtr CreateContext(IntPtr dpy, ref XVisualInfo vis, IntPtr shareList, bool direct);
|
||||
|
||||
[DllImport(Library, EntryPoint = "glXDestroyContext")]
|
||||
public static extern void DestroyContext(IntPtr dpy, IntPtr context);
|
||||
|
||||
|
@ -302,20 +300,23 @@ namespace OpenTK.Platform.X11
|
|||
[DllImport(Library, EntryPoint = "glXChooseVisual")]
|
||||
public extern static IntPtr ChooseVisual(IntPtr dpy, int screen, IntPtr attriblist);
|
||||
|
||||
public static IntPtr ChooseVisual(IntPtr dpy, int screen, int[] attriblist)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (int* attriblist_ptr = attriblist)
|
||||
{
|
||||
return ChooseVisual(dpy, screen, (IntPtr)attriblist_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
[DllImport(Library, EntryPoint = "glXChooseVisual")]
|
||||
public extern static IntPtr ChooseVisual(IntPtr dpy, int screen, int[] attriblist);
|
||||
|
||||
//public static IntPtr ChooseVisual(IntPtr dpy, int screen, int[] attriblist)
|
||||
//{
|
||||
// unsafe
|
||||
// {
|
||||
// fixed (int* attriblist_ptr = attriblist)
|
||||
// {
|
||||
// return ChooseVisual(dpy, screen, (IntPtr)attriblist_ptr);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
#region Extensions
|
||||
|
||||
public partial class Sgi
|
||||
{
|
||||
|
@ -331,5 +332,11 @@ namespace OpenTK.Platform.X11
|
|||
internal delegate int SwapIntervalSGI(int interval);
|
||||
internal static SwapIntervalSGI glXSwapIntervalSGI = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning restore 1591
|
|
@ -9,6 +9,9 @@ using System.Collections.Generic;
|
|||
using System.Text;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Diagnostics;
|
||||
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace OpenTK.Platform.X11
|
||||
{
|
||||
|
@ -80,15 +83,6 @@ namespace OpenTK.Platform.X11
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region internal static bool SupportsExtension(string p)
|
||||
|
||||
internal static bool SupportsExtension(string p)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
//internal struct Status
|
||||
|
|
|
@ -19,177 +19,151 @@ namespace OpenTK.Platform.X11
|
|||
/// Provides methods to create and control an opengl context on the X11 platform.
|
||||
/// This class supports OpenTK, and is not intended for use by OpenTK programs.
|
||||
/// </summary>
|
||||
internal sealed class X11GLContext : IGraphicsContext, IGLContextInternal, IGLContextCreationHack
|
||||
internal sealed class X11GLContext : IGraphicsContext, IGraphicsContextInternal
|
||||
{
|
||||
IntPtr context;
|
||||
DisplayMode mode;
|
||||
X11WindowInfo windowInfo = new X11WindowInfo();
|
||||
GraphicsMode format;
|
||||
IntPtr visual;
|
||||
bool vsync_supported;
|
||||
int vsync_interval;
|
||||
IntPtr context;
|
||||
X11WindowInfo window;
|
||||
IntPtr visual;
|
||||
bool vsync_supported;
|
||||
int vsync_interval;
|
||||
|
||||
bool disposed;
|
||||
bool disposed;
|
||||
|
||||
#region --- Constructors ---
|
||||
|
||||
static X11GLContext()
|
||||
{
|
||||
// Set the GetCurrentContext implementation.
|
||||
if (GraphicsContext.GetCurrentContext == null)
|
||||
GraphicsContext.GetCurrentContext = X11GLContext.GetCurrentContext;
|
||||
}
|
||||
static X11GLContext()
|
||||
{
|
||||
// Set the GetCurrentContext implementation.
|
||||
if (GraphicsContext.GetCurrentContext == null)
|
||||
GraphicsContext.GetCurrentContext = X11GLContext.GetCurrentContext;
|
||||
}
|
||||
|
||||
/// <private />
|
||||
/// <summary>Constructs a new X11GLContext object.</summary>
|
||||
public X11GLContext() { }
|
||||
internal X11GLContext(GraphicsMode mode, IWindowInfo info, IGraphicsContext shared, bool directRendering)
|
||||
{
|
||||
//if (mode == null) mode = GraphicsMode.Default;
|
||||
if (info == null) throw new ArgumentNullException("info", "Should point to a valid window.");
|
||||
|
||||
window = (X11WindowInfo)info;
|
||||
window.VisualInfo = SelectVisual(mode);
|
||||
|
||||
Debug.Print("Chose visual: {0}", window.VisualInfo);
|
||||
|
||||
CreateContext(shared, directRendering);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IGLContextCreationHack Members ---
|
||||
#region --- Private Methods ---
|
||||
|
||||
#region bool IGLContextCreationHack.SelectDisplayMode(DisplayMode mode, IWindowInfo info)
|
||||
#region XVisualInfo SelectVisual(GraphicsMode mode)
|
||||
|
||||
/// <summary>
|
||||
/// HACK! This function will be removed in 0.3.15
|
||||
/// Checks if the specified OpenTK.Platform.DisplayMode is available, and selects it if it is.
|
||||
/// </summary>
|
||||
/// <param name="mode">The OpenTK.Platform.DisplayMode to select.</param>
|
||||
/// <param name="info">The OpenTK.Platform.IWindowInfo that describes the display to use. Note: a window handle is not necessary for this function!</param>
|
||||
/// <returns>True if the DisplayMode is available, false otherwise.</returns>
|
||||
bool IGLContextCreationHack.SelectDisplayMode(DisplayMode mode, IWindowInfo info)
|
||||
XVisualInfo SelectVisual(GraphicsMode mode)
|
||||
{
|
||||
List<int> visualAttributes = new List<int>();
|
||||
|
||||
// TODO: Improve modesetting code.
|
||||
if (mode == null || mode.Color.BitsPerPixel == 0)
|
||||
if (mode == null || mode.ColorDepth.BitsPerPixel == 0)
|
||||
{
|
||||
// Define the bare essentials - needed for compatibility with Mono's System.Windows.Forms
|
||||
Debug.Print("Preparing visual for System.Windows.Forms (compatibility mode)");
|
||||
|
||||
visualAttributes.Add((int)Glx.Enums.GLXAttribute.RGBA);
|
||||
/*visualAttributes.Add((int)Glx.Enums.GLXAttribute.RED_SIZE);
|
||||
Debug.Print("Mono/X11 compatibility mode.");
|
||||
|
||||
visualAttributes.Add((int)GLXAttribute.RGBA);
|
||||
//visualAttributes.Add((int)GLXAttribute.RED_SIZE);
|
||||
//visualAttributes.Add((int)1);
|
||||
//visualAttributes.Add((int)GLXAttribute.GREEN_SIZE);
|
||||
//visualAttributes.Add((int)1);
|
||||
//visualAttributes.Add((int)GLXAttribute.BLUE_SIZE);
|
||||
//visualAttributes.Add((int)1);
|
||||
visualAttributes.Add((int)GLXAttribute.DEPTH_SIZE);
|
||||
visualAttributes.Add((int)1);
|
||||
visualAttributes.Add((int)Glx.Enums.GLXAttribute.GREEN_SIZE);
|
||||
visualAttributes.Add((int)1);
|
||||
visualAttributes.Add((int)Glx.Enums.GLXAttribute.BLUE_SIZE);
|
||||
visualAttributes.Add((int)1);*/
|
||||
visualAttributes.Add((int)Glx.Enums.GLXAttribute.DEPTH_SIZE);
|
||||
visualAttributes.Add((int)1);
|
||||
visualAttributes.Add((int)Glx.Enums.GLXAttribute.DOUBLEBUFFER);
|
||||
visualAttributes.Add((int)0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Print("Preparing visual for DisplayMode: {0}", mode.ToString());
|
||||
|
||||
visualAttributes.Add((int)Glx.Enums.GLXAttribute.RGBA);
|
||||
visualAttributes.Add((int)Glx.Enums.GLXAttribute.RED_SIZE);
|
||||
visualAttributes.Add((int)mode.Color.Red);
|
||||
visualAttributes.Add((int)Glx.Enums.GLXAttribute.GREEN_SIZE);
|
||||
visualAttributes.Add((int)mode.Color.Green);
|
||||
visualAttributes.Add((int)Glx.Enums.GLXAttribute.BLUE_SIZE);
|
||||
visualAttributes.Add((int)mode.Color.Blue);
|
||||
visualAttributes.Add((int)Glx.Enums.GLXAttribute.ALPHA_SIZE);
|
||||
visualAttributes.Add((int)mode.Color.Alpha);
|
||||
visualAttributes.Add((int)Glx.Enums.GLXAttribute.DEPTH_SIZE);
|
||||
visualAttributes.Add((int)mode.DepthBits);
|
||||
visualAttributes.Add((int)Glx.Enums.GLXAttribute.DOUBLEBUFFER);
|
||||
visualAttributes.Add((int)0);
|
||||
visualAttributes.Add((int)GLXAttribute.RGBA);
|
||||
visualAttributes.Add((int)GLXAttribute.RED_SIZE);
|
||||
visualAttributes.Add((int)mode.ColorDepth.Red);
|
||||
visualAttributes.Add((int)GLXAttribute.GREEN_SIZE);
|
||||
visualAttributes.Add((int)mode.ColorDepth.Green);
|
||||
visualAttributes.Add((int)GLXAttribute.BLUE_SIZE);
|
||||
visualAttributes.Add((int)mode.ColorDepth.Blue);
|
||||
visualAttributes.Add((int)GLXAttribute.ALPHA_SIZE);
|
||||
visualAttributes.Add((int)mode.ColorDepth.Alpha);
|
||||
visualAttributes.Add((int)GLXAttribute.DEPTH_SIZE);
|
||||
visualAttributes.Add((int)mode.Depth);
|
||||
}
|
||||
|
||||
//windowInfo.CopyInfoFrom(info);
|
||||
visual = Glx.ChooseVisual(windowInfo.Display, windowInfo.Screen, visualAttributes.ToArray());
|
||||
if (mode.Buffers > 1)
|
||||
visualAttributes.Add((int)GLXAttribute.DOUBLEBUFFER);
|
||||
if (mode.Stencil > 1)
|
||||
{
|
||||
visualAttributes.Add((int)GLXAttribute.STENCIL_SIZE);
|
||||
visualAttributes.Add(mode.Stencil);
|
||||
}
|
||||
if (mode.AccumulatorFormat.BitsPerPixel > 0)
|
||||
{
|
||||
visualAttributes.Add((int)GLXAttribute.ACCUM_ALPHA_SIZE);
|
||||
visualAttributes.Add(mode.AccumulatorFormat.Alpha);
|
||||
visualAttributes.Add((int)GLXAttribute.ACCUM_BLUE_SIZE);
|
||||
visualAttributes.Add(mode.AccumulatorFormat.Blue);
|
||||
visualAttributes.Add((int)GLXAttribute.ACCUM_GREEN_SIZE);
|
||||
visualAttributes.Add(mode.AccumulatorFormat.Green);
|
||||
visualAttributes.Add((int)GLXAttribute.ACCUM_RED_SIZE);
|
||||
visualAttributes.Add(mode.AccumulatorFormat.Red);
|
||||
}
|
||||
if (mode.Stereo)
|
||||
visualAttributes.Add((int)GLXAttribute.STEREO);
|
||||
|
||||
visualAttributes.Add((int)0);
|
||||
|
||||
visual = Glx.ChooseVisual(window.Display, window.Screen, visualAttributes.ToArray());
|
||||
|
||||
if (visual == IntPtr.Zero)
|
||||
return false;
|
||||
else
|
||||
{
|
||||
windowInfo.VisualInfo = (XVisualInfo)Marshal.PtrToStructure(visual,
|
||||
typeof(XVisualInfo));
|
||||
Debug.Print("Chose visual {0}", windowInfo.VisualInfo.ToString());
|
||||
}
|
||||
return true;
|
||||
throw new GraphicsContextException(String.Format("Failed to set requested mode: {0}.", mode.ToString()));
|
||||
|
||||
return (XVisualInfo)Marshal.PtrToStructure(visual, typeof(XVisualInfo));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
void IGLContextCreationHack.SetWindowHandle(IntPtr handle)
|
||||
{
|
||||
this.windowInfo.Handle = handle;
|
||||
}
|
||||
#region void CreateContext(IGraphicsContext shareContext, bool direct)
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IGraphicsContext Members ---
|
||||
|
||||
#region public void CreateContext()
|
||||
|
||||
public void CreateContext()
|
||||
{
|
||||
this.CreateContext(true, null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void CreateContext(bool direct)
|
||||
|
||||
public void CreateContext(bool direct)
|
||||
{
|
||||
this.CreateContext(direct, null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void CreateContext(bool direct, IGraphicsContext shareContext)
|
||||
|
||||
public void CreateContext(bool direct, IGraphicsContext shareContext)
|
||||
void CreateContext(IGraphicsContext shareContext, bool direct)
|
||||
{
|
||||
try
|
||||
{
|
||||
Debug.WriteLine("Creating opengl context.");
|
||||
Debug.Indent();
|
||||
ContextHandle shareHandle = shareContext != null ? (shareContext as IGraphicsContextInternal).Context : (ContextHandle)IntPtr.Zero;
|
||||
|
||||
ContextHandle shareHandle = shareContext != null ? (shareContext as IGLContextInternal).Context : (ContextHandle)IntPtr.Zero;
|
||||
|
||||
Debug.Write(direct ? "Context is direct, " : "Context is indirect, ");
|
||||
Debug.WriteLine(shareHandle.Handle == IntPtr.Zero ? "not shared." :
|
||||
String.Format("shared with ({0}).", shareHandle));
|
||||
Debug.Write("Creating OpenGL context: ");
|
||||
Debug.Write(direct ? "direct, " : "indirect, ");
|
||||
Debug.Write(shareHandle.Handle == IntPtr.Zero ? "not shared... " :
|
||||
String.Format("shared with ({0})... ", shareHandle));
|
||||
|
||||
// Try to call Glx.CreateContext with the specified parameters.
|
||||
context = Glx.CreateContext(windowInfo.Display, visual, shareHandle.Handle, direct);
|
||||
context = Glx.CreateContext(window.Display, visual, shareHandle.Handle, direct);
|
||||
|
||||
// Context creation succeeded, return.
|
||||
if (context != IntPtr.Zero)
|
||||
{
|
||||
Debug.Print("New opengl context created. (id: {0})", context);
|
||||
|
||||
this.MakeCurrent();
|
||||
GL.LoadAll();
|
||||
Glu.LoadAll();
|
||||
Glx.LoadAll();
|
||||
Debug.Print("done! (id: {0})", context);
|
||||
|
||||
//this.MakeCurrent();
|
||||
return;
|
||||
}
|
||||
// Context creation failed. Retry with a non-shared context with the
|
||||
// direct/indirect rendering mode flipped.
|
||||
Debug.Print("Cotnext creation failed, retrying with a non-shared, {0} context.",
|
||||
!direct ? "direct" : "indirect");
|
||||
context = Glx.CreateContext(windowInfo.Display, visual, IntPtr.Zero, !direct);
|
||||
Debug.Print("failed.");
|
||||
Debug.Write(String.Format("Creating OpenGL context: {0}, not shared... ", !direct ? "direct" : "indirect"));
|
||||
context = Glx.CreateContext(window.Display, visual, IntPtr.Zero, !direct);
|
||||
if (context != IntPtr.Zero)
|
||||
{
|
||||
Debug.Print("New opengl context created. (id: {0})", context);
|
||||
|
||||
this.MakeCurrent();
|
||||
GL.LoadAll();
|
||||
Glu.LoadAll();
|
||||
Glx.LoadAll();
|
||||
Debug.Print("done! (id: {0})", context);
|
||||
|
||||
//this.MakeCurrent();
|
||||
return;
|
||||
}
|
||||
|
||||
vsync_supported = Glx.SupportsExtension("glxSwapControlSGI");
|
||||
|
||||
throw new ApplicationException("Glx.CreateContext call failed (returned 0).");
|
||||
Debug.Print("failed.");
|
||||
throw new GraphicsModeException("Failed to create OpenGL context. Glx.CreateContext call returned 0.");
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -199,11 +173,21 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
#endregion
|
||||
|
||||
bool SupportsExtension(string e)
|
||||
{
|
||||
string extensions = Glx.QueryExtensionsString(window.Display, window.Screen);
|
||||
return !String.IsNullOrEmpty(extensions) && extensions.Contains(e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IGraphicsContext Members ---
|
||||
|
||||
#region public void SwapBuffers()
|
||||
|
||||
public void SwapBuffers()
|
||||
{
|
||||
Glx.SwapBuffers(windowInfo.Display, windowInfo.Handle);
|
||||
Glx.SwapBuffers(window.Display, window.Handle);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -214,11 +198,11 @@ namespace OpenTK.Platform.X11
|
|||
public void MakeCurrent()
|
||||
{
|
||||
Debug.Write(String.Format("Making context {0} current on thread {1} (Display: {2}, Screen: {3}, Window: {4})... ",
|
||||
context, System.Threading.Thread.CurrentThread.ManagedThreadId, windowInfo.Display, windowInfo.Screen, windowInfo.Handle));
|
||||
context, System.Threading.Thread.CurrentThread.ManagedThreadId, window.Display, window.Screen, window.Handle));
|
||||
|
||||
if (windowInfo.Display != IntPtr.Zero && windowInfo.Handle != IntPtr.Zero && context != IntPtr.Zero)
|
||||
if (window.Display != IntPtr.Zero && window.Handle != IntPtr.Zero && context != IntPtr.Zero)
|
||||
{
|
||||
result = Glx.MakeCurrent(windowInfo.Display, windowInfo.Handle, context);
|
||||
result = Glx.MakeCurrent(window.Display, window.Handle, context);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
|
@ -244,9 +228,9 @@ namespace OpenTK.Platform.X11
|
|||
set
|
||||
{
|
||||
if (value)
|
||||
Glx.MakeCurrent(windowInfo.Display, windowInfo.Handle, context);
|
||||
Glx.MakeCurrent(window.Display, window.Handle, context);
|
||||
else
|
||||
Glx.MakeCurrent(windowInfo.Handle, IntPtr.Zero, IntPtr.Zero);
|
||||
Glx.MakeCurrent(window.Handle, IntPtr.Zero, IntPtr.Zero);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -304,18 +288,30 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
#region --- IGLContextInternal Members ---
|
||||
|
||||
#region void LoadAll()
|
||||
|
||||
void IGraphicsContextInternal.LoadAll()
|
||||
{
|
||||
GL.LoadAll();
|
||||
Glu.LoadAll();
|
||||
Glx.LoadAll();
|
||||
vsync_supported = this.SupportsExtension("SGI_swap_control") && this.GetAddress("glXSwapControlSGI") != IntPtr.Zero;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public DisplayMode Mode
|
||||
|
||||
GraphicsMode IGLContextInternal.GraphicsMode
|
||||
GraphicsMode IGraphicsContextInternal.GraphicsMode
|
||||
{
|
||||
get { return format; }
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IntPtr IGLContextInternal.Context
|
||||
|
||||
ContextHandle IGLContextInternal.Context
|
||||
ContextHandle IGraphicsContextInternal.Context
|
||||
{
|
||||
get { return context; }
|
||||
/*private set { context = value; }*/
|
||||
|
@ -325,7 +321,7 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
#region IWindowInfo IGLContextInternal.Info
|
||||
|
||||
IWindowInfo IGLContextInternal.Info { get { return windowInfo; } }
|
||||
IWindowInfo IGraphicsContextInternal.Info { get { return window; } }
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -363,8 +359,8 @@ namespace OpenTK.Platform.X11
|
|||
if (!disposed)
|
||||
{
|
||||
// Clean unmanaged resources:
|
||||
Glx.MakeCurrent(windowInfo.Display, IntPtr.Zero, IntPtr.Zero);
|
||||
Glx.DestroyContext(windowInfo.Display, context);
|
||||
Glx.MakeCurrent(window.Display, IntPtr.Zero, IntPtr.Zero);
|
||||
Glx.DestroyContext(window.Display, context);
|
||||
API.Free(visual);
|
||||
|
||||
if (manuallyCalled)
|
||||
|
|
|
@ -32,42 +32,42 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
#region --- Fields ---
|
||||
|
||||
private X11WindowInfo window = new X11WindowInfo();
|
||||
private DisplayMode mode = new DisplayMode();
|
||||
private X11Input driver;
|
||||
X11WindowInfo window = new X11WindowInfo();
|
||||
X11Input driver;
|
||||
|
||||
// Window manager hints for fullscreen windows.
|
||||
private const string MOTIF_WM_ATOM = "_MOTIF_WM_HINTS";
|
||||
private const string KDE_WM_ATOM = "KWM_WIN_DECORATION";
|
||||
private const string KDE_NET_WM_ATOM = "_KDE_NET_WM_WINDOW_TYPE";
|
||||
private const string ICCM_WM_ATOM = "_NET_WM_WINDOW_TYPE";
|
||||
const string MOTIF_WM_ATOM = "_MOTIF_WM_HINTS";
|
||||
const string KDE_WM_ATOM = "KWM_WIN_DECORATION";
|
||||
const string KDE_NET_WM_ATOM = "_KDE_NET_WM_WINDOW_TYPE";
|
||||
const string ICCM_WM_ATOM = "_NET_WM_WINDOW_TYPE";
|
||||
|
||||
// Number of pending events.
|
||||
private int pending = 0;
|
||||
int pending = 0;
|
||||
|
||||
private int top, bottom, left, right;
|
||||
int width, height;
|
||||
int top, bottom, left, right;
|
||||
|
||||
// C# ResizeEventArgs
|
||||
private ResizeEventArgs resizeEventArgs = new ResizeEventArgs();
|
||||
ResizeEventArgs resizeEventArgs = new ResizeEventArgs();
|
||||
|
||||
// Used for event loop.
|
||||
private XEvent e = new XEvent();
|
||||
XEvent e = new XEvent();
|
||||
|
||||
private bool disposed;
|
||||
private bool exists;
|
||||
private bool isExiting;
|
||||
bool disposed;
|
||||
bool exists;
|
||||
bool isExiting;
|
||||
|
||||
// XAtoms for window properties
|
||||
private static IntPtr WMTitle; // The title of the GameWindow.
|
||||
private static IntPtr UTF8String; // No idea.
|
||||
static IntPtr WMTitle; // The title of the GameWindow.
|
||||
static IntPtr UTF8String; // No idea.
|
||||
|
||||
// Fields used for fullscreen mode changes.
|
||||
private int pre_fullscreen_width, pre_fullscreen_height;
|
||||
private bool fullscreen = false;
|
||||
int pre_fullscreen_width, pre_fullscreen_height;
|
||||
bool fullscreen = false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Public Constructors ---
|
||||
#region --- Constructors ---
|
||||
|
||||
/// <summary>
|
||||
/// Constructs and initializes a new X11GLNative window.
|
||||
|
@ -75,23 +75,28 @@ namespace OpenTK.Platform.X11
|
|||
/// </summary>
|
||||
public X11GLNative()
|
||||
{
|
||||
Debug.Print("Native window driver: {0}", this.ToString());
|
||||
try
|
||||
{
|
||||
Debug.Print("Creating X11GLNative window.");
|
||||
Debug.Indent();
|
||||
|
||||
//Utilities.ThrowOnX11Error = true; // Not very reliable
|
||||
//Utilities.ThrowOnX11Error = true; // Not very reliable
|
||||
|
||||
// Open the display to the X server, and obtain the screen and root window.
|
||||
//window.Display = API.OpenDisplay(null); // null == default display
|
||||
window.Display = API.DefaultDisplay;
|
||||
if (window.Display == IntPtr.Zero)
|
||||
throw new Exception("Could not open connection to X");
|
||||
// Open the display to the X server, and obtain the screen and root window.
|
||||
window.Display = API.OpenDisplay(null); // null == default display //window.Display = API.DefaultDisplay;
|
||||
if (window.Display == IntPtr.Zero)
|
||||
throw new Exception("Could not open connection to X");
|
||||
|
||||
window.Screen = API.DefaultScreen;//Functions.XDefaultScreen(window.Display);
|
||||
window.RootWindow = API.RootWindow;//Functions.XRootWindow(window.Display, window.Screen);
|
||||
window.Screen = Functions.XDefaultScreen(window.Display); //API.DefaultScreen;
|
||||
window.RootWindow = Functions.XRootWindow(window.Display, window.Screen); // API.RootWindow;
|
||||
Debug.Print("Display: {0}, Screen {1}, Root window: {2}", window.Display, window.Screen, window.RootWindow);
|
||||
|
||||
Debug.Print("Display: {0}, Screen {1}, Root window: {2}",
|
||||
window.Display, window.Screen, window.RootWindow);
|
||||
|
||||
RegisterAtoms(window);
|
||||
RegisterAtoms(window);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Debug.Unindent();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -121,6 +126,89 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
#region --- INativeGLWindow Members ---
|
||||
|
||||
#region public void CreateWindow(int width, int height, GraphicsMode mode, out IGraphicsContext context)
|
||||
|
||||
public void CreateWindow(int width, int height, GraphicsMode mode, out IGraphicsContext context)
|
||||
{
|
||||
if (width <= 0) throw new ArgumentOutOfRangeException("width", "Must be higher than zero.");
|
||||
if (height <= 0) throw new ArgumentOutOfRangeException("height", "Must be higher than zero.");
|
||||
if (exists) throw new InvalidOperationException("A render window already exists.");
|
||||
|
||||
Debug.Indent();
|
||||
|
||||
// Create the context. This call also creates an XVisualInfo structure for us.
|
||||
context = new GraphicsContext(mode, window);
|
||||
|
||||
// Create a window on this display using the visual above
|
||||
Debug.Write("Opening render window... ");
|
||||
|
||||
XSetWindowAttributes attributes = new XSetWindowAttributes();
|
||||
attributes.background_pixel = IntPtr.Zero;
|
||||
attributes.border_pixel = IntPtr.Zero;
|
||||
attributes.colormap =
|
||||
API.CreateColormap(window.Display, window.RootWindow, window.VisualInfo.visual, 0/*AllocNone*/);
|
||||
window.EventMask =
|
||||
EventMask.StructureNotifyMask | EventMask.SubstructureNotifyMask | EventMask.ExposureMask |
|
||||
EventMask.KeyReleaseMask | EventMask.KeyPressMask |
|
||||
EventMask.PointerMotionMask | // Bad! EventMask.PointerMotionHintMask |
|
||||
EventMask.ButtonPressMask | EventMask.ButtonReleaseMask;
|
||||
attributes.event_mask = (IntPtr)window.EventMask;
|
||||
|
||||
uint mask = (uint)SetWindowValuemask.ColorMap | (uint)SetWindowValuemask.EventMask |
|
||||
(uint)SetWindowValuemask.BackPixel | (uint)SetWindowValuemask.BorderPixel;
|
||||
|
||||
window.Handle = Functions.XCreateWindow(window.Display, window.RootWindow,
|
||||
0, 0, width, height, 0, window.VisualInfo.depth/*(int)CreateWindowArgs.CopyFromParent*/,
|
||||
(int)CreateWindowArgs.InputOutput, window.VisualInfo.visual, (UIntPtr)mask, ref attributes);
|
||||
|
||||
if (window.Handle == IntPtr.Zero)
|
||||
throw new ApplicationException("XCreateWindow call failed (returned 0).");
|
||||
|
||||
XVisualInfo vis = window.VisualInfo;
|
||||
Glx.CreateContext(window.Display, ref vis, IntPtr.Zero, true);
|
||||
|
||||
// Set the window hints
|
||||
XSizeHints hints = new XSizeHints();
|
||||
hints.x = 0;
|
||||
hints.y = 0;
|
||||
hints.width = width;
|
||||
hints.height = height;
|
||||
hints.flags = (IntPtr)(XSizeHintsFlags.USSize | XSizeHintsFlags.USPosition);
|
||||
Functions.XSetWMNormalHints(window.Display, window.Handle, ref hints);
|
||||
|
||||
// Register for window destroy notification
|
||||
IntPtr wm_destroy_atom = Functions.XInternAtom(window.Display, "WM_DELETE_WINDOW", true);
|
||||
//XWMHints hint = new XWMHints();
|
||||
Functions.XSetWMProtocols(window.Display, window.Handle, new IntPtr[] { wm_destroy_atom }, 1);
|
||||
|
||||
Top = Left = 0;
|
||||
Right = Width;
|
||||
Bottom = Height;
|
||||
|
||||
//XTextProperty text = new XTextProperty();
|
||||
//text.value = "OpenTK Game Window";
|
||||
//text.format = 8;
|
||||
//Functions.XSetWMName(window.Display, window.Handle, ref text);
|
||||
//Functions.XSetWMProperties(display, window, name, name, 0, /*None*/ null, 0, hints);
|
||||
|
||||
Debug.Print("done! (id: {0})", window.Handle);
|
||||
|
||||
//(glContext as IGLContextCreationHack).SetWindowHandle(window.Handle);
|
||||
|
||||
API.MapRaised(window.Display, window.Handle);
|
||||
mapped = true;
|
||||
|
||||
//context.CreateContext(true, null);
|
||||
|
||||
driver = new X11Input(window);
|
||||
|
||||
Debug.WriteLine("X11GLNative window created successfully!");
|
||||
Debug.Unindent();
|
||||
exists = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void ProcessEvents()
|
||||
|
||||
public void ProcessEvents()
|
||||
|
@ -161,16 +249,9 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
case XEventName.ConfigureNotify:
|
||||
// If the window size changed, raise the C# Resize event.
|
||||
if (e.ConfigureEvent.width != mode.Width ||
|
||||
e.ConfigureEvent.height != mode.Height)
|
||||
if (e.ConfigureEvent.width != width || e.ConfigureEvent.height != height)
|
||||
{
|
||||
Debug.WriteLine(
|
||||
String.Format(
|
||||
"New res: {0}x{1}",
|
||||
e.ConfigureEvent.width,
|
||||
e.ConfigureEvent.height
|
||||
)
|
||||
);
|
||||
Debug.WriteLine(String.Format("ConfigureNotify: {0}x{1}", e.ConfigureEvent.width, e.ConfigureEvent.height));
|
||||
|
||||
resizeEventArgs.Width = e.ConfigureEvent.width;
|
||||
resizeEventArgs.Height = e.ConfigureEvent.height;
|
||||
|
@ -257,7 +338,7 @@ namespace OpenTK.Platform.X11
|
|||
pre_fullscreen_width = this.Width;
|
||||
//Functions.XRaiseWindow(this.window.Display, this.Handle);
|
||||
Functions.XMoveResizeWindow(this.window.Display, this.Handle, 0, 0,
|
||||
DisplayDevice.PrimaryDisplay.Width, DisplayDevice.PrimaryDisplay.Height);
|
||||
DisplayDevice.Default.Width, DisplayDevice.Default.Height);
|
||||
Debug.Unindent();
|
||||
fullscreen = true;
|
||||
}
|
||||
|
@ -370,19 +451,7 @@ namespace OpenTK.Platform.X11
|
|||
}
|
||||
|
||||
#endregion
|
||||
/*
|
||||
#region public IInputDriver InputDriver
|
||||
|
||||
public IInputDriver InputDriver
|
||||
{
|
||||
get
|
||||
{
|
||||
return driver;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
*/
|
||||
#region public IWindowInfo WindowInfo
|
||||
|
||||
public IWindowInfo WindowInfo
|
||||
|
@ -392,115 +461,6 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
#endregion
|
||||
|
||||
#region public void CreateWindow(int width, int height)
|
||||
|
||||
public void CreateWindow(int width, int height)
|
||||
{
|
||||
#if false
|
||||
if (exists)
|
||||
throw new ApplicationException("Render window already exists!");
|
||||
|
||||
Debug.Print("Creating GameWindow with mode: {0}", mode != null ? mode.ToString() : "default");
|
||||
Debug.Indent();
|
||||
|
||||
glContext = new X11GLContext();
|
||||
(glContext as IGLContextCreationHack).SelectDisplayMode(mode, window);
|
||||
if (glContext == null)
|
||||
throw new ApplicationException("Could not create GraphicsContext");
|
||||
Debug.Print("Created GraphicsContext");
|
||||
window.VisualInfo = ((X11WindowInfo)((IGLContextInternal)glContext).Info).VisualInfo;
|
||||
//window.VisualInfo = Marshal.PtrToStructure(Glx.ChooseVisual(window.Display, window.Screen,
|
||||
|
||||
// Create a window on this display using the visual above
|
||||
Debug.Write("Opening render window... ");
|
||||
|
||||
XSetWindowAttributes attributes = new XSetWindowAttributes();
|
||||
attributes.background_pixel = IntPtr.Zero;
|
||||
attributes.border_pixel = IntPtr.Zero;
|
||||
attributes.colormap =
|
||||
API.CreateColormap(window.Display, window.RootWindow, window.VisualInfo.visual, 0/*AllocNone*/);
|
||||
window.EventMask =
|
||||
EventMask.StructureNotifyMask | EventMask.SubstructureNotifyMask | EventMask.ExposureMask |
|
||||
EventMask.KeyReleaseMask | EventMask.KeyPressMask |
|
||||
EventMask.PointerMotionMask | /* Bad! EventMask.PointerMotionHintMask | */
|
||||
EventMask.ButtonPressMask | EventMask.ButtonReleaseMask;
|
||||
attributes.event_mask = (IntPtr)window.EventMask;
|
||||
|
||||
uint mask = (uint)SetWindowValuemask.ColorMap | (uint)SetWindowValuemask.EventMask |
|
||||
(uint)SetWindowValuemask.BackPixel | (uint)SetWindowValuemask.BorderPixel;
|
||||
|
||||
window.Handle = Functions.XCreateWindow(window.Display, window.RootWindow,
|
||||
0, 0, width, height, 0, window.VisualInfo.depth/*(int)CreateWindowArgs.CopyFromParent*/,
|
||||
(int)CreateWindowArgs.InputOutput, window.VisualInfo.visual, (UIntPtr)mask, ref attributes);
|
||||
|
||||
if (window.Handle == IntPtr.Zero)
|
||||
throw new ApplicationException("XCreateWindow call failed (returned 0).");
|
||||
|
||||
// Set the window hints
|
||||
XSizeHints hints = new XSizeHints();
|
||||
hints.x = 0;
|
||||
hints.y = 0;
|
||||
hints.width = width;
|
||||
hints.height = height;
|
||||
hints.flags = (IntPtr)(XSizeHintsFlags.USSize | XSizeHintsFlags.USPosition);
|
||||
Functions.XSetWMNormalHints(window.Display, window.Handle, ref hints);
|
||||
|
||||
// Register for window destroy notification
|
||||
IntPtr wm_destroy_atom = Functions.XInternAtom(window.Display,
|
||||
"WM_DELETE_WINDOW", true);
|
||||
//XWMHints hint = new XWMHints();
|
||||
Functions.XSetWMProtocols(window.Display, window.Handle, new IntPtr[] { wm_destroy_atom }, 1);
|
||||
|
||||
Top = Left = 0;
|
||||
Right = Width;
|
||||
Bottom = Height;
|
||||
|
||||
//XTextProperty text = new XTextProperty();
|
||||
//text.value = "OpenTK Game Window";
|
||||
//text.format = 8;
|
||||
//Functions.XSetWMName(window.Display, window.Handle, ref text);
|
||||
//Functions.XSetWMProperties(display, window, name, name, 0, /*None*/ null, 0, hints);
|
||||
|
||||
Debug.Print("done! (id: {0})", window.Handle);
|
||||
|
||||
(glContext as IGLContextCreationHack).SetWindowHandle(window.Handle);
|
||||
|
||||
API.MapRaised(window.Display, window.Handle);
|
||||
mapped = true;
|
||||
|
||||
glContext.CreateContext(true, null);
|
||||
|
||||
driver = new X11Input(window);
|
||||
|
||||
Debug.Unindent();
|
||||
Debug.WriteLine("GameWindow creation completed successfully!");
|
||||
exists = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void CreateWindow(int width, int height, DisplayMode mode, out IGraphicsContext glContext)
|
||||
|
||||
/// <summary>
|
||||
/// Opens a new render window with the given DisplayMode.
|
||||
/// </summary>
|
||||
/// <param name="mode">The DisplayMode of the render window.</param>
|
||||
/// <remarks>
|
||||
/// Creates the window visual and colormap. Associates the colormap/visual
|
||||
/// with the window and raises the window on top of the window stack.
|
||||
/// <para>
|
||||
/// Colormap creation is currently disabled.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public void CreateWindow(int width, int height, DisplayMode mode, out IGraphicsContext glContext)
|
||||
{
|
||||
this.CreateWindow(width, height);//, mode.ToGraphicsMode(), out glContext);
|
||||
glContext = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnCreate
|
||||
|
||||
public event CreateEvent Create;
|
||||
|
@ -581,7 +541,7 @@ namespace OpenTK.Platform.X11
|
|||
{
|
||||
get
|
||||
{
|
||||
return mode.Width;
|
||||
return width;
|
||||
}
|
||||
set
|
||||
{/*
|
||||
|
@ -610,7 +570,7 @@ namespace OpenTK.Platform.X11
|
|||
{
|
||||
get
|
||||
{
|
||||
return mode.Height;
|
||||
return height;
|
||||
}
|
||||
set
|
||||
{/*
|
||||
|
@ -639,8 +599,8 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
private void OnResize(ResizeEventArgs e)
|
||||
{
|
||||
mode.Width = e.Width;
|
||||
mode.Height = e.Height;
|
||||
width = e.Width;
|
||||
height = e.Height;
|
||||
if (this.Resize != null)
|
||||
{
|
||||
this.Resize(this, e);
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace OpenTK.Platform.X11
|
|||
/// </summary>
|
||||
internal sealed class X11Input : IInputDriver
|
||||
{
|
||||
X11WindowInfo window;
|
||||
//X11WindowInfo window;
|
||||
KeyboardDevice keyboard = new KeyboardDevice();
|
||||
MouseDevice mouse = new MouseDevice();
|
||||
List<KeyboardDevice> dummy_keyboard_list = new List<KeyboardDevice>(1);
|
||||
|
@ -50,7 +50,7 @@ namespace OpenTK.Platform.X11
|
|||
throw new ArgumentException("A valid parent window must be defined, in order to create an X11Input driver.");
|
||||
|
||||
//window = new X11WindowInfo(attach);
|
||||
window = (X11WindowInfo)attach;
|
||||
X11WindowInfo window = (X11WindowInfo)attach;
|
||||
|
||||
// Init mouse
|
||||
mouse.Description = "Default X11 mouse";
|
||||
|
@ -69,8 +69,6 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
keysyms = new IntPtr[(lastKeyCode - firstKeyCode + 1) * keysyms_per_keycode];
|
||||
Marshal.PtrToStructure(keysym_ptr, keysyms);
|
||||
//keysyms = (IntPtr[])Marshal.PtrToStructure(keysym_ptr, typeof(IntPtr[]));
|
||||
|
||||
API.Free(keysym_ptr);
|
||||
|
||||
KeyboardDevice kb = new KeyboardDevice();
|
||||
|
|
Loading…
Reference in a new issue