Example #1
0
        public void Initialize(Presenter presenter)
        {
            // https://msdn.microsoft.com/en-us/library/windows/desktop/mt186590(v=vs.85).aspx
            Presenter  = presenter;
            Device3D11 = Device3D11.CreateFromDirect3D12(
                Device.NativeDevice,
                DeviceCreationFlags.BgraSupport,// | DeviceCreationFlags.Debug,
                null,
                null,
                presenter.NativeCommandQueue);

            DeviceContext3D = Device3D11.ImmediateContext;
            Device3D        = Device3D11.QueryInterface <Device3D>();

            // create d2d/directwrite
            using (var factory = new Factory(FactoryType.SingleThreaded))
            {
                Factory = factory.QueryInterface <Factory1>();
            }


            RoundedRectangleGeometry = new RoundedRectangleGeometry(
                Factory,
                new RoundedRectangle()
            {
                RadiusX = 32,
                RadiusY = 32,
                Rect    = new RectangleF(128, 128, 500 - 128 * 2, 500 - 128 * 2)
            });


            // direct write
            FactoryDW      = new FactoryDW(SharpDX.DirectWrite.FactoryType.Shared);
            FontLoader     = new ResourceFontLoader(FactoryDW, @"Fonts");
            FontCollection = new FontCollection(FactoryDW, FontLoader, FontLoader.Key);

            TextFormat = new TextFormat(
                FactoryDW,
                "Material-Design-Iconic-Font",
                FontCollection,
                SharpDX.DirectWrite.FontWeight.Normal,
                FontStyle.Normal,
                FontStretch.Normal,
                30);
            TextFormat.TextAlignment      = TextAlignment.Leading;
            TextFormat.ParagraphAlignment = ParagraphAlignment.Near;

            DeviceContextOptions deviceOptions = DeviceContextOptions.None;

            using (var deviceGI = Device3D.QueryInterface <DeviceGI>())
            {
                Device2D      = new Device(Factory, deviceGI);
                DeviceContext = new DeviceContext(Device2D, deviceOptions);
            }

            DesktopDpi = Factory.DesktopDpi;
            InitializePresentable(Device);
        }
        public SharpDX.Direct2D1.DeviceContext1 CreateDrawingContext(
            Bitmap1 renderTarget,
            DeviceContextOptions options = DeviceContextOptions.None)
        {
            var drawingContext = new SharpDX.Direct2D1.DeviceContext1(d2dDevice, options);

            drawingContext.Target = renderTarget;
            return(drawingContext);
        }
Example #3
0
        public static D2D1MetaResource <IDxgi1_2ContainerWithSwapChain> CreateForSwapChain(
            ThreadingMode threadingMode         = ThreadingMode.SingleThreaded,
            DeviceContextOptions contextOptions = DeviceContextOptions.EnableMultithreadedOptimizations,
            DebugLevel debugLevel = DebugLevel.None)
        {
            var props = new CreationProperties
            {
                DebugLevel    = debugLevel,
                ThreadingMode = threadingMode,
                Options       = contextOptions
            };

            return(CreateForSwapChainCore(ref props));
        }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DeviceContext"/> class using an existing <see cref="Device"/>.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="options">The options to be applied to the created device context.</param>
 /// <remarks>
 /// The new device context will not have a  selected target bitmap. The caller must create and select a bitmap as the target surface of the context.
 /// </remarks>
 /// <unmanaged>HRESULT ID2D1Device::CreateDeviceContext([In] D2D1_DEVICE_CONTEXT_OPTIONS options,[Out] ID2D1DeviceContext** deviceContext)</unmanaged>
 public DeviceContext(Device device, DeviceContextOptions options)
     : base(IntPtr.Zero)
 {
     device.CreateDeviceContext(options, this);
 }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DeviceContext"/> class using an existing <see cref="Device"/>.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="options">The options to be applied to the created device context.</param>
 /// <remarks>
 /// The new device context will not have a  selected target bitmap. The caller must create and select a bitmap as the target surface of the context.
 /// </remarks>
 /// <unmanaged>HRESULT ID2D1Device::CreateDeviceContext([In] D2D1_DEVICE_CONTEXT_OPTIONS options,[Out] ID2D1DeviceContext** deviceContext)</unmanaged>
 public DeviceContext(Device device, DeviceContextOptions options)
     : base(IntPtr.Zero)
 {
     device.CreateDeviceContext(options, this);
 }
        public SharpDX.Direct2D1.DeviceContext1 CreateDrawingContext(
            Bitmap1 renderTarget, 
            DeviceContextOptions options = DeviceContextOptions.None)
        {

            var drawingContext = new SharpDX.Direct2D1.DeviceContext1(d2dDevice, options);
            drawingContext.Target = renderTarget;
            return drawingContext;

        }