Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="parameters"></param>
        public GenericDisplay(Game game, GraphicsDevice device, GameParameters parameters) : base(game, device, parameters)
        {
            window = CreateTouchForm(parameters, null);

            try {
                NvApi.Initialize();
                NvApi.Stereo_Disable();
            }
            catch (NVException nvex) {
                Log.Debug(nvex.Message);
            }

            //var deviceFlags			=	DeviceCreationFlags.SingleThreaded;
            var deviceFlags = DeviceCreationFlags.None;

            deviceFlags |= parameters.UseDebugDevice ? DeviceCreationFlags.Debug : DeviceCreationFlags.None;
            deviceFlags |= parameters.SupportVideo ? DeviceCreationFlags.BgraSupport | (DeviceCreationFlags)2048 : DeviceCreationFlags.None;

            var driverType = DriverType.Hardware;

            var featureLevel = HardwareProfileChecker.GetFeatureLevel(parameters.GraphicsProfile);


            swapChainDesc = new SwapChainDescription()
            {
                BufferCount       = 2,
                ModeDescription   = new ModeDescription(parameters.Width, parameters.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed        = true,
                OutputHandle      = window.Handle,
                SampleDescription = new SampleDescription(parameters.MsaaLevel, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput,
                Flags             = SwapChainFlags.None,
            };


            D3D.Device.CreateWithSwapChain(driverType, deviceFlags, new[] { featureLevel }, swapChainDesc, out d3dDevice, out swapChain);

            //Log.Message("   compute shaders : {0}", d3dDevice.CheckFeatureSupport(Feature.ComputeShaders) );
            //Log.Message("   shader doubles  : {0}", d3dDevice.CheckFeatureSupport(Feature.ShaderDoubles) );
            //Log.Message("   threading       : {0}", d3dDevice.CheckFeatureSupport(Feature.Threading) );
            bool driverConcurrentCreates;
            bool driverCommandLists;

            d3dDevice.CheckThreadingSupport(out driverConcurrentCreates, out driverCommandLists);
            d3dDevice.GetCounterCapabilities();
            Log.Message("   Concurrent Creates : {0}", driverConcurrentCreates);
            Log.Message("   Command Lists      : {0}", driverCommandLists);


            var factory = swapChain.GetParent <Factory>();

            factory.MakeWindowAssociation(window.Handle, WindowAssociationFlags.IgnoreAll);


            clientWidth  = window.ClientSize.Width;
            clientHeight = window.ClientSize.Height;
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="game"></param>
        /// <param name="device"></param>
        /// <param name="parameters"></param>
        public OculusRiftDisplay(Game game, GraphicsDevice device, GraphicsParameters parameters) : base(game, device, parameters)
        {
            oculus = new Wrap();

            // Initialize the Oculus runtime.
            oculus.Initialize();

            OVR.GraphicsLuid graphicsLuid;
            hmd = oculus.Hmd_Create(out graphicsLuid);

            if (hmd == null)
            {
                MessageBox.Show("Oculus Rift not detected.", "Uh oh", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (hmd.ProductName == string.Empty)
            {
                MessageBox.Show("The HMD is not enabled.", "There's a tear in the Rift", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }


            parameters.Width  = hmd.Resolution.Width;
            parameters.Height = hmd.Resolution.Height;

            window = CreateForm(parameters, null, false);

            var deviceFlags = DeviceCreationFlags.None;

            deviceFlags |= parameters.UseDebugDevice ? DeviceCreationFlags.Debug : DeviceCreationFlags.None;

            var driverType = DriverType.Hardware;

            var featureLevel = HardwareProfileChecker.GetFeatureLevel(parameters.GraphicsProfile);


            var swapChainDesc = new SwapChainDescription {
                BufferCount       = 1,
                ModeDescription   = new ModeDescription(hmd.Resolution.Width, hmd.Resolution.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed        = true,
                OutputHandle      = window.Handle,
                SampleDescription = new SampleDescription(parameters.MsaaLevel, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput | Usage.ShaderInput,
                Flags             = SwapChainFlags.None,
            };


            D3D.Device.CreateWithSwapChain(driverType, deviceFlags, new[] { featureLevel }, swapChainDesc, out d3dDevice, out swapChain);


            var myFactory = swapChain.GetParent <Factory>();

            myFactory.MakeWindowAssociation(window.Handle, WindowAssociationFlags.IgnoreAll);
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="parameters"></param>
        public StereoInterlacedDisplay(Game game, GraphicsDevice device, GraphicsParameters parameters) : base(game, device, parameters)
        {
            try {
                NvApi.Initialize();
                NvApi.Stereo_Disable();
            }
            catch (NVException nvex) {
                Log.Debug(nvex.Message);
            }


            window = CreateForm(parameters, null, false);

            var deviceFlags = DeviceCreationFlags.None;

            deviceFlags |= parameters.UseDebugDevice ? DeviceCreationFlags.Debug : DeviceCreationFlags.None;

            var driverType = DriverType.Hardware;

            var featureLevel = HardwareProfileChecker.GetFeatureLevel(parameters.GraphicsProfile);


            swapChainDesc = new SwapChainDescription()
            {
                BufferCount       = 1,
                ModeDescription   = new ModeDescription(parameters.Width, parameters.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed        = true,
                OutputHandle      = window.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput,
                Flags             = SwapChainFlags.None,
            };


            D3D.Device.CreateWithSwapChain(driverType, deviceFlags, new[] { featureLevel }, swapChainDesc, out d3dDevice, out swapChain);


            var factory = swapChain.GetParent <Factory>();

            factory.MakeWindowAssociation(window.Handle, WindowAssociationFlags.IgnoreAll);


            clientWidth  = window.ClientSize.Width;
            clientHeight = window.ClientSize.Height;
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="parameters"></param>
        public NV3DVisionDisplay(Game game, GraphicsDevice device, GraphicsParameters parameters) : base(game, device, parameters)
        {
            Log.Message("Using NVidia 3D Vision");

            //
            //	Init NV API and enable stereo :
            //
            NvApi.Initialize();
            NvApi.Stereo_Enable();
            NvApi.Stereo_SetDriverMode(NvStereoDriverMode.Direct);


            //
            //	Create main window
            //
            window = CreateForm(parameters, null, false);


            var deviceFlags = DeviceCreationFlags.None;

            deviceFlags |= parameters.UseDebugDevice ? DeviceCreationFlags.Debug : DeviceCreationFlags.None;

            var driverType = DriverType.Hardware;

            var featureLevel = HardwareProfileChecker.GetFeatureLevel(parameters.GraphicsProfile);


            swapChainDesc = new SwapChainDescription()
            {
                BufferCount       = 1,
                ModeDescription   = new ModeDescription(parameters.Width, parameters.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed        = true,
                OutputHandle      = window.Handle,
                SampleDescription = new SampleDescription(parameters.MsaaLevel, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput,
                Flags             = SwapChainFlags.None,
            };


            //
            //	Create device :
            //
            D3D.Device.CreateWithSwapChain(driverType, deviceFlags, new[] { featureLevel }, swapChainDesc, out d3dDevice, out swapChain);


            var factory = swapChain.GetParent <Factory>();

            factory.MakeWindowAssociation(window.Handle, WindowAssociationFlags.IgnoreAll);


            clientWidth  = window.ClientSize.Width;
            clientHeight = window.ClientSize.Height;


            //
            //	Setup 3DVision :
            //

            try {
                stereoHandle = NvApi.Stereo_CreateHandleFromIUnknown(d3dDevice.NativePointer);

                NvApi.Stereo_Activate(stereoHandle);
                NvApi.Stereo_SetActiveEye(stereoHandle, NvStereoActiveEye.Mono);
            } catch (NVException) {
                SafeDispose(ref d3dDevice);
                SafeDispose(ref swapChain);
                throw;
            }
        }
Esempio n. 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="parameters"></param>
        public OculusRiftDisplay(Game game, GraphicsDevice device, GameParameters parameters) : base(game, device, parameters)
        {
            window = CreateForm(parameters, null);

            oculus = new Wrap();

            // Initialize the Oculus runtime.
            oculus.Initialize();

            // Use the head mounted display, if it's available, otherwise use the debug HMD.
            int numberOfHeadMountedDisplays = oculus.Hmd_Detect();

            if (numberOfHeadMountedDisplays > 0)
            {
                hmd = oculus.Hmd_Create(0);
            }
            else
            {
                hmd = oculus.Hmd_CreateDebug(OculusWrap.OVR.HmdType.DK2);
            }

            if (hmd == null)
            {
                MessageBox.Show("Oculus Rift not detected.", "Uh oh", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (hmd.ProductName == string.Empty)
            {
                MessageBox.Show("The HMD is not enabled.", "There's a tear in the Rift", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }


            OVR.Recti destMirrorRect;
            OVR.Recti sourceRenderTargetRect;
            hmd.AttachToWindow(window.Handle, out destMirrorRect, out sourceRenderTargetRect);

            // Create a backbuffer that's the same size as the HMD's resolution.
            OVR.Sizei backBufferSize;
            backBufferSize.Width  = hmd.Resolution.Width;
            backBufferSize.Height = hmd.Resolution.Height;

            Input.OculusRiftSensors.RecenterPosition = hmd.RecenterPose;

            var deviceFlags = DeviceCreationFlags.None;

            deviceFlags |= parameters.UseDebugDevice ? DeviceCreationFlags.Debug : DeviceCreationFlags.None;

            var driverType = DriverType.Hardware;

            var featureLevel = HardwareProfileChecker.GetFeatureLevel(parameters.GraphicsProfile);


            swapChainDesc = new SwapChainDescription {
                BufferCount       = 1,
                ModeDescription   = new ModeDescription(backBufferSize.Width, backBufferSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed        = true,
                OutputHandle      = window.Handle,
                SampleDescription = new SampleDescription(parameters.MsaaLevel, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput | Usage.ShaderInput,
                Flags             = SwapChainFlags.None,
            };


            D3D.Device.CreateWithSwapChain(driverType, deviceFlags, new[] { featureLevel }, swapChainDesc, out d3dDevice, out swapChain);


            var factory = swapChain.GetParent <Factory>();

            factory.MakeWindowAssociation(window.Handle, WindowAssociationFlags.IgnoreAll);


            clientWidth  = window.ClientSize.Width;
            clientHeight = window.ClientSize.Height;
        }
Esempio n. 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="parameters"></param>
        public StereoDualHeadDisplay(Game game, GraphicsDevice device, GameParameters parameters) : base(game, device, parameters)
        {
            try {
                NvApi.Initialize();
                NvApi.Stereo_Disable();
            }
            catch (NVException nvex) {
                Log.Debug(nvex.Message);
            }

            var featureLevel = HardwareProfileChecker.GetFeatureLevel(parameters.GraphicsProfile);

            Adapter adapter;
            Output  leftOut, rightOut;

            GetDualHeadAdapter(featureLevel, out adapter, out leftOut, out rightOut);



            window1     = CreateForm(parameters, leftOut);
            window2     = CreateForm(parameters, rightOut);
            window1.Tag = leftOut.Description;
            window2.Tag = rightOut.Description;

            window1.AddOwnedForm(window2);

            window2.Show();
            window1.Show();

            window1.Resize    += window_Resize;
            window2.Resize    += window_Resize;
            window1.Move      += window_Move;
            window2.Move      += window_Move;
            window1.Activated += window_Activated;
            window2.Activated += window_Activated;
            targetForm         = window1;



            var deviceFlags = DeviceCreationFlags.None;

            deviceFlags |= parameters.UseDebugDevice ? DeviceCreationFlags.Debug : DeviceCreationFlags.None;


            swapChainDesc1 = new SwapChainDescription()
            {
                BufferCount       = 1,
                ModeDescription   = new ModeDescription(parameters.Width, parameters.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed        = true,
                OutputHandle      = window1.Handle,
                SampleDescription = new SampleDescription(parameters.MsaaLevel, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput,
                Flags             = SwapChainFlags.None,
            };

            swapChainDesc2 = new SwapChainDescription()
            {
                BufferCount       = 1,
                ModeDescription   = new ModeDescription(parameters.Width, parameters.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed        = true,
                OutputHandle      = window2.Handle,
                SampleDescription = new SampleDescription(parameters.MsaaLevel, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput,
                Flags             = SwapChainFlags.None,
            };


            d3dDevice = new D3D.Device(adapter, deviceFlags, featureLevel);


            using (var factory = adapter.GetParent <Factory>()) {
                swapChain1 = new SwapChain(factory, d3dDevice, swapChainDesc1);
                swapChain2 = new SwapChain(factory, d3dDevice, swapChainDesc2);

                //factory.MakeWindowAssociation( new IntPtr(0), WindowAssociationFlags.None );
                factory.MakeWindowAssociation(window1.Handle, WindowAssociationFlags.IgnoreAll | WindowAssociationFlags.IgnoreAltEnter);
                factory.MakeWindowAssociation(window2.Handle, WindowAssociationFlags.IgnoreAll | WindowAssociationFlags.IgnoreAltEnter);
            }


            clientWidth  = window1.ClientSize.Width;
            clientHeight = window1.ClientSize.Height;
        }
Esempio n. 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="parameters"></param>
        public GenericDisplay(Game game, GraphicsDevice device, GraphicsParameters parameters) : base(game, device, parameters)
        {
            try {
                window = CreateForm(parameters, null, true);
            }
            catch (System.EntryPointNotFoundException) {
                Log.Warning("Looks like your system does't support touch gestures. You need Windows 8.1 or newer for this.");
                window = CreateForm(parameters, null, false);
            }

            try {
                NvApi.Initialize();
                NvApi.Stereo_Disable();
            }
            catch (NVException nvex) {
                Log.Debug(nvex.Message);
            }

            var deviceFlags = DeviceCreationFlags.BgraSupport;

            //deviceFlags			|=	DeviceCreationFlags.SingleThreaded;
            deviceFlags |= parameters.UseDebugDevice ? DeviceCreationFlags.Debug : DeviceCreationFlags.None;

            var driverType = DriverType.Hardware;

            var featureLevel = HardwareProfileChecker.GetFeatureLevel(parameters.GraphicsProfile);


            swapChainDesc = new SwapChainDescription()
            {
                BufferCount       = 1,                                          // UE4 use this.
                ModeDescription   = new ModeDescription(parameters.Width, parameters.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed        = true,
                OutputHandle      = window.Handle,
                SampleDescription = new SampleDescription(parameters.MsaaLevel, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput,
                Flags             = SwapChainFlags.None,
            };

            D3D.Device.CreateWithSwapChain(driverType, deviceFlags, new[] { featureLevel }, swapChainDesc, out d3dDevice, out swapChain);

            //Log.Message("   compute shaders : {0}", d3dDevice.CheckFeatureSupport(Feature.ComputeShaders) );
            //Log.Message("   shader doubles  : {0}", d3dDevice.CheckFeatureSupport(Feature.ShaderDoubles) );
            //Log.Message("   threading       : {0}", d3dDevice.CheckFeatureSupport(Feature.Threading) );
            bool driverConcurrentCreates;
            bool driverCommandLists;

            d3dDevice.CheckThreadingSupport(out driverConcurrentCreates, out driverCommandLists);
            //d3dDevice.GetCounterCapabilities();
            Log.Message("   Concurrent Creates : {0}", driverConcurrentCreates);
            Log.Message("   Command Lists      : {0}", driverCommandLists);


            var factory = swapChain.GetParent <Factory>();

            factory.MakeWindowAssociation(window.Handle, WindowAssociationFlags.IgnoreAll);


            clientWidth  = window.ClientSize.Width;
            clientHeight = window.ClientSize.Height;

            fullscr = parameters.FullScreen;
        }