public HmdSwapTextureSet(IntPtr hmdPtr, Device device, int width, int height)
        {
            var cDesc = new _D3D11_TEXTURE2D_DESC()
            {
                Width              = (uint)width,
                Height             = (uint)height,
                MipLevels          = (uint)1,
                ArraySize          = (uint)1,
                Format             = (uint)DrawSystem.GetRenderTargetFormat(),
                SampleDesc_Count   = (uint)1,
                SampleDesc_Quality = (uint)0,
                Usage              = (uint)ResourceUsage.Default,
                BindFlags          = (uint)(BindFlags.RenderTarget | BindFlags.ShaderResource),
                CPUAccessFlags     = (uint)CpuAccessFlags.None,
                MiscFlags          = (uint)ResourceOptionFlags.None,
            };

            unsafe
            {
                IntPtr textureSetPtr;
                int    result = LibOVR.ovrHmd_CreateSwapTextureSetD3D11(hmdPtr, device.NativePointer, (IntPtr)(&cDesc), out textureSetPtr);
                if (result != 0)
                {
                    MessageBox.Show("Failed to ovrHmd_CreateSwapTexturesetD3D11() code=" + result);
                    return;
                }

                var textureSet = CRef <LibOVR.ovrSwapTextureSet> .FromPtr(textureSetPtr);

                if (textureSet == null)
                {
                    return;
                }

                var textureList = new List <CRef <LibOVR.ovrTexture> >();
                for (int texIndex = 0; texIndex < textureSet.Value.TextureCount; ++texIndex)
                {
                    IntPtr texPtr = textureSet.Value.Textures + sizeof(LibOVR.ovrTexture) * texIndex;
                    var    tex    = CRef <LibOVR.ovrTexture> .FromPtr(texPtr);

                    textureList.Add(tex);
                }

                m_hmdPtr     = hmdPtr;
                m_textureSet = textureSet;
                m_textures   = textureList.ToArray();
            }

            var csize = m_textures[0].Value.Header.TextureSize;

            m_resolution = new Size(csize.w, csize.h);

            // make SharpDx resource
            m_textureResList = m_textures.Select(t => new Texture2D(t.Value.Texture)).ToList();

            // make and set texture views
            m_renderTargetViewList = m_textureResList.Select(t => new RenderTargetView(device, t)).ToList();
            _SetTextureView(0, m_renderTargetViewList[0]);
            _SetTextureView(1, m_renderTargetViewList[1]);
        }
Exemple #2
0
 public static CRef <string> FromCharPtr(IntPtr ptr)
 {
     if (ptr == IntPtr.Zero)
     {
         return(null);
     }
     else
     {
         var handle = new CRef <string>();
         handle.m_ptr = ptr;
         handle.Value = Marshal.PtrToStringAnsi(ptr);
         return(handle);
     }
 }
Exemple #3
0
 public static CRef <ValueType> FromPtr(IntPtr ptr)
 {
     if (ptr == IntPtr.Zero)
     {
         return(null);
     }
     else
     {
         var handle = new CRef <ValueType>();
         handle.m_ptr = ptr;
         handle.Value = (ValueType)Marshal.PtrToStructure(ptr, typeof(ValueType));
         return(handle);
     }
 }
Exemple #4
0
        private HmdSystem()
        {
            //var initParams = new LibOVR.ovrInitParams;
            //initParams.Flags = 0;

            if (LibOVR.ovr_Initialize(IntPtr.Zero) != 0)
            {
                MessageBox.Show("Failed to initialize LibOVR.");
                return;
            }

            string version = CRef <string> .FromCharPtr(LibOVR.ovr_GetVersionString()).Value;

            int detect = LibOVR.ovrHmd_Detect();

            Debug.Print("[HMD] sdk version = {0}", version);
            Debug.Print("[HMD] detected device count = {0}", detect);
        }
Exemple #5
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);
            }
        }
Exemple #6
0
 public HmdDevice(CRef <LibOVR.ovrHmdDesc> handle)
 {
     m_handle = handle;
 }