示例#1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            device   = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware, SharpDX.Direct3D11.DeviceCreationFlags.None, SharpDX.Direct3D.FeatureLevel.Level_11_0);
            c_device = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware, SharpDX.Direct3D11.DeviceCreationFlags.None, SharpDX.Direct3D.FeatureLevel.Level_11_1);
            factory  = new SharpDX.DXGI.Factory1();

            int width  = factory.Adapters1[numAdapter].Outputs[numOutput].Description.DesktopBounds.Width;
            int height = factory.Adapters1[numAdapter].Outputs[numOutput].Description.DesktopBounds.Height;

            target = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            // creating CPU-accessible texture resource
            SharpDX.Direct3D11.Texture2DDescription texdes = new SharpDX.Direct3D11.Texture2DDescription();
            texdes.CpuAccessFlags            = SharpDX.Direct3D11.CpuAccessFlags.Read;
            texdes.BindFlags                 = SharpDX.Direct3D11.BindFlags.None;
            texdes.Format                    = SharpDX.DXGI.Format.B8G8R8A8_UNorm;
            texdes.Height                    = height;
            texdes.Width                     = width;
            texdes.OptionFlags               = SharpDX.Direct3D11.ResourceOptionFlags.Shared;
            texdes.MipLevels                 = 1;
            texdes.ArraySize                 = 1;
            texdes.SampleDescription.Count   = 1;
            texdes.SampleDescription.Quality = 0;
            texdes.Usage                     = SharpDX.Direct3D11.ResourceUsage.Staging;

            screenTexture        = new SharpDX.Direct3D11.Texture2D(c_device, texdes);
            sharedResourceHandle = screenTexture.QueryInterface <SharpDX.DXGI.Resource>().SharedHandle;
            sharedTexture        = device.OpenSharedResource <SharpDX.Direct3D11.Texture2D>(sharedResourceHandle);


            output           = new SharpDX.DXGI.Output1(factory.Adapters1[numAdapter].Outputs[numOutput].NativePointer);
            duplicatedOutput = output.DuplicateOutput(c_device);
        }
示例#2
0
        public VRRenderer(SharpDX.Direct3D11.Device d3d11Device, SharpDX.Direct3D11.Device unityDevice, VRRig rig)
        {
            instance = this;


            this.rig      = rig;
            device        = d3d11Device;
            unityRenderer = unityDevice;

            bounds      = new VRTextureBounds_t();
            bounds.vMin = bounds.uMin = 0;
            bounds.vMax = bounds.uMax = 1;

            var w           = rig.leftTexture.Description.Width;
            var h           = rig.leftTexture.Description.Height;
            var description = new SharpDX.Direct3D11.Texture2DDescription()
            {
                Width  = (int)w,
                Height = (int)h,

                MipLevels = 1,
                ArraySize = 1,

                SampleDescription = new SampleDescription()
                {
                    Count = 1
                },

                BindFlags      = SharpDX.Direct3D11.BindFlags.ShaderResource | SharpDX.Direct3D11.BindFlags.RenderTarget,
                CpuAccessFlags = SharpDX.Direct3D11.CpuAccessFlags.None,
                Format         = Format.R8G8B8A8_UNorm,
                OptionFlags    = SharpDX.Direct3D11.ResourceOptionFlags.Shared,
                Usage          = SharpDX.Direct3D11.ResourceUsage.Default
            };

            System.Diagnostics.Trace.WriteLine("Creating D3D11 Textures");

            leftVRTexture  = new SharpDX.Direct3D11.Texture2D(d3d11Device, description);
            rightVRTexture = new SharpDX.Direct3D11.Texture2D(d3d11Device, description);

            leftEye = new Texture_t()
            {
                eColorSpace = EColorSpace.Gamma,
                eType       = ETextureType.DirectX,
                handle      = leftVRTexture.NativePointer
            };
            rightEye = new Texture_t()
            {
                eColorSpace = EColorSpace.Gamma,
                eType       = ETextureType.DirectX,
                handle      = rightVRTexture.NativePointer
            };


            var sharedHandleLeft  = leftVRTexture.QueryInterface <Resource>().SharedHandle;
            var sharedHandleRight = rightVRTexture.QueryInterface <Resource>().SharedHandle;

            leftHandle  = unityRenderer.OpenSharedResource <SharpDX.Direct3D11.Texture2D>(sharedHandleLeft);
            rightHandle = unityRenderer.OpenSharedResource <SharpDX.Direct3D11.Texture2D>(sharedHandleRight);

            var viewDesc = new SharpDX.Direct3D11.ShaderResourceViewDescription()
            {
                Format    = Format.R8G8B8A8_UNorm,
                Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D,
                Texture2D = new SharpDX.Direct3D11.ShaderResourceViewDescription.Texture2DResource()
                {
                    MipLevels       = 1,
                    MostDetailedMip = 0
                }
            };
            var leftView  = new SharpDX.Direct3D11.ShaderResourceView(unityDevice, leftHandle, viewDesc);
            var rightView = new SharpDX.Direct3D11.ShaderResourceView(unityDevice, rightHandle, viewDesc);

            leftUnityTexture  = Texture2D.CreateExternalTexture(w, h, TextureFormat.ARGB32, false, false, leftView.NativePointer);
            rightUnityTexture = Texture2D.CreateExternalTexture(w, h, TextureFormat.ARGB32, false, false, rightView.NativePointer);
        }