Permalink
Browse files

Merge branch 'branch_develop3d_GLContextLostReloadResources' into dev…

…elop3d
  • Loading branch information...
Aranda committed Aug 1, 2012
2 parents 9ed4a4d + 93a291a commit 26539aa2d89ee335f770cee036690ae1137632ff
@@ -78,6 +78,12 @@ protected override void OnResume()
(deviceManager as GraphicsDeviceManager).ForceSetFullScreen();
Game.Window.RequestFocus();
}
+
+ protected override void OnRestart()
+ {
+ base.OnRestart();
+ Game.Window.OnRestart();
+ }
}
public static class ActivityExtensions
@@ -71,6 +71,7 @@ public class AndroidGameWindow : AndroidGameView , Android.Views.View.IOnTouchLi
private DisplayOrientation _currentOrientation;
private AndroidTouchEventManager _touchManager = null;
private bool exiting = false;
+ private bool _contextWasLost = false;
public bool TouchEnabled
{
@@ -146,7 +147,15 @@ public override bool OnKeyUp(Keycode keyCode, KeyEvent e)
{
//
}
-
+
+ internal void OnRestart()
+ {
+ // If restarting, check if the context was lost. It appears that it always is,
+ // but I suspect that it's possible to avoid this case as some games don't need
+ // to reload their textures after switching back from another app.
+ _contextWasLost = GraphicsContext == null || GraphicsContext.IsDisposed;
+ }
+
protected override void CreateFrameBuffer()
{
Android.Util.Log.Debug("MonoGame", "AndroidGameWindow.CreateFrameBuffer");
@@ -155,20 +164,28 @@ protected override void CreateFrameBuffer()
{
GLContextVersion = GLContextVersion.Gles2_0;
base.CreateFrameBuffer();
+ Android.Util.Log.Debug("MonoGame", "AndroidGameWindow.CreateFrameBuffer");
}
catch (Exception)
#endif
{
throw new NotSupportedException("Could not create OpenGLES 2.0 frame buffer");
}
- if (_game.GraphicsDevice != null)
+ if (_game.GraphicsDevice != null && _contextWasLost)
{
+ _contextWasLost = false;
_game.GraphicsDevice.Initialize();
+ EffectPass.RecompileAll();
+ Microsoft.Xna.Framework.Content.ContentManager.ReloadGraphicsContent();
+
+ _game.graphicsDeviceManager.OnDeviceReset(EventArgs.Empty);
+ _game.GraphicsDevice.OnDeviceReset();
}
if (!GraphicsContext.IsCurrent)
MakeCurrent();
}
+
protected override void DestroyFrameBuffer()
{
Android.Util.Log.Debug("MonoGame", "AndroidGameWindow.DestroyFrameBuffer");
Oops, something went wrong.

0 comments on commit 26539aa

Please sign in to comment.