*/␊ |
#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;␊ |
|
␉␉␉// 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()␊ |
|
␊ |
␉␉␉␉␉// 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;␊ |
|
␉␉␉␉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(␊ |
|
␉␉␉␉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␊ |
|
␉␉␉␉RenderTargetCount > 0␊ |
␉␉␉);␊ |
␊ |
#if WIIU_GAMEPAD␊ |
␉␉␉wiiuPixelData = new byte[␊ |
␉␉␉␉PresentationParameters.BackBufferWidth *␊ |
␉␉␉␉PresentationParameters.BackBufferHeight *␊ |
␉␉␉␉4␊ |
␉␉␉];␊ |
#endif␊ |
␊ |
␉␉␉// Now, update the viewport␊ |
␉␉␉Viewport = new Viewport(␊ |
␉␉␉␉0,␊ |
|
␉␉}␊ |
␊ |
␉␉#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␊ |
␉}␊ |
}␊ |