diff --git a/src/Content/ContentManager.cs b/src/Content/ContentManager.cs index b16c0c1..877d7cc 100644 --- a/src/Content/ContentManager.cs +++ b/src/Content/ContentManager.cs @@ -380,7 +380,7 @@ namespace Microsoft.Xna.Framework.Content else if ((typeof(T) == typeof(Video))) { // FIXME: Not using the stream! -flibit - result = new Video(modifiedAssetName); + result = new Video(modifiedAssetName, graphicsDeviceService.GraphicsDevice); } else { diff --git a/src/Content/ContentReaders/VideoReader.cs b/src/Content/ContentReaders/VideoReader.cs index d329f7f..2407af2 100644 --- a/src/Content/ContentReaders/VideoReader.cs +++ b/src/Content/ContentReaders/VideoReader.cs @@ -63,7 +63,15 @@ namespace Microsoft.Xna.Framework.Content float framesPerSecond = input.ReadObject(); VideoSoundtrackType soundTrackType = (VideoSoundtrackType) input.ReadObject(); - return new Video(path, durationMS, width, height, framesPerSecond, soundTrackType); + return new Video( + path, + input.GraphicsDevice, + durationMS, + width, + height, + framesPerSecond, + soundTrackType + ); } #endregion diff --git a/src/Game.cs b/src/Game.cs index b3cad12..a6e83d9 100644 --- a/src/Game.cs +++ b/src/Game.cs @@ -211,9 +211,6 @@ namespace Microsoft.Xna.Framework #region Internal Fields - /* This variable solely exists for the VideoPlayer -flibit */ - internal static Game Instance = null; - internal bool RunApplication; #endregion @@ -278,8 +275,6 @@ namespace Microsoft.Xna.Framework public Game() { - Instance = this; - AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; LaunchParameters = new LaunchParameters(); @@ -362,7 +357,6 @@ namespace Microsoft.Xna.Framework AppDomain.CurrentDomain.UnhandledException -= OnUnhandledException; _isDisposed = true; - Instance = null; } } diff --git a/src/Media/Xiph/Video.cs b/src/Media/Xiph/Video.cs index 3295f88..b002b93 100644 --- a/src/Media/Xiph/Video.cs +++ b/src/Media/Xiph/Video.cs @@ -11,6 +11,8 @@ using System; using System.IO; using System.Threading; + +using Microsoft.Xna.Framework.Graphics; #endregion namespace Microsoft.Xna.Framework.Media @@ -66,6 +68,12 @@ namespace Microsoft.Xna.Framework.Media set; } + internal GraphicsDevice GraphicsDevice + { + get; + private set; + } + #endregion #region Internal Variables: TheoraPlay @@ -83,9 +91,10 @@ namespace Microsoft.Xna.Framework.Media #region Internal Constructors - internal Video(string fileName) + internal Video(string fileName, GraphicsDevice device) { this.fileName = fileName; + GraphicsDevice = device; // Set everything to NULL. Yes, this actually matters later. theoraDecoder = IntPtr.Zero; @@ -102,12 +111,13 @@ namespace Microsoft.Xna.Framework.Media internal Video( string fileName, + GraphicsDevice device, int durationMS, int width, int height, float framesPerSecond, VideoSoundtrackType soundtrackType - ) : this(fileName) { + ) : this(fileName, device) { /* If you got here, you've still got the XNB file! Well done! * Except if you're running FNA, you're not using the WMV anymore. * But surely it's the same video, right...? diff --git a/src/Media/Xiph/VideoPlayer.cs b/src/Media/Xiph/VideoPlayer.cs index 6c62f30..9720e55 100644 --- a/src/Media/Xiph/VideoPlayer.cs +++ b/src/Media/Xiph/VideoPlayer.cs @@ -382,27 +382,7 @@ namespace Microsoft.Xna.Framework.Media // Initialize private members. timer = new Stopwatch(); - - // The VideoPlayer will use the GraphicsDevice that is set now. - currentDevice = Game.Instance.GraphicsDevice; - - // Initialize this here to prevent null GetTexture returns. videoTexture = new RenderTargetBinding[1]; - videoTexture[0] = new RenderTargetBinding( - new RenderTarget2D( - currentDevice, - 1280, - 720, - false, - SurfaceFormat.Color, - DepthFormat.None, - 0, - RenderTargetUsage.PreserveContents - ) - ); - - // Initialize the other GL bits. - GL_initialize(); } public void Dispose() @@ -431,6 +411,11 @@ namespace Microsoft.Xna.Framework.Media { checkDisposed(); + if (Video == null) + { + throw new InvalidOperationException(); + } + // Be sure we can even get something from TheoraPlay... if ( State == MediaState.Stopped || Video.theoraDecoder == IntPtr.Zero || @@ -617,6 +602,17 @@ namespace Microsoft.Xna.Framework.Media } while (Video.videoStream == IntPtr.Zero); nextVideo = TheoraPlay.getVideoFrame(Video.videoStream); + // The VideoPlayer will use the GraphicsDevice that is set now. + if (currentDevice != Video.GraphicsDevice) + { + if (currentDevice != null) + { + GL_dispose(); + } + currentDevice = Video.GraphicsDevice; + GL_initialize(); + } + RenderTargetBinding overlap = videoTexture[0]; videoTexture[0] = new RenderTargetBinding( new RenderTarget2D( @@ -630,7 +626,10 @@ namespace Microsoft.Xna.Framework.Media RenderTargetUsage.PreserveContents ) ); - overlap.RenderTarget.Dispose(); + if (overlap.RenderTarget != null) + { + overlap.RenderTarget.Dispose(); + } GL_setupTextures( (int) currentVideo.width, (int) currentVideo.height