diff --git a/src/Game.cs b/src/Game.cs index 812fcff..ccddc96 100644 --- a/src/Game.cs +++ b/src/Game.cs @@ -644,7 +644,6 @@ namespace Microsoft.Xna.Framework if (GraphicsDevice != null) { GraphicsDevice.Present(); - Platform.Present(GraphicsDevice); } } diff --git a/src/GamePlatform.cs b/src/GamePlatform.cs index 4e46ad8..6b5eed0 100644 --- a/src/GamePlatform.cs +++ b/src/GamePlatform.cs @@ -101,39 +101,8 @@ namespace Microsoft.Xna.Framework /// public abstract void RunLoop(); - /// - /// Starts a device transition (windowed to full screen or vice versa). - /// - /// - /// Specifies whether the device will be in full-screen mode upon completion of - /// the change. - /// - public abstract void BeginScreenDeviceChange( - bool willBeFullScreen - ); - - /// - /// Completes a device transition. - /// - /// - /// Screen device name. - /// - /// - /// The new width of the game's client window. - /// - /// - /// The new height of the game's client window. - /// - public abstract void EndScreenDeviceChange( - string screenDeviceName, - int clientWidth, - int clientHeight - ); - public abstract void OnIsMouseVisibleChanged(bool visible); - public abstract void Present(GraphicsDevice device); - public abstract void ShowRuntimeError( String title, String message diff --git a/src/Graphics/GraphicsDevice.cs b/src/Graphics/GraphicsDevice.cs index 2abb4da..808d074 100644 --- a/src/Graphics/GraphicsDevice.cs +++ b/src/Graphics/GraphicsDevice.cs @@ -7,6 +7,15 @@ */ #endregion +#region WIIU_GAMEPAD Option +// #define WIIU_GAMEPAD +/* This is something I added for myself, because I am a complete goof. + * You should NEVER enable this in your shipping build. + * Let your hacker customers self-build FNA, they'll know what to do. + * -flibit + */ +#endregion + #region Using Statements using System; using System.Collections.Generic; @@ -406,6 +415,28 @@ namespace Microsoft.Xna.Framework.Graphics // Set the default viewport and scissor rect. Viewport = new Viewport(PresentationParameters.Bounds); ScissorRectangle = Viewport.Bounds; + +#if WIIU_GAMEPAD + wiiuStream = DRC.drc_new_streamer(); + if (wiiuStream == IntPtr.Zero) + { + System.Console.WriteLine("Failed to alloc GamePad stream!"); + return; + } + if (DRC.drc_start_streamer(wiiuStream) < 1) // ??? + { + System.Console.WriteLine("Failed to start GamePad stream!"); + DRC.drc_delete_streamer(wiiuStream); + wiiuStream = IntPtr.Zero; + return; + } + DRC.drc_enable_system_input_feeder(wiiuStream); + wiiuPixelData = new byte[ + PresentationParameters.BackBufferWidth * + PresentationParameters.BackBufferHeight * + 4 + ]; +#endif } ~GraphicsDevice() @@ -449,6 +480,15 @@ namespace Microsoft.Xna.Framework.Graphics // Dispose of the GL Device/Context GLDevice.Dispose(); + +#if WIIU_GAMEPAD + if (wiiuStream != IntPtr.Zero) + { + DRC.drc_stop_streamer(wiiuStream); + DRC.drc_delete_streamer(wiiuStream); + wiiuStream = IntPtr.Zero; + } +#endif } IsDisposed = true; @@ -486,6 +526,21 @@ namespace Microsoft.Xna.Framework.Graphics null, PresentationParameters.DeviceWindowHandle ); +#if WIIU_GAMEPAD + if (wiiuStream != IntPtr.Zero) + { + GetBackBufferData(wiiuPixelData); + DRC.drc_push_vid_frame( + wiiuStream, + wiiuPixelData, + (uint) wiiuPixelData.Length, + (ushort) GLDevice.Backbuffer.Width, + (ushort) GLDevice.Backbuffer.Height, + DRC.drc_pixel_format.DRC_RGBA, + DRC.drc_flipping_mode.DRC_NO_FLIP + ); + } +#endif } public void Present( @@ -498,6 +553,21 @@ namespace Microsoft.Xna.Framework.Graphics destinationRectangle, overrideWindowHandle ); +#if WIIU_GAMEPAD + if (wiiuStream != IntPtr.Zero) + { + GetBackBufferData(wiiuPixelData); + DRC.drc_push_vid_frame( + wiiuStream, + wiiuPixelData, + (uint) wiiuPixelData.Length, + (ushort) GLDevice.Backbuffer.Width, + (ushort) GLDevice.Backbuffer.Height, + DRC.drc_pixel_format.DRC_RGBA, + DRC.drc_flipping_mode.DRC_NO_FLIP + ); + } +#endif } #endregion @@ -564,6 +634,14 @@ namespace Microsoft.Xna.Framework.Graphics RenderTargetCount > 0 ); +#if WIIU_GAMEPAD + wiiuPixelData = new byte[ + PresentationParameters.BackBufferWidth * + PresentationParameters.BackBufferHeight * + 4 + ]; +#endif + // Now, update the viewport Viewport = new Viewport( 0, @@ -1335,5 +1413,67 @@ namespace Microsoft.Xna.Framework.Graphics } #endregion + + #region Wii U GamePad Support, libdrc Interop + +#if WIIU_GAMEPAD + private static class DRC + { + // FIXME: Deal with Mac/Windows LibName later. + private const string nativeLibName = "libdrc.so"; + + public enum drc_pixel_format + { + DRC_RGB, + DRC_RGBA, + DRC_BGR, + DRC_BGRA, + DRC_RGB565 + } + + public enum drc_flipping_mode + { + DRC_NO_FLIP, + DRC_FLIP_VERTICALLY + } + + /* IntPtr refers to a drc_streamer* */ + [DllImportAttribute(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr drc_new_streamer(); + + /* self refers to a drc_streamer* */ + [DllImportAttribute(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void drc_delete_streamer(IntPtr self); + + /* self refers to a drc_streamer* */ + [DllImportAttribute(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern int drc_start_streamer(IntPtr self); + + /* self refers to a drc_streamer* */ + [DllImportAttribute(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void drc_stop_streamer(IntPtr self); + + /* self refers to a drc_streamer* */ + [DllImportAttribute(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern int drc_push_vid_frame( + IntPtr self, + byte[] buffer, + uint size, + ushort width, + ushort height, + drc_pixel_format pixfmt, + drc_flipping_mode flipmode + ); + + /* self refers to a drc_streamer* */ + [DllImportAttribute(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void drc_enable_system_input_feeder(IntPtr self); + } + + private IntPtr wiiuStream; + private byte[] wiiuPixelData; +#endif + + #endregion } } diff --git a/src/GraphicsDeviceManager.cs b/src/GraphicsDeviceManager.cs index 375d841..6ee8096 100644 --- a/src/GraphicsDeviceManager.cs +++ b/src/GraphicsDeviceManager.cs @@ -251,10 +251,10 @@ namespace Microsoft.Xna.Framework } // Make the Platform device changes. - game.Platform.BeginScreenDeviceChange( + game.Window.BeginScreenDeviceChange( GraphicsDevice.PresentationParameters.IsFullScreen ); - game.Platform.EndScreenDeviceChange( + game.Window.EndScreenDeviceChange( "FNA", GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight @@ -290,8 +290,8 @@ namespace Microsoft.Xna.Framework PreferredBackBufferHeight; // Apply settings. - game.Platform.BeginScreenDeviceChange(IsFullScreen); - game.Platform.EndScreenDeviceChange( + game.Window.BeginScreenDeviceChange(IsFullScreen); + game.Window.EndScreenDeviceChange( "FNA", GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight diff --git a/src/SDL2/SDL2_GamePlatform.cs b/src/SDL2/SDL2_GamePlatform.cs index 45c3dcb..bd45fb5 100644 --- a/src/SDL2/SDL2_GamePlatform.cs +++ b/src/SDL2/SDL2_GamePlatform.cs @@ -24,15 +24,6 @@ */ #endregion -#region WIIU_GAMEPAD Option -// #define WIIU_GAMEPAD -/* This is something I added for myself, because I am a complete goof. - * You should NEVER enable this in your shipping build. - * Let your hacker customers self-build FNA, they'll know what to do. - * -flibit - */ -#endregion - #region Using Statements using System; using System.IO; @@ -49,68 +40,6 @@ namespace Microsoft.Xna.Framework { class SDL2_GamePlatform : GamePlatform { - #region Wii U GamePad Support, libdrc Interop - -#if WIIU_GAMEPAD - private static class DRC - { - // FIXME: Deal with Mac/Windows LibName later. - private const string nativeLibName = "libdrc.so"; - - public enum drc_pixel_format - { - DRC_RGB, - DRC_RGBA, - DRC_BGR, - DRC_BGRA, - DRC_RGB565 - } - - public enum drc_flipping_mode - { - DRC_NO_FLIP, - DRC_FLIP_VERTICALLY - } - - /* IntPtr refers to a drc_streamer* */ - [DllImportAttribute(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr drc_new_streamer(); - - /* self refers to a drc_streamer* */ - [DllImportAttribute(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void drc_delete_streamer(IntPtr self); - - /* self refers to a drc_streamer* */ - [DllImportAttribute(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int drc_start_streamer(IntPtr self); - - /* self refers to a drc_streamer* */ - [DllImportAttribute(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void drc_stop_streamer(IntPtr self); - - /* self refers to a drc_streamer* */ - [DllImportAttribute(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int drc_push_vid_frame( - IntPtr self, - byte[] buffer, - uint size, - ushort width, - ushort height, - drc_pixel_format pixfmt, - drc_flipping_mode flipmode - ); - - /* self refers to a drc_streamer* */ - [DllImportAttribute(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void drc_enable_system_input_feeder(IntPtr self); - } - - private IntPtr wiiuStream; - private byte[] wiiuPixelData; -#endif - - #endregion - #region Private OSX-specific Variables private bool INTERNAL_useFullscreenSpaces; @@ -236,25 +165,6 @@ namespace Microsoft.Xna.Framework // Ready to run the loop! INTERNAL_runApplication = true; - -#if WIIU_GAMEPAD - wiiuStream = DRC.drc_new_streamer(); - if (wiiuStream == IntPtr.Zero) - { - System.Console.WriteLine("Failed to alloc GamePad stream!"); - return; - } - if (DRC.drc_start_streamer(wiiuStream) < 1) // ??? - { - System.Console.WriteLine("Failed to start GamePad stream!"); - DRC.drc_delete_streamer(wiiuStream); - wiiuStream = IntPtr.Zero; - return; - } - DRC.drc_enable_system_input_feeder(wiiuStream); - Rectangle bounds = game.Window.ClientBounds; - wiiuPixelData = new byte[bounds.Width * bounds.Height * 4]; -#endif } #endregion @@ -483,44 +393,11 @@ namespace Microsoft.Xna.Framework } } - public override void BeginScreenDeviceChange(bool willBeFullScreen) - { - Game.Window.BeginScreenDeviceChange(willBeFullScreen); - } - - public override void EndScreenDeviceChange(string screenDeviceName, int clientWidth, int clientHeight) - { - Game.Window.EndScreenDeviceChange(screenDeviceName, clientWidth, clientHeight); - -#if WIIU_GAMEPAD - wiiuPixelData = new byte[clientWidth * clientHeight * 4]; -#endif - } - public override void Log(string Message) { Console.WriteLine(Message); } - public override void Present(GraphicsDevice device) - { -#if WIIU_GAMEPAD - if (wiiuStream != IntPtr.Zero) - { - device.GetBackBufferData(wiiuPixelData); - DRC.drc_push_vid_frame( - wiiuStream, - wiiuPixelData, - (uint) wiiuPixelData.Length, - (ushort) device.GLDevice.Backbuffer.Width, - (ushort) device.GLDevice.Backbuffer.Height, - DRC.drc_pixel_format.DRC_RGBA, - DRC.drc_flipping_mode.DRC_NO_FLIP - ); - } -#endif - } - public override void ShowRuntimeError(string title, string message) { SDL.SDL_ShowSimpleMessageBox( @@ -920,15 +797,6 @@ namespace Microsoft.Xna.Framework Game.Window = null; } -#if WIIU_GAMEPAD - if (wiiuStream != IntPtr.Zero) - { - DRC.drc_stop_streamer(wiiuStream); - DRC.drc_delete_streamer(wiiuStream); - wiiuStream = IntPtr.Zero; - } -#endif - // This _should_ be the last SDL call we make... SDL.SDL_Quit(); }