Permalink
Browse files

[EGL] Fixed display connection

We now use the display connection specified in EglWindowInfo
throughout the EGL backend, instead of opening new connections
in EglGraphicsMode. This fixes EGL errors in
Egl.CreateWindowSurface.

As part of this fix, all instances of
IPlatformFactory.CreateGraphicsMode() have been removed. This
API is no longer used in OpenTK 1.1
  • Loading branch information...
thefiddler committed May 19, 2014
1 parent 97b211a commit d483b01de0c461517817dc89478da5928c04475c
@@ -207,7 +207,7 @@ static partial class Egl
public static extern bool GetConfigAttrib(EGLDisplay dpy, EGLConfig config, int attribute, out int value);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglCreateWindowSurface")]
- public static extern EGLSurface CreateWindowSurface(EGLDisplay dpy, EGLConfig config, IntPtr win, int[] attrib_list);
+ public static extern EGLSurface CreateWindowSurface(EGLDisplay dpy, EGLConfig config, IntPtr win, IntPtr attrib_list);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglCreatePbufferSurface")]
public static extern EGLSurface CreatePbufferSurface(EGLDisplay dpy, EGLConfig config, int[] attrib_list);
@@ -55,19 +55,15 @@ abstract class EglContext : EmbeddedGraphicsContext
EglContext shared = (EglContext)sharedContext;
- int dummy_major, dummy_minor;
- if (!Egl.Initialize(window.Display, out dummy_major, out dummy_minor))
- throw new GraphicsContextException(String.Format("Failed to initialize EGL, error {0}.", Egl.GetError()));
-
WindowInfo = window;
// Select an EGLConfig that matches the desired mode. We cannot use the 'mode'
// parameter directly, since it may have originated on a different system (e.g. GLX)
// and it may not support the desired renderer.
Renderable = major > 1 ? RenderableFlags.ES2 : RenderableFlags.ES;
- Mode = new EglGraphicsMode().SelectGraphicsMode(mode.ColorFormat,
- mode.Depth, mode.Stencil, mode.Samples, mode.AccumulatorFormat,
- mode.Buffers, mode.Stereo,
+ Mode = new EglGraphicsMode().SelectGraphicsMode(window,
+ mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples,
+ mode.AccumulatorFormat, mode.Buffers, mode.Stereo,
Renderable);
if (!Mode.Index.HasValue)
throw new GraphicsModeException("Invalid or unsupported GraphicsMode.");
@@ -32,31 +32,17 @@
namespace OpenTK.Platform.Egl
{
- class EglGraphicsMode : IGraphicsMode
+ class EglGraphicsMode
{
- #region IGraphicsMode Members
-
- public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil,
- int samples, ColorFormat accum, int buffers, bool stereo)
- {
- // According to the EGL specs, the ES flag should select ES 1.0 or higher, which
- // makes sense as a default. EglContext.cs checks
- return SelectGraphicsMode(color, depth, stencil, samples, accum, buffers, stereo,
- RenderableFlags.ES);
- }
-
- #endregion
-
- #region Public Members
-
- public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil,
+ public GraphicsMode SelectGraphicsMode(EglWindowInfo window,
+ ColorFormat color, int depth, int stencil,
int samples, ColorFormat accum, int buffers, bool stereo,
RenderableFlags renderable_flags)
{
IntPtr[] configs = new IntPtr[1];
int[] attribList = new int[]
{
- //Egl.SURFACE_TYPE, Egl.WINDOW_BIT,
+ Egl.SURFACE_TYPE, Egl.WINDOW_BIT,
Egl.RENDERABLE_TYPE, (int)renderable_flags,
Egl.RED_SIZE, color.Red,
@@ -73,11 +59,7 @@ class EglGraphicsMode : IGraphicsMode
Egl.NONE,
};
- // Todo: what if we don't wish to use the default display?
- IntPtr display = Egl.GetDisplay(IntPtr.Zero);
- int major, minor;
- if (!Egl.Initialize(display, out major, out minor))
- throw new GraphicsModeException(String.Format("Failed to initialize display connection, error {0}", Egl.GetError()));
+ IntPtr display = window.Display;
int num_configs;
if (!Egl.ChooseConfig(display, attribList, configs, configs.Length, out num_configs) || num_configs == 0)
@@ -101,7 +83,5 @@ class EglGraphicsMode : IGraphicsMode
return new GraphicsMode(active_config, new ColorFormat(r, g, b, a), d, s, sample_buffers > 0 ? samples : 0, 0, 2, false);
}
-
- #endregion
}
}
@@ -63,11 +63,6 @@ public override GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphi
};
}
- public override IGraphicsMode CreateGraphicsMode()
- {
- return new EglGraphicsMode();
- }
-
#endregion
#region Private Members
@@ -45,19 +45,30 @@ class EglWindowInfo : IWindowInfo
#endregion
- #region Constructiors
+ #region Constructors
public EglWindowInfo(IntPtr handle, IntPtr display)
+ : this(handle, display, IntPtr.Zero)
{
- Handle = handle;
- Display = display;
}
public EglWindowInfo(IntPtr handle, IntPtr display, IntPtr surface)
{
Handle = handle;
- Display = display;
Surface = surface;
+
+ if (display == IntPtr.Zero)
+ {
+ display = Egl.GetDisplay(IntPtr.Zero);
+ }
+
+ Display = display;
+
+ int dummy_major, dummy_minor;
+ if (!Egl.Initialize(Display, out dummy_major, out dummy_minor))
+ {
+ throw new GraphicsContextException(String.Format("Failed to initialize EGL, error {0}.", Egl.GetError()));
+ }
}
#endregion
@@ -72,7 +83,7 @@ public EglWindowInfo(IntPtr handle, IntPtr display, IntPtr surface)
public void CreateWindowSurface(IntPtr config)
{
- Surface = Egl.CreateWindowSurface(Display, config, Handle, null);
+ Surface = Egl.CreateWindowSurface(Display, config, Handle, IntPtr.Zero);
if (Surface==IntPtr.Zero)
{
throw new GraphicsContextException(String.Format(
@@ -130,11 +130,6 @@ public GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext
return default_implementation.CreateGetCurrentGraphicsContext();
}
- public IGraphicsMode CreateGraphicsMode()
- {
- return default_implementation.CreateGraphicsMode();
- }
-
public IKeyboardDriver2 CreateKeyboardDriver()
{
return default_implementation.CreateKeyboardDriver();
@@ -195,11 +190,6 @@ public override GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphi
throw new PlatformNotSupportedException(error_string);
}
- public override IGraphicsMode CreateGraphicsMode()
- {
- throw new PlatformNotSupportedException(error_string);
- }
-
public override IKeyboardDriver2 CreateKeyboardDriver()
{
throw new PlatformNotSupportedException(error_string);
@@ -45,8 +45,6 @@ interface IPlatformFactory : IDisposable
GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext();
- IGraphicsMode CreateGraphicsMode();
-
OpenTK.Input.IKeyboardDriver2 CreateKeyboardDriver();
OpenTK.Input.IMouseDriver2 CreateMouseDriver();
@@ -63,11 +63,6 @@ public virtual IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInf
public abstract GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext();
- public virtual IGraphicsMode CreateGraphicsMode()
- {
- throw new NotSupportedException();
- }
-
public abstract IKeyboardDriver2 CreateKeyboardDriver();
public abstract IMouseDriver2 CreateMouseDriver();
@@ -76,11 +76,6 @@ public override GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphi
};
}
- public override IGraphicsMode CreateGraphicsMode()
- {
- throw new NotSupportedException();
- }
-
public override IKeyboardDriver2 CreateKeyboardDriver()
{
return new X11Keyboard();
Oops, something went wrong.

0 comments on commit d483b01

Please sign in to comment.