Addressed comments

This commit is contained in:
Manuel Zanin 2017-03-21 10:21:22 +01:00
parent 8ffe3bc504
commit 70ac147b5c
7 changed files with 69 additions and 74 deletions

View file

@ -130,15 +130,15 @@ namespace OpenTK.Graphics
minor = 0; minor = 0;
// Angle needs an embedded context // Angle needs an embedded context
var use_angle_flag = GraphicsContextFlags.Angle const GraphicsContextFlags useAngleFlag = GraphicsContextFlags.Angle
| GraphicsContextFlags.AngleD3D9 | GraphicsContextFlags.AngleD3D9
| GraphicsContextFlags.AngleD3D11 | GraphicsContextFlags.AngleD3D11
| GraphicsContextFlags.AngleOpenGL; | GraphicsContextFlags.AngleOpenGL;
var use_angle = false; var useAngle = false;
if ((flags & use_angle_flag) != 0) if ((flags & useAngleFlag) != 0)
{ {
flags |= GraphicsContextFlags.Embedded; flags |= GraphicsContextFlags.Embedded;
use_angle = true; useAngle = true;
} }
Debug.Print("Creating GraphicsContext."); Debug.Print("Creating GraphicsContext.");
@ -164,7 +164,7 @@ namespace OpenTK.Graphics
factory = Factory.Default; factory = Factory.Default;
break; break;
case true: case true:
factory = use_angle ? Factory.Angle : Factory.Embedded; factory = useAngle ? Factory.Angle : Factory.Embedded;
break; break;
} }

View file

@ -212,8 +212,7 @@ namespace OpenTK.Platform.Egl
public static extern bool QuerySurfacePointerANGLE(EGLDisplay display, EGLSurface surface, int attribute, out IntPtr value); public static extern bool QuerySurfacePointerANGLE(EGLDisplay display, EGLSurface surface, int attribute, out IntPtr value);
[DllImport("libEGL.dll", EntryPoint = "eglGetPlatformDisplayEXT")] [DllImport("libEGL.dll", EntryPoint = "eglGetPlatformDisplayEXT")]
public static extern EGLDisplay GetPlatformDisplay(int platform, EGLNativeDisplayType display_id, public static extern EGLDisplay GetPlatformDisplay(int platform, EGLNativeDisplayType displayId, int[] attribList);
int[] attrib_list);
// EGL_ANGLE_software_display // EGL_ANGLE_software_display
public static readonly EGLNativeDisplayType SOFTWARE_DISPLAY_ANGLE = new EGLNativeDisplayType(-1); public static readonly EGLNativeDisplayType SOFTWARE_DISPLAY_ANGLE = new EGLNativeDisplayType(-1);

View file

@ -90,11 +90,11 @@ namespace OpenTK.Platform.Egl
bool offscreen = (flags & GraphicsContextFlags.Offscreen) != 0; bool offscreen = (flags & GraphicsContextFlags.Offscreen) != 0;
SurfaceType surface_type = offscreen SurfaceType surfaceType = offscreen
? SurfaceType.PBUFFER_BIT ? SurfaceType.PBUFFER_BIT
: SurfaceType.WINDOW_BIT; : SurfaceType.WINDOW_BIT;
Mode = new EglGraphicsMode().SelectGraphicsMode(surface_type, Mode = new EglGraphicsMode().SelectGraphicsMode(surfaceType,
window.Display, mode.ColorFormat, mode.Depth, mode.Stencil, window.Display, mode.ColorFormat, mode.Depth, mode.Stencil,
mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo, mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo,
Renderable); Renderable);
@ -115,9 +115,9 @@ namespace OpenTK.Platform.Egl
} }
} }
int[] attrib_list = new int[] { Egl.CONTEXT_CLIENT_VERSION, major, Egl.NONE }; int[] attribList = { Egl.CONTEXT_CLIENT_VERSION, major, Egl.NONE };
var share_context = shared != null ? shared.HandleAsEGLContext : IntPtr.Zero; var shareContext = shared?.HandleAsEGLContext ?? IntPtr.Zero;
HandleAsEGLContext = Egl.CreateContext(window.Display, config, share_context, attrib_list); HandleAsEGLContext = Egl.CreateContext(window.Display, config, shareContext, attribList);
GraphicsContextFlags = flags; GraphicsContextFlags = flags;
} }

View file

@ -26,8 +26,6 @@
#endregion #endregion
using System; using System;
using System.Collections.Generic;
using System.Text;
using OpenTK.Graphics; using OpenTK.Graphics;
namespace OpenTK.Platform.Egl namespace OpenTK.Platform.Egl
@ -46,25 +44,24 @@ namespace OpenTK.Platform.Egl
public GraphicsMode SelectGraphicsMode(EglWindowInfo window, public GraphicsMode SelectGraphicsMode(EglWindowInfo window,
ColorFormat color, int depth, int stencil, ColorFormat color, int depth, int stencil,
int samples, ColorFormat accum, int buffers, bool stereo, int samples, ColorFormat accum, int buffers, bool stereo,
RenderableFlags renderable_flags) RenderableFlags renderableFlags)
{ {
return SelectGraphicsMode( return SelectGraphicsMode(
SurfaceType.WINDOW_BIT, SurfaceType.WINDOW_BIT,
window.Display, window.Display,
color, depth, stencil, samples, accum, buffers, stereo, renderable_flags color, depth, stencil, samples, accum, buffers, stereo, renderableFlags);
);
} }
public GraphicsMode SelectGraphicsMode(SurfaceType surface_type, public GraphicsMode SelectGraphicsMode(SurfaceType surfaceType,
IntPtr display, ColorFormat color, int depth, int stencil, IntPtr display, ColorFormat color, int depth, int stencil,
int samples, ColorFormat accum, int buffers, bool stereo, int samples, ColorFormat accum, int buffers, bool stereo,
RenderableFlags renderable_flags) RenderableFlags renderableFlags)
{ {
IntPtr[] configs = new IntPtr[1]; IntPtr[] configs = new IntPtr[1];
int[] attribList = new int[] int[] attribList = new int[]
{ {
Egl.SURFACE_TYPE, (int) surface_type, Egl.SURFACE_TYPE, (int) surfaceType,
Egl.RENDERABLE_TYPE, (int)renderable_flags, Egl.RENDERABLE_TYPE, (int)renderableFlags,
Egl.RED_SIZE, color.Red, Egl.RED_SIZE, color.Red,
Egl.GREEN_SIZE, color.Green, Egl.GREEN_SIZE, color.Green,
@ -80,28 +77,27 @@ namespace OpenTK.Platform.Egl
Egl.NONE, Egl.NONE,
}; };
int num_configs; int numConfigs;
if (!Egl.ChooseConfig(display, attribList, configs, configs.Length, out num_configs) || num_configs == 0) if (!Egl.ChooseConfig(display, attribList, configs, configs.Length, out numConfigs) || numConfigs == 0)
{ {
throw new GraphicsModeException(String.Format("Failed to retrieve GraphicsMode, error {0}", Egl.GetError())); throw new GraphicsModeException(String.Format("Failed to retrieve GraphicsMode, error {0}", Egl.GetError()));
} }
// See what we really got // See what we really got
IntPtr active_config = configs[0]; IntPtr activeConfig = configs[0];
int r, g, b, a; int r, g, b, a;
Egl.GetConfigAttrib(display, active_config, Egl.RED_SIZE, out r); Egl.GetConfigAttrib(display, activeConfig, Egl.RED_SIZE, out r);
Egl.GetConfigAttrib(display, active_config, Egl.GREEN_SIZE, out g); Egl.GetConfigAttrib(display, activeConfig, Egl.GREEN_SIZE, out g);
Egl.GetConfigAttrib(display, active_config, Egl.BLUE_SIZE, out b); Egl.GetConfigAttrib(display, activeConfig, Egl.BLUE_SIZE, out b);
Egl.GetConfigAttrib(display, active_config, Egl.ALPHA_SIZE, out a); Egl.GetConfigAttrib(display, activeConfig, Egl.ALPHA_SIZE, out a);
int d, s; int d, s;
Egl.GetConfigAttrib(display, active_config, Egl.DEPTH_SIZE, out d); Egl.GetConfigAttrib(display, activeConfig, Egl.DEPTH_SIZE, out d);
Egl.GetConfigAttrib(display, active_config, Egl.STENCIL_SIZE, out s); Egl.GetConfigAttrib(display, activeConfig, Egl.STENCIL_SIZE, out s);
int sample_buffers; int sampleBuffers;
Egl.GetConfigAttrib(display, active_config, Egl.SAMPLES, out sample_buffers); Egl.GetConfigAttrib(display, activeConfig, Egl.SAMPLES, out sampleBuffers);
Egl.GetConfigAttrib(display, active_config, Egl.SAMPLES, out samples); Egl.GetConfigAttrib(display, activeConfig, Egl.SAMPLES, out samples);
return new GraphicsMode(active_config, new ColorFormat(r, g, b, a), d, s, sample_buffers > 0 ? samples : 0, 0, 2, false); return new GraphicsMode(activeConfig, new ColorFormat(r, g, b, a), d, s, sampleBuffers > 0 ? samples : 0, 0, 2, false);
} }
} }
} }

View file

@ -64,8 +64,8 @@ namespace OpenTK.Platform.Egl
Display = display; Display = display;
int dummy_major, dummy_minor; int dummyMajor, dummyMinor;
if (!Egl.Initialize(Display, out dummy_major, out dummy_minor)) if (!Egl.Initialize(Display, out dummyMajor, out dummyMinor))
{ {
throw new GraphicsContextException(String.Format("Failed to initialize EGL, error {0}.", Egl.GetError())); throw new GraphicsContextException(String.Format("Failed to initialize EGL, error {0}.", Egl.GetError()));
} }
@ -116,7 +116,7 @@ namespace OpenTK.Platform.Egl
CreatePbufferSurface(config, width, height, out surface); CreatePbufferSurface(config, width, height, out surface);
} }
public void CreatePbufferSurface(IntPtr config, int width, int height, out IntPtr surface_) public void CreatePbufferSurface(IntPtr config, int width, int height, out IntPtr bufferSurface)
{ {
int[] attribs = new int[] int[] attribs = new int[]
{ {
@ -126,13 +126,12 @@ namespace OpenTK.Platform.Egl
Egl.TEXTURE_FORMAT, Egl.TEXTURE_RGBA, Egl.TEXTURE_FORMAT, Egl.TEXTURE_RGBA,
Egl.NONE Egl.NONE
}; };
surface_ = Egl.CreatePbufferSurface(Display, config, attribs); bufferSurface = Egl.CreatePbufferSurface(Display, config, attribs);
if (surface_ == IntPtr.Zero) if (bufferSurface == IntPtr.Zero)
{ {
throw new GraphicsContextException(String.Format( throw new GraphicsContextException(String.Format(
"[EGL] Failed to create pbuffer surface, error {0}.", Egl.GetError())); "[EGL] Failed to create pbuffer surface, error {0}.", Egl.GetError()));
} }
} }
public void DestroySurface() public void DestroySurface()
@ -140,19 +139,20 @@ namespace OpenTK.Platform.Egl
DestroySurface(ref surface); DestroySurface(ref surface);
} }
public void DestroySurface(ref IntPtr surface_) public void DestroySurface(ref IntPtr bufferSurface)
{ {
if (surface_ == IntPtr.Zero) if (bufferSurface == IntPtr.Zero)
{ {
return; return;
} }
if (Egl.GetCurrentSurface(Egl.DRAW) == Surface) if (Egl.GetCurrentSurface(Egl.DRAW) == Surface)
Egl.MakeCurrent(Display, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
if (Egl.DestroySurface(Display, surface_))
{ {
surface_ = IntPtr.Zero; Egl.MakeCurrent(Display, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
}
if (Egl.DestroySurface(Display, bufferSurface))
{
bufferSurface = IntPtr.Zero;
return; return;
} }

View file

@ -26,9 +26,7 @@
#endregion #endregion
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Text;
using OpenTK.Platform.Egl; using OpenTK.Platform.Egl;
namespace OpenTK.Platform namespace OpenTK.Platform
@ -40,8 +38,10 @@ namespace OpenTK.Platform
{ {
#region Fields #region Fields
bool disposed; private bool disposed;
static IPlatformFactory default_implementation, embedded_implementation, angle_implementation; private static IPlatformFactory defaultImplementation;
private static IPlatformFactory embeddedImplementation;
private static IPlatformFactory angleImplementation;
#endregion #endregion
@ -122,20 +122,20 @@ namespace OpenTK.Platform
public static IPlatformFactory Default public static IPlatformFactory Default
{ {
get { return default_implementation; } get { return defaultImplementation; }
private set { default_implementation = value; } private set { defaultImplementation = value; }
} }
public static IPlatformFactory Embedded public static IPlatformFactory Embedded
{ {
get { return embedded_implementation; } get { return embeddedImplementation; }
private set { embedded_implementation = value; } private set { embeddedImplementation = value; }
} }
public static IPlatformFactory Angle public static IPlatformFactory Angle
{ {
get { return angle_implementation; } get { return angleImplementation; }
private set { angle_implementation = value; } private set { angleImplementation = value; }
} }
#endregion #endregion
@ -145,60 +145,60 @@ namespace OpenTK.Platform
public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title,
GraphicsMode mode, GameWindowFlags options, DisplayDevice device) GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
{ {
return default_implementation.CreateNativeWindow(x, y, width, height, title, mode, options, device); return defaultImplementation.CreateNativeWindow(x, y, width, height, title, mode, options, device);
} }
public IDisplayDeviceDriver CreateDisplayDeviceDriver() public IDisplayDeviceDriver CreateDisplayDeviceDriver()
{ {
return default_implementation.CreateDisplayDeviceDriver(); return defaultImplementation.CreateDisplayDeviceDriver();
} }
public IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags) public IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
{ {
return default_implementation.CreateGLContext(mode, window, shareContext, directRendering, major, minor, flags); return defaultImplementation.CreateGLContext(mode, window, shareContext, directRendering, major, minor, flags);
} }
public IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags) public IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
{ {
return default_implementation.CreateGLContext(handle, window, shareContext, directRendering, major, minor, flags); return defaultImplementation.CreateGLContext(handle, window, shareContext, directRendering, major, minor, flags);
} }
public GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext() public GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext()
{ {
return default_implementation.CreateGetCurrentGraphicsContext(); return defaultImplementation.CreateGetCurrentGraphicsContext();
} }
public IKeyboardDriver2 CreateKeyboardDriver() public IKeyboardDriver2 CreateKeyboardDriver()
{ {
return default_implementation.CreateKeyboardDriver(); return defaultImplementation.CreateKeyboardDriver();
} }
public IMouseDriver2 CreateMouseDriver() public IMouseDriver2 CreateMouseDriver()
{ {
return default_implementation.CreateMouseDriver(); return defaultImplementation.CreateMouseDriver();
} }
public IGamePadDriver CreateGamePadDriver() public IGamePadDriver CreateGamePadDriver()
{ {
return default_implementation.CreateGamePadDriver(); return defaultImplementation.CreateGamePadDriver();
} }
public IJoystickDriver2 CreateJoystickDriver() public IJoystickDriver2 CreateJoystickDriver()
{ {
return default_implementation.CreateJoystickDriver(); return defaultImplementation.CreateJoystickDriver();
} }
[Obsolete] [Obsolete]
public IJoystickDriver CreateLegacyJoystickDriver() public IJoystickDriver CreateLegacyJoystickDriver()
{ {
#pragma warning disable 612,618 #pragma warning disable 612,618
return default_implementation.CreateLegacyJoystickDriver(); return defaultImplementation.CreateLegacyJoystickDriver();
#pragma warning restore 612,618 #pragma warning restore 612,618
} }
public void RegisterResource(IDisposable resource) public void RegisterResource(IDisposable resource)
{ {
default_implementation.RegisterResource(resource); defaultImplementation.RegisterResource(resource);
} }
class UnsupportedPlatform : PlatformFactoryBase class UnsupportedPlatform : PlatformFactoryBase

View file

@ -401,11 +401,11 @@ namespace OpenTK.Platform
/// supplied platform window (e.g. a window created with /// supplied platform window (e.g. a window created with
/// CreateWindowsWindowInfo, or CreateDummyWindowInfo). /// CreateWindowsWindowInfo, or CreateDummyWindowInfo).
/// </summary> /// </summary>
/// <param name="platform_window"></param> /// <param name="platformWindow"></param>
/// <returns></returns> /// <returns></returns>
public static IAngleWindowInfo CreateAngleWindowInfo(IWindowInfo platform_window) public static IAngleWindowInfo CreateAngleWindowInfo(IWindowInfo platformWindow)
{ {
return new AngleWindowInfo(platform_window); return new AngleWindowInfo(platformWindow);
} }
#endregion #endregion