示例#1
0
        /// <summary>
        /// Creates a default D3D11 Texture with forced Shared-Flag
        /// </summary>
        /// <param name="device"></param>
        /// <param name="description"></param>
        /// <param name="D3D10Dev"> </param>
        /// <param name="D2DFactory"> </param>
        public SharedTexture(D2DInteropHandler handler, Texture2DDescription description)
        {
            As11Tex = new Texture2D(handler.D3DDevice11, new Texture2DDescription()
                {
                    ArraySize = description.ArraySize,
                    BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
                    CpuAccessFlags = description.CpuAccessFlags,
                    Format = description.Format,
                    Height = description.Height,
                    MipLevels = description.MipLevels,
                    OptionFlags = ResourceOptionFlags.KeyedMutex,
                    SampleDescription = description.SampleDescription,
                    Usage = description.Usage,
                    Width = description.Width
                });

            Mutex11 = new KeyedMutex(As11Tex);
            AsResource = new SlimDX.DXGI.Resource(As11Tex);

            As10Tex = handler.D3DDevice10.OpenSharedResource<SlimDX.Direct3D10.Texture2D>(AsResource.SharedHandle);
            Mutex10 = new KeyedMutex(As10Tex);
            AsSurface = As10Tex.AsSurface();
            As2DTarget = SlimDX.Direct2D.RenderTarget.FromDXGI(handler.D2DFactory, AsSurface, new RenderTargetProperties()
                                                                                                            {
                                                                                                                MinimumFeatureLevel = FeatureLevel.Direct3D10,
                                                                                                                Usage = RenderTargetUsage.None,
                                                                                                                Type = RenderTargetType.Hardware,
                                                                                                                PixelFormat = new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)
                                                                                                            });
        }
示例#2
0
        public void Initialize()
        {
            DXGIAdapter = new Factory1().GetAdapter1(0);
            var swapDescription = new SwapChainDescription()
            {
                BufferCount = 1,
                Usage = Usage.RenderTargetOutput,
                OutputHandle = Output.Handle,
                IsWindowed = true,
                ModeDescription =
                    new ModeDescription(0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                SampleDescription = new SampleDescription(1, 0),
                Flags = SwapChainFlags.AllowModeSwitch,
                SwapEffect = SwapEffect.Discard
            };
            #if DEBUG
            Device.CreateWithSwapChain(DXGIAdapter, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport, new[] { FeatureLevel.Level_10_0 }, swapDescription, out D3DDevice,
                                       out SChain);
            #else
            Device.CreateWithSwapChain(DXGIAdapter, DeviceCreationFlags.BgraSupport, new[] { FeatureLevel.Level_10_0 }, swapDescription, out D3DDevice,
                                       out SChain);
            #endif
            Context = D3DDevice.ImmediateContext;

            D2DInterop = new D2DInteropHandler(this);

            EnableWinEvents();
            InitOnce();
            InitDevice();
        }