Esempio n. 1
0
        void CreateEyeTextures()
        {
            for (int eye_idx = 0; eye_idx < 2; eye_idx++)
            {
                OculusWrap.OVR.EyeType eye     = (OculusWrap.OVR.EyeType)eye_idx;
                EyeTexture             eye_tex = new EyeTexture();
                eye_texes[eye_idx] = eye_tex;

                // Retrieve size and position of the texture for the current eye.
                eye_tex.FieldOfView           = hmd.DefaultEyeFov[eye_idx];
                eye_tex.TextureSize           = hmd.GetFovTextureSize(eye, hmd.DefaultEyeFov[eye_idx], 1.0f);
                eye_tex.RenderDescription     = hmd.GetRenderDesc(eye, hmd.DefaultEyeFov[eye_idx]);
                eye_tex.HmdToEyeViewOffset    = eye_tex.RenderDescription.HmdToEyeViewOffset;
                eye_tex.ViewportSize.Position = new OculusWrap.OVR.Vector2i(0, 0);
                eye_tex.ViewportSize.Size     = eye_tex.TextureSize;
                eye_tex.Viewport = new Viewport(0, 0, eye_tex.TextureSize.Width, eye_tex.TextureSize.Height, 0.0f, 1.0f);

                // Define a texture at the size recommended for the eye texture.
                eye_tex.Texture2DDescription = DefineEyeTextureDescription(eye_tex);

                // Convert the SharpDX texture description to the native Direct3D texture description.
                OculusWrap.OVR.D3D11.D3D11_TEXTURE2D_DESC swapTextureDescriptionD3D11 = SharpDXHelpers.CreateTexture2DDescription(eye_tex.Texture2DDescription);

                // Create a SwapTextureSet, which will contain the textures to render to, for the current eye.
                var result = hmd.CreateSwapTextureSetD3D11(device.NativePointer, ref swapTextureDescriptionD3D11, out eye_tex.SwapTextureSet);
                WriteErrorDetails(oculus, result, "Failed to create swap texture set.");

                // Create room for each DirectX texture in the SwapTextureSet.
                eye_tex.Textures          = new Texture2D[eye_tex.SwapTextureSet.TextureCount];
                eye_tex.RenderTargetViews = new RenderTargetView[eye_tex.SwapTextureSet.TextureCount];

                // Create a texture 2D and a render target view, for each unmanaged texture contained in the SwapTextureSet.
                for (int tex_idx = 0; tex_idx < eye_tex.SwapTextureSet.TextureCount; tex_idx++)
                {
                    // Retrieve the current textureData object.
                    OculusWrap.OVR.D3D11.D3D11TextureData textureData = eye_tex.SwapTextureSet.Textures[tex_idx];

                    // Create a managed Texture2D, based on the unmanaged texture pointer.
                    eye_tex.Textures[tex_idx] = new Texture2D(textureData.Texture);

                    // Create a render target view for the current Texture2D.
                    eye_tex.RenderTargetViews[tex_idx] = new RenderTargetView(device, eye_tex.Textures[tex_idx]);
                }

                // Define the depth buffer, at the size recommended for the eye texture.
                eye_tex.DepthBufferDescription = DefineEyeDepthBufferDescription(eye_tex);

                // Create the depth buffer.
                eye_tex.DepthBuffer      = new Texture2D(device, eye_tex.DepthBufferDescription);
                eye_tex.DepthStencilView = new DepthStencilView(device, eye_tex.DepthBuffer);

                // Specify the texture to show on the HMD.
                layer_eye_fov.ColorTexture[eye_idx]      = eye_tex.SwapTextureSet.SwapTextureSetPtr;
                layer_eye_fov.Viewport[eye_idx].Position = new OculusWrap.OVR.Vector2i(0, 0);
                layer_eye_fov.Viewport[eye_idx].Size     = eye_tex.TextureSize;
                layer_eye_fov.Fov[eye_idx] = eye_tex.FieldOfView;
                layer_eye_fov.Header.Flags = OculusWrap.OVR.LayerFlags.None;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a Direct3D texture description, based on the SharpDX texture description.
        /// </summary>
        /// <param name="texture2DDescription">SharpDX texture description.</param>
        /// <returns>Direct3D texture description, based on the SharpDX texture description.</returns>
        public static OculusWrap.OVR.D3D11.D3D11_TEXTURE2D_DESC CreateTexture2DDescription(Texture2DDescription texture2DDescription)
        {
            OculusWrap.OVR.D3D11.D3D11_TEXTURE2D_DESC d3d11DTexture = new OculusWrap.OVR.D3D11.D3D11_TEXTURE2D_DESC();
            d3d11DTexture.Width              = (uint)texture2DDescription.Width;
            d3d11DTexture.Height             = (uint)texture2DDescription.Height;
            d3d11DTexture.MipLevels          = (uint)texture2DDescription.MipLevels;
            d3d11DTexture.ArraySize          = (uint)texture2DDescription.ArraySize;
            d3d11DTexture.Format             = (OculusWrap.OVR.D3D11.DXGI_FORMAT)texture2DDescription.Format;
            d3d11DTexture.SampleDesc.Count   = (uint)texture2DDescription.SampleDescription.Count;
            d3d11DTexture.SampleDesc.Quality = (uint)texture2DDescription.SampleDescription.Quality;
            d3d11DTexture.Usage              = (OculusWrap.OVR.D3D11.D3D11_USAGE)texture2DDescription.Usage;
            d3d11DTexture.BindFlags          = (uint)texture2DDescription.BindFlags;
            d3d11DTexture.CPUAccessFlags     = (uint)texture2DDescription.CpuAccessFlags;
            d3d11DTexture.MiscFlags          = (uint)texture2DDescription.OptionFlags;

            return(d3d11DTexture);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a Direct3D texture description, based on the SharpDX texture description.
        /// </summary>
        /// <param name="texture2DDescription">SharpDX texture description.</param>
        /// <returns>Direct3D texture description, based on the SharpDX texture description.</returns>
        public static OculusWrap.OVR.D3D11.D3D11_TEXTURE2D_DESC CreateTexture2DDescription(Texture2DDescription texture2DDescription)
        {
            OculusWrap.OVR.D3D11.D3D11_TEXTURE2D_DESC d3d11DTexture = new OculusWrap.OVR.D3D11.D3D11_TEXTURE2D_DESC();
            d3d11DTexture.Width = (uint)texture2DDescription.Width;
            d3d11DTexture.Height = (uint)texture2DDescription.Height;
            d3d11DTexture.MipLevels = (uint)texture2DDescription.MipLevels;
            d3d11DTexture.ArraySize = (uint)texture2DDescription.ArraySize;
            d3d11DTexture.Format = (OculusWrap.OVR.D3D11.DXGI_FORMAT)texture2DDescription.Format;
            d3d11DTexture.SampleDesc.Count = (uint)texture2DDescription.SampleDescription.Count;
            d3d11DTexture.SampleDesc.Quality = (uint)texture2DDescription.SampleDescription.Quality;
            d3d11DTexture.Usage = (OculusWrap.OVR.D3D11.D3D11_USAGE)texture2DDescription.Usage;
            d3d11DTexture.BindFlags = (uint)texture2DDescription.BindFlags;
            d3d11DTexture.CPUAccessFlags = (uint)texture2DDescription.CpuAccessFlags;
            d3d11DTexture.MiscFlags = (uint)texture2DDescription.OptionFlags;

            return d3d11DTexture;
        }
Esempio n. 4
0
        void CreateMirrorTexture(Control control)
        {
            OculusWrap.OVR.ovrResult result;

            // Define the texture used to display the rendered result on the computer monitor.
            Texture2DDescription mirrorTextureDescription = DefineMirrorTextureDescription(control);

            // Convert the SharpDX texture description to the native Direct3D texture description.
            OculusWrap.OVR.D3D11.D3D11_TEXTURE2D_DESC mirrorTextureDescriptionD3D11 = SharpDXHelpers.CreateTexture2DDescription(mirrorTextureDescription);

            OculusWrap.D3D11.MirrorTexture mirrorTexture;

            // Create the texture used to display the rendered result on the computer monitor.
            result = hmd.CreateMirrorTextureD3D11(device.NativePointer, ref mirrorTextureDescriptionD3D11, out mirrorTexture);
            WriteErrorDetails(oculus, result, "Failed to create mirror texture.");

            mtex = new Texture2D(mirrorTexture.Texture.Texture);
        }