示例#1
0
        private void CreateTexture(int width, int height)
        {
            var description = new D3D10.Texture2DDescription();

            description.ArraySize                    = 1;
            description.BindingOptions               = D3D10.BindingOptions.RenderTarget | D3D10.BindingOptions.ShaderResource;
            description.CpuAccessOptions             = D3D10.CpuAccessOptions.None;
            description.Format                       = DirectX.Graphics.Format.B8G8R8A8UNorm;
            description.MipLevels                    = 1;
            description.MiscellaneousResourceOptions = D3D10.MiscellaneousResourceOptions.Shared;
            description.SampleDescription            = new DirectX.Graphics.SampleDescription(1, 0);
            description.Usage = D3D10.Usage.Default;

            description.Height = (uint)height;
            description.Width  = (uint)width;

            // Assign result to temporary variable in case CreateTexture2D throws
            var texture = this.device.CreateTexture2D(description);

            if (this.texture != null)
            {
                this.texture.Dispose();
            }
            this.texture = texture;
        }
示例#2
0
        /// <summary>
        /// Releases the DirectX device and any device dependent resources.
        /// </summary>
        /// <remarks>
        /// This method is safe to be called even if the instance has been disposed.
        /// </remarks>
        public void FreeResources()
        {
            this.OnFreeResources();

            if (this.texture != null)
            {
                this.texture.Dispose();
                this.texture = null;
            }
            if (this.renderTarget != null)
            {
                this.renderTarget.Dispose();
                this.renderTarget = null;
            }
            if (this.device != null)
            {
                this.device.Dispose();
                this.device = null;
            }
        }
示例#3
0
        private static Direct3DTexture9 GetSharedSurface(Direct3DDevice9Ex device, Microsoft.WindowsAPICodePack.DirectX.Direct3D10.Texture2D texture)
        {
            // First get a shared handle to the D3D10 texture
            using (var surface = texture.QueryInterface <Microsoft.WindowsAPICodePack.DirectX.Graphics.Resource>())
            {
                IntPtr handle = surface.SharedHandle;

                // Then create a D3D9 texture using the D3D10 shared handle.
                // The D3D10 texture must be in the DXGI_FORMAT_B8G8R8A8_UNORM
                // format (direct 9 version is D3DFMT_A8R8G8B8).
                return(device.CreateTexture(
                           texture.Description.Width,
                           texture.Description.Height,
                           1,
                           1,  // D3DUSAGE_RENDERTARGET
                           21, // D3DFMT_A8R8G8B8
                           0,  // D3DPOOL_DEFAULT
                           ref handle));
            }
        }
示例#4
0
        /// <summary>
        /// Assigns a <see cref="D3D10.Texture2D"/> as the source of the back buffer.
        /// </summary>
        /// <param name="texture">
        /// The <c>Texture2D</c> to assign as the back buffer. Value can be null.
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// The D3D10Image has not been locked by a call to the
        /// <see cref="D3DImage.Lock" /> or <see cref="D3DImage.TryLock" /> methods.
        /// </exception>
        public void SetBackBuffer(D3D10.Texture2D texture)
        {
            // Free the old surface
            if (this.surface != null)
            {
                this.surface.Dispose();
                this.surface = null;
            }

            if (texture == null)
            {
                this.SetBackBuffer(D3DResourceType.IDirect3DSurface9, IntPtr.Zero);
            }
            else
            {
                using (var device = CreateDevice(Directx2D.NativeMethods.GetDesktopWindow()))
                    using (var texture9 = GetSharedSurface(device, texture))
                    {
                        this.surface = texture9.GetSurfaceLevel(0);
                    }

                this.SetBackBuffer(D3DResourceType.IDirect3DSurface9, this.surface.NativeInterface);
            }
        }
示例#5
0
        private void CreateTexture(int width, int height)
        {
            var description = new D3D10.Texture2DDescription();
            description.ArraySize = 1;
            description.BindingOptions = D3D10.BindingOptions.RenderTarget | D3D10.BindingOptions.ShaderResource;
            description.CpuAccessOptions = D3D10.CpuAccessOptions.None;
            description.Format = DirectX.Graphics.Format.B8G8R8A8UNorm;
            description.MipLevels = 1;
            description.MiscellaneousResourceOptions = D3D10.MiscellaneousResourceOptions.Shared;
            description.SampleDescription = new DirectX.Graphics.SampleDescription(1, 0);
            description.Usage = D3D10.Usage.Default;

            description.Height = (uint)height;
            description.Width = (uint)width;

            // Assign result to temporary variable in case CreateTexture2D throws
            var texture = this.device.CreateTexture2D(description);
            if (this.texture != null)
            {
                this.texture.Dispose();
            }
            this.texture = texture;
        }
示例#6
0
        /// <summary>
        /// Releases the DirectX device and any device dependent resources.
        /// </summary>
        /// <remarks>
        /// This method is safe to be called even if the instance has been disposed.
        /// </remarks>
        public void FreeResources()
        {
            this.OnFreeResources();

            if (this.texture != null)
            {
                this.texture.Dispose();
                this.texture = null;
            }
            if (this.renderTarget != null)
            {
                this.renderTarget.Dispose();
                this.renderTarget = null;
            }
            if (this.device != null)
            {
                this.device.Dispose();
                this.device = null;
            }
        }