Permalink
Browse files

Removed the background GL context, we schedule or block tasks on the …

…UI thread which run in Tick()
  • Loading branch information...
1 parent ba97b4f commit 5c21ce4e4a66386dbccf1041a8c242398ffeb5ca @renaudbedard committed Aug 6, 2013
Showing with 45 additions and 8 deletions.
  1. +4 −2 MonoGame.Framework/Desktop/OpenTKGameWindow.cs
  2. +41 −6 MonoGame.Framework/Threading.cs
@@ -366,8 +366,8 @@ private void Initialize()
}
#endif
// Provide the graphics context for background loading
- Threading.BackgroundContext = new GraphicsContext(stencilGraphicsMode, window.WindowInfo);
- Threading.WindowInfo = window.WindowInfo;
+ //Threading.BackgroundContext = new GraphicsContext(stencilGraphicsMode, window.WindowInfo);
+ //Threading.WindowInfo = window.WindowInfo;
keys = new List<Keys>();
@@ -437,12 +437,14 @@ protected virtual void Dispose(bool disposing)
}
// Release native resources
+ /*
if (Threading.BackgroundContext != null)
{
Threading.BackgroundContext.Dispose();
Threading.BackgroundContext = null;
Threading.WindowInfo = null;
}
+ */
disposed = true;
}
@@ -64,14 +64,14 @@ internal class Threading
{
static int mainThreadId;
static int currentThreadId;
-#if ANDROID
+//#if ANDROID
static List<Action> actions = new List<Action>();
static Mutex actionsMutex = new Mutex();
-#elif IOS
+#if IOS
public static EAGLContext BackgroundContext;
#elif WINDOWS || LINUX
- public static IGraphicsContext BackgroundContext;
- public static IWindowInfo WindowInfo;
+ //public static IGraphicsContext BackgroundContext;
+ //public static IWindowInfo WindowInfo;
#endif
static Threading()
{
@@ -130,6 +130,7 @@ internal static void BlockOnUIThread(Action action)
GraphicsExtensions.CheckGLError();
}
#elif WINDOWS || LINUX
+ /*
if (BackgroundContext == null)
action();
else lock (BackgroundContext)
@@ -144,6 +145,16 @@ internal static void BlockOnUIThread(Action action)
// Must make the context not current on this thread or the next thread will get error 170 from the MakeCurrent call
BackgroundContext.MakeCurrent(null);
}
+ */
+
+ ManualResetEventSlim resetEvent = new ManualResetEventSlim(false);
+ Add(() =>
+ {
+ action();
+ resetEvent.Set();
+ });
+ resetEvent.Wait();
+
#else
ManualResetEventSlim resetEvent = new ManualResetEventSlim(false);
#if MONOMAC
@@ -164,7 +175,22 @@ internal static void BlockOnUIThread(Action action)
#endif
}
-#if ANDROID
+ internal static void ScheduleOnUIThread(Action action)
+ {
+ if (action == null)
+ throw new ArgumentNullException("action");
+
+ // If we are already on the UI thread, just call the action and be done with it
+ if (mainThreadId == Thread.CurrentThread.ManagedThreadId)
+ {
+ action();
+ return;
+ }
+
+ Add(action);
+ }
+
+//#if ANDROID
static void Add(Action action)
{
lock (actions)
@@ -189,6 +215,15 @@ internal static void Run()
actions.Clear();
}
}
-#endif
+
+ internal static bool HasPendingActions
+ {
+ get
+ {
+ lock (actions)
+ return actions.Count > 0;
+ }
+ }
+//#endif
}
}

0 comments on commit 5c21ce4

Please sign in to comment.