Exemple #1
0
        public ConfigForm(HmdDevice hmd)
        {
            m_hasResult = false;
            m_result    = new Result()
            {
                UseHmd = false
            };
            m_hmd = hmd;

            InitializeComponent();

            string labelFormat = "Detected device : {0}";

            if (m_hmd == null)
            {
                // disable use hmd option
                m_monoralMode.Checked      = true;
                m_stereoMode.Checked       = false;
                m_stereoMode.Enabled       = false;
                m_detectedHmdLabel.Text    = string.Format(labelFormat, "NONE");
                m_detectedHmdLabel.Enabled = false;
            }
            else
            {
                m_monoralMode.Checked   = false;
                m_stereoMode.Checked    = true;
                m_detectedHmdLabel.Text = string.Format(labelFormat, hmd.DisplayName);
            }
        }
        public DrawPassCtrl(DrawSystem.D3DData d3d, DrawResourceRepository repository, HmdDevice hmd, bool bStereoRendering, int multiThreadCount)
        {
            m_d3d              = d3d;
            m_repository       = repository;
            m_bStereoRendering = bStereoRendering;
            m_hmd              = hmd;
            m_factory          = new DrawContext.Factory(d3d, repository);

            if (bStereoRendering)
            {
                m_stereoContext = new StereoDrawContext(d3d, repository, hmd, m_factory.CreateDeferredDrawContext());
            }
            else
            {
                m_monoralContext = new MonoralDrawContext(d3d, repository, m_factory.CreateImmediateDrawContext());
            }

            // Init settings
            m_d3d.Device.QueryInterface <Device1>().MaximumFrameLatency = 1;

            m_subThreadCtxList = new List <_SubThreadContextData>();
            for (int index = 0; index < multiThreadCount; ++index)
            {
                var drawContext = m_factory.CreateDeferredDrawContext();
                m_subThreadCtxList.Add(new _SubThreadContextData()
                {
                    DrawContext = drawContext
                });
            }
        }
        private DrawSystem(IntPtr hWnd, Device device, SwapChain swapChain, HmdDevice hmd, bool bStereoRendering, int multiThreadCount)
        {
            m_d3d = new D3DData
            {
                Device       = device,
                SwapChain    = swapChain,
                WindowHandle = hWnd,
            };

            m_debug      = new DrawDebugCtrl();
            m_repository = new DrawResourceRepository(m_d3d);
            m_passCtrl   = new DrawPassCtrl(m_d3d, m_repository, hmd, bStereoRendering, multiThreadCount);

            m_bStereoRendering = bStereoRendering;
            m_hmd = hmd;
            if (m_hmd != null)
            {
                m_hmd.Setup(m_d3d, m_repository.GetDefaultRenderTarget());
            }

            m_drawBuffer = new DrawBuffer();
        }
Exemple #4
0
        /// <summary>
        /// get the first detected hmd device
        /// </summary>
        /// <returns>
        /// detected hmd
        /// </returns>
        public HmdDevice DetectHmd()
        {
            IntPtr hmdPtr;

            if (LibOVR.ovrHmd_Create(0, out hmdPtr) != 0)
            {
                MessageBox.Show("Oculus Rift not detected.");
                return(null);
            }

            var hmd = CRef <LibOVR.ovrHmdDesc> .FromPtr(hmdPtr);

            if (hmd == null)
            {
                return(null);
            }
            else
            {
                m_hmdDevice = new HmdDevice(hmd);
                return(m_hmdDevice);
            }
        }
        public StereoDrawContext(DrawSystem.D3DData d3d, DrawResourceRepository repository, HmdDevice hmd, DrawContext context)
        {
            m_d3d        = d3d;
            m_repository = repository;
            m_context    = context;
            m_hmd        = hmd;

            // Create render targets for each HMD eye
            m_textureSets = new HmdSwapTextureSet[2];
            var eyeResolution = hmd.EyeResolution;
            var resNames      = new string[] { "OVRLeftEye", "OVRRightEye" };

            for (int index = 0; index < 2; ++index)
            {
                var textureSet = m_hmd.CreateSwapTextureSet(d3d.Device, eyeResolution.Width, eyeResolution.Height);
                m_textureSets[index] = textureSet;

                var renderTargetList = RenderTarget.FromSwapTextureSet(m_d3d, resNames[index], textureSet);
                foreach (var renderTarget in renderTargetList)
                {
                    m_repository.AddResource(renderTarget);
                }
            }

            // Create temporaly render target
            var tmpRt = RenderTarget.CreateRenderTarget(d3d, "Temp", eyeResolution.Width, eyeResolution.Height);

            m_repository.AddResource(tmpRt);

            // Create texture for Mirroring
            Size defaultRenderTargetSize = m_repository.GetDefaultRenderTarget().Resolution;

            m_mirrorTexture = m_hmd.CreateMirrorTexture(m_d3d.Device, defaultRenderTargetSize.Width, defaultRenderTargetSize.Height);

            m_commandListTable = new List <CommandList>();
        }
Exemple #6
0
        static void Main()
        {
            bool bStereoRendering = false; // change to 'false' due to non-stereo rendering for debug
            int  multiThreadCount = 4;     // 1 is single thread

            HmdDevice hmd = null;

            try
            {
                // init oculus rift hmd system
                HmdSystem.Initialize();
                var hmdSys = HmdSystem.GetInstance();
                hmd = hmdSys.DetectHmd();
            }
            catch (Exception)
            {
                // failed to detect hmd
                hmd = null;
            }

#if !DEBUG
            var configForm = new ConfigForm(hmd);
            Application.Run(configForm);
            if (configForm.HasResult())
            {
                bStereoRendering = configForm.GetResult().UseHmd;
            }
            else
            {
                // cancel
                return;
            }
#endif
            Size resolution = new Size();
            if (!bStereoRendering)
            {
                //resolution.Width = 1920;// Full HD
                //resolution.Height = 1080;
                resolution.Width  = 1280;
                resolution.Height = 720;
            }
            else
            {
                hmd.ResetPose();
                resolution = hmd.Resolution;
            }

            var form = new MainForm();
            form.ClientSize = resolution;

            // Create Device & SwapChain
            var desc = new SwapChainDescription()
            {
                BufferCount     = 2,
                ModeDescription =
                    new ModeDescription(resolution.Width, resolution.Height, new Rational(0, 1), DrawSystem.GetRenderTargetFormat()),
                IsWindowed        = true,
                OutputHandle      = form.GetRenderTarget().Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Sequential,
                Usage             = Usage.RenderTargetOutput,
                Flags             = SwapChainFlags.AllowModeSwitch,
            };

            FeatureLevel[] levels =
            {
                FeatureLevel.Level_11_0
            };

            Device    device;
            SwapChain swapChain;
#if DEBUG
            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.Debug, levels, desc, out device, out swapChain);
#else
            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, levels, desc, out device, out swapChain);
#endif

            // Ignore all windows events
            var factory = swapChain.GetParent <Factory>();
            factory.MakeWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll);

            DrawSystem.Initialize(form.GetRenderTarget().Handle, device, swapChain, hmd, bStereoRendering, multiThreadCount);
            InputSystem.Initialize(form.GetRenderTarget());
            EntitySystem.Initialize();
            MapSystem.Initialize();
            ChrSystem.Initialize();
            CameraSystem.Initialize();
            CullingSystem.Initialize();
            GameSystem.Initialize();

            GameSystem.GetInstance().Config.IsUseHmd = bStereoRendering;
            var scene = new Scene(device, swapChain, form.GetRenderTarget(), hmd, bStereoRendering, multiThreadCount);
            RenderLoop.Run(form, () => { scene.RenderFrame(); });
            scene.Dispose();

            // Release
            GameSystem.Dispose();
            CullingSystem.Dispose();
            CameraSystem.Dispose();
            ChrSystem.Dispose();
            MapSystem.Dispose();
            EntitySystem.Dispose();
            InputSystem.Dispose();
            DrawSystem.Dispose();
            device.Dispose();
            swapChain.Dispose();
            HmdSystem.Dispose();
        }
 static public void Initialize(IntPtr hWnd, Device device, SwapChain swapChain, HmdDevice hmd, bool bStereoRendering, int multiThreadCount)
 {
     s_singleton = new DrawSystem(hWnd, device, swapChain, hmd, bStereoRendering, multiThreadCount);
 }
Exemple #8
0
        public Scene(Device device, SwapChain swapChain, Panel renderTarget, HmdDevice hmd, bool bStereoRendering, int multiThreadCount)
        {
            var drawSys = DrawSystem.GetInstance();
            var mapSys  = MapSystem.GetInstance();

            // load textures
            var textures = new List <TextureView>(new[]
            {
                TextureView.FromFile("dot", drawSys.D3D, "Image/dot.png"),
                TextureView.FromFile("floor", drawSys.D3D, "Image/floor.jpg"),
            });
            var numTextures = new DrawSystem.TextureData[10];

            for (int i = 0; i < 10; ++i)
            {
                var name = String.Format("number_{0}", i);
                numTextures[i] = new DrawSystem.TextureData
                {
                    Resource = TextureView.FromFile(name, drawSys.D3D, String.Format("Image/{0}.png", name)),
                    UvScale  = Vector2.One,
                };
            }
            textures.AddRange(numTextures.Select(item => item.Resource));
            foreach (var tex in textures)
            {
                drawSys.ResourceRepository.AddResource(tex);
            }

            // create number entity
            m_fps          = new FpsCounter();
            m_numberEntity = new NumberEntity(new NumberEntity.InitParam()
            {
                Dot = new DrawSystem.TextureData
                {
                    Resource = drawSys.ResourceRepository.FindResource <TextureView>("dot"),
                    UvScale  = Vector2.One,
                },
                Numbers = numTextures,
                Layout  = Matrix.RotationYawPitchRoll(1.0f, -1.5f, MathUtil.PI) * Matrix.Translation(-1.5f, 2.5f, -4.5f)
            });

            // create map
            mapSys.LoadResource();
            mapSys.CreateMap("Level/l9000.tmx");

            // create player
            m_player = new PlayerEntity();
            ChrSystem.GetInstance().Player = m_player;

            m_multiThreadCount = multiThreadCount;
            m_taskList         = new List <Task>(m_multiThreadCount);
            m_taskResultList   = new List <CommandList>(m_multiThreadCount);

            // other settings
#if DEBUG
            CameraSystem.GetInstance().ActivateCamera(CameraSystem.FollowEntityCameraName);
            //CameraSystem.GetInstance().ActivateCamera(CameraSystem.FixedCameraName);
            //CameraSystem.GetInstance().ActivateCamera(CameraSystem.FreeCameraName);
#else
            CameraSystem.GetInstance().ActivateCamera(CameraSystem.FollowEntityCameraName);
#endif // DEBUG
        }