public wnd_overlay() { this.Paint += Wnd_overlay_Paint; int initialStyle = WinAPI.GetWindowLong(this.Handle, -20); WinAPI.SetWindowLong(this.Handle, -20, initialStyle | 0x80000 | 0x20 | 0x80); InitializeComponent(); var factory = new Factory(); var renderProp = new HwndRenderTargetProperties() { Hwnd = this.Handle, PixelSize = new Size2(this.Width, this.Height), PresentOptions = PresentOptions.Immediately, }; Device = new WindowRenderTarget(factory, new RenderTargetProperties(new PixelFormat(Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)), renderProp); this.Visible = false; factory.Dispose(); updateWnd.RunWorkerAsync(); SharpDXThread.Start(); }
private void RenderInternal(D2D1.Factory factory, D2D1.RenderTarget rt, Map map, Envelope envelope) { //if style is not enabled, we don't need to render anything if (!Style.Enabled) { return; } var geoms = GetGeometriesInView(envelope); if (geoms.Count == 0) { return; } var stylesToRender = GetStylesToRender(Style); foreach (var style in stylesToRender) { if (style is VectorStyle) { using (var tmp = SharpDXVectorStyle.FromVectorStyle(rt, factory, (VectorStyle)style)) { //Linestring outlines is drawn by drawing the layer once with a thicker line //before drawing the "inline" on top. if (tmp.EnableOutline) { foreach (var geom in geoms) { if (geom != null) { //Draw background of all line-outlines first if (geom is ILineString) { SharpDXVectorRenderer.DrawLineString(rt, factory, geom as ILineString, tmp.Outline, tmp.OutlineWidth, tmp.OutlineStrokeStyle, map, tmp.LineOffset); } else if (geom is IMultiLineString) { SharpDXVectorRenderer.DrawMultiLineString(rt, factory, geom as IMultiLineString, tmp.Outline, tmp.OutlineWidth, tmp.OutlineStrokeStyle, map, tmp.LineOffset); } } } } foreach (IGeometry geom in geoms) { if (geom != null) { RenderGeometry(factory, rt, map, geom, tmp); } } } } else { lock (_syncRoot) _logger.Debug(fmh => fmh("Not a VectorStyle!")); } } }
/// <summary> /// Initializes a new instance of the <see cref="FactoryHandlerD2D"/> class. /// </summary> /// <param name="core">The core.</param> internal FactoryHandlerD2D(GraphicsCore core) { bool doFallbackMethod = core.Force2DFallbackMethod; // Do default method (Windows 8 and newer) if (!doFallbackMethod) { try { m_factory2 = new D2D.Factory2( D2D.FactoryType.SingleThreaded, core.IsDebugEnabled ? D2D.DebugLevel.Information : D2D.DebugLevel.None); m_factory = m_factory2; } catch (Exception) { doFallbackMethod = true; } } // Fallback method (on older windows platforms (< Windows 8)) if (doFallbackMethod) { m_factory2 = null; m_factory = new D2D.Factory( D2D.FactoryType.SingleThreaded, core.IsDebugEnabled ? D2D.DebugLevel.Information : D2D.DebugLevel.None); } }
public GeometryManager(D2D.Factory factory) { if (factory != null) this.factory = factory; else throw new ArgumentNullException(); }
private void SetupInstance(RendererOptions options) { _rendererOptions = options; if (options.Hwnd == IntPtr.Zero) { throw new ArgumentNullException(nameof(options.Hwnd)); } if (User32.IsWindow(options.Hwnd) == 0) { throw new ArgumentException("The window does not exist (hwnd = 0x" + options.Hwnd.ToString("X") + ")"); } RECT bounds = new RECT(); if (HelperMethods.GetRealWindowRect(options.Hwnd, out bounds) == 0) { throw new Exception("Failed to get the size of the given window (hwnd = 0x" + options.Hwnd.ToString("X") + ")"); } this.Width = bounds.Right - bounds.Left; this.Height = bounds.Bottom - bounds.Top; this.VSync = options.VSync; this.MeasureFPS = options.MeasureFps; _deviceProperties = new HwndRenderTargetProperties() { Hwnd = options.Hwnd, PixelSize = new Size2(this.Width, this.Height), PresentOptions = options.VSync ? PresentOptions.None : PresentOptions.Immediately }; var renderProperties = new RenderTargetProperties( RenderTargetType.Default, new PixelFormat(Format.R8G8B8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied), 96.0f, 96.0f, // we use 96.0f because it's the default value. This will scale every drawing by 1.0f (it obviously does not scale anything). Our drawing will be dpi aware! RenderTargetUsage.None, FeatureLevel.Level_DEFAULT); _factory = new Factory(); _fontFactory = new FontFactory(); try { _device = new WindowRenderTarget(_factory, renderProperties, _deviceProperties); } catch (SharpDXException) // D2DERR_UNSUPPORTED_PIXEL_FORMAT { renderProperties.PixelFormat = new PixelFormat(Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied); _device = new WindowRenderTarget(_factory, renderProperties, _deviceProperties); } _device.AntialiasMode = AntialiasMode.Aliased; // AntialiasMode.PerPrimitive fails rendering some objects // other than in the documentation: Cleartype is much faster for me than GrayScale _device.TextAntialiasMode = options.AntiAliasing ? SharpDX.Direct2D1.TextAntialiasMode.Cleartype : SharpDX.Direct2D1.TextAntialiasMode.Aliased; _sharedBrush = new SolidColorBrush(_device, default(RawColor4)); }
public Direct2DRenderer(IntPtr hwnd, bool limitFps) { _factory = new Factory(); _fontFactory = new FontFactory(); RECT bounds;//immer 1920x1080. resizing muss durch die Overlay klasse geregelt sein NativeMethods.GetWindowRect(hwnd, out bounds); var targetProperties = new HwndRenderTargetProperties { Hwnd = hwnd, PixelSize = new Size2(bounds.Right - bounds.Left, bounds.Bottom - bounds.Top), PresentOptions = limitFps ? PresentOptions.None : PresentOptions.Immediately //Immediatly -> Zeichnet sofort ohne auf 60fps zu locken. None lockt auf 60fps }; var prop = new RenderTargetProperties(RenderTargetType.Hardware, new PixelFormat(Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied), 0, 0, RenderTargetUsage.None, FeatureLevel.Level_DEFAULT); _device = new WindowRenderTarget(_factory, prop, targetProperties) { TextAntialiasMode = TextAntialiasMode.Cleartype, AntialiasMode = AntialiasMode.PerPrimitive }; }
public BitmapDrawingContext(int width, int height) { if (width < 0 || height < 0) throw new Exception("Negative BitmapDrawingContext's area"); _width = width; _height = height; _device = new Device1(DriverType.Hardware, DeviceCreationFlags.BgraSupport, FeatureLevel.Level_10_0); var textureDesc = new Texture2DDescription { MipLevels = 1, ArraySize = 1, BindFlags = BindFlags.RenderTarget, CpuAccessFlags = CpuAccessFlags.None, Format = Format.B8G8R8A8_UNorm, OptionFlags = ResourceOptionFlags.None, Width = _width, Height = _height, Usage = ResourceUsage.Default, SampleDescription = new SampleDescription(1, 0) }; _texture = new Texture2D(_device, textureDesc); _factory = new Factory(FactoryType.SingleThreaded, DebugLevel.None); }
// ReSharper restore InconsistentNaming static CompositionEngine() { _wicFactory = new SharpDX.WIC.ImagingFactory(); _dWriteFactory = new SharpDX.DirectWrite.Factory(); var d3DDevice = new SharpDX.Direct3D11.Device( DriverType.Hardware, DeviceCreationFlags.BgraSupport #if DEBUG | DeviceCreationFlags.Debug #endif , FeatureLevel.Level_11_1, FeatureLevel.Level_11_0, FeatureLevel.Level_10_1, FeatureLevel.Level_10_0, FeatureLevel.Level_9_3, FeatureLevel.Level_9_2, FeatureLevel.Level_9_1 ); var dxgiDevice = ComObject.As<SharpDX.DXGI.Device>(d3DDevice.NativePointer); //new SharpDX.DXGI.Device2(d3DDevice.NativePointer); var d2DDevice = new SharpDX.Direct2D1.Device(dxgiDevice); _d2DFactory = d2DDevice.Factory; _d2DDeviceContext = new SharpDX.Direct2D1.DeviceContext(d2DDevice, D2D.DeviceContextOptions.None); _d2DDeviceContext.DotsPerInch = new Size2F(LogicalDpi, LogicalDpi); }
/// <summary> /// Конструктор /// </summary> /// <param name="BackBuffer">Буффер на который будем рисовать, наш холст</param> /// <param name="Width">Ширина области в которую будем рисовать</param> /// <param name="Height">Высота объласти в которую будем рисовать</param> public TextWirter(SharpDX.Direct3D11.Texture2D BackBuffer, int Width, int Height) { this.TextFont = "Calibri"; this.TextSize = 14; _width = Width; _heght = Height; _Factory2D = new SharpDX.Direct2D1.Factory(); using (var surface = BackBuffer.QueryInterface <Surface>()) { _RenderTarget2D = new RenderTarget( _Factory2D, surface, new RenderTargetProperties( new PixelFormat( Format.R8G8B8A8_UNorm, AlphaMode.Premultiplied))); } _RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive; _FactoryDWrite = new SharpDX.DirectWrite.Factory(); _SceneColorBrush = new SolidColorBrush(_RenderTarget2D, Color.White); // Initialize a TextFormat InitTextFormat(); _RenderTarget2D.TextAntialiasMode = TextAntialiasMode.Cleartype; // Initialize a TextLayout // _TextLayout = new TextLayout(_FactoryDWrite, "SharpDX D2D1 - DWrite", _TextFormat, Width, Height); }
private void LoadOverlay(object sender, EventArgs e) { this.DoubleBuffered = true; base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.SupportsTransparentBackColor | ControlStyles.ResizeRedraw | ControlStyles.Opaque | ControlStyles.UserPaint, true); this._factory = new SharpDX.Direct2D1.Factory(); this._fontFactory = new SharpDX.DirectWrite.Factory(); HwndRenderTargetProperties properties = new HwndRenderTargetProperties { Hwnd = base.Handle, PixelSize = new Size2(base.Size.Width, base.Size.Height), PresentOptions = PresentOptions.None }; this._renderProperties = properties; this._device = new WindowRenderTarget(this._factory, new RenderTargetProperties(new PixelFormat(Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)), this._renderProperties); this._brush = new SolidColorBrush(this._device, new RawColor4((float)Color.Red.R, (float)Color.Red.G, (float)Color.Red.B, (float)Color.Red.A)); this._font = new TextFormat(this._fontFactory, "Verdana", FontWeight.Bold, FontStyle.Normal, 12f); this._fontSmall = new TextFormat(this._fontFactory, "Verdana", FontWeight.Bold, FontStyle.Normal, 10f); Console.WriteLine("Starting Maler Thread"); Thread thread1 = new Thread(new ParameterizedThreadStart(this.DirectXThread)) { Priority = ThreadPriority.Highest, IsBackground = true }; this._threadDx = thread1; this._running = true; this._threadDx.Start(); }
public void CreateDeviceIndependentResources(hkaSkeleton skeleton) { this.skeleton = skeleton; d2dFactory = new SharpDX.Direct2D1.Factory(); dwriteFactory = new SharpDX.DirectWrite.Factory(); }
public void Init(Window window) { var factory = new D2D.Factory(); var pixelFormat = new D2D.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D.AlphaMode.Ignore); var renderTargetProperties = new D2D.RenderTargetProperties ( // 默认的行为就是尝试使用硬件优先,否则再使用软件 D2D.RenderTargetType.Default, // 像素格式,对于当前大多数显卡来说,选择 B8G8R8A8 是完全能支持的 // 而且也方便和其他框架,如 WPF 交互 pixelFormat, dpiX: 96, dpiY: 96, D2D.RenderTargetUsage.None, D2D.FeatureLevel.Level_DEFAULT ); var hwndRenderTargetProperties = new D2D.HwndRenderTargetProperties(); hwndRenderTargetProperties.Hwnd = new WindowInteropHelper(window).Handle; hwndRenderTargetProperties.PixelSize = new Size2((int)window.ActualWidth, (int)window.ActualHeight); var renderTarget = new D2D.WindowRenderTarget(factory, renderTargetProperties, hwndRenderTargetProperties); }
private void Initialize() { G.Memory = new Mx(); factory = new Factory(); renderProperties = new HwndRenderTargetProperties() { Hwnd = nwHWND, PixelSize = new Size2((int)windowWidth, (int)windowHeight), PresentOptions = PresentOptions.Immediately }; device = new WindowRenderTarget(factory, new RenderTargetProperties(new PixelFormat(Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied)), renderProperties) { TextAntialiasMode = TextAntialiasMode.Grayscale, AntialiasMode = AntialiasMode.Aliased }; var margins = new Win32.Margins(); margins.Left = -1; margins.Top = 0; margins.Right = 0; margins.Bottom = 0; Win32.DwmExtendFrameIntoClientArea(nwHWND, ref margins); }
private void LoadOverlay(object sender, EventArgs e) { DoubleBuffered = true; SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.Opaque | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true); _Factory = new Factory(); _FontFactory = new FontFactory(); _RenderProperties = new HwndRenderTargetProperties { Hwnd = Handle, PixelSize = new SharpDX.Size2(Size.Width, Size.Height), PresentOptions = PresentOptions.None }; // Initialize DirectX _Device = new WindowRenderTarget(_Factory, new RenderTargetProperties(new PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)), _RenderProperties); _SolidColorBrush = new SolidColorBrush(_Device, new RawColor4(Color.White.R, Color.White.G, Color.White.B, Color.White.A)); _ThreadDX = new Thread(new ParameterizedThreadStart(DirectXThread)) { Priority = ThreadPriority.Highest, IsBackground = true }; _Running = true; _ThreadDX.Start(); }
public void Dispose() { foreach (var grad in verticalGradientCache.Values) { grad.Dispose(); } verticalGradientCache.Clear(); if (renderTarget != null) { renderTarget.Dispose(); renderTarget = null; } if (directWriteFactory != null) { directWriteFactory.Dispose(); directWriteFactory = null; } if (factory != null) { factory.Dispose(); factory = null; } }
public static void WatermarkText(Stream imageStream, Stream outputStream, string watermark, string font = "Times New Roman", float fontSize = 30.0f, int colorARGB = TransparentWhite) { using (var wic = new WIC.ImagingFactory2()) using (var d2d = new D2D.Factory()) using (var image = CreateWicImage(wic, imageStream)) using (var wicBitmap = new WIC.Bitmap(wic, image.Size.Width, image.Size.Height, WIC.PixelFormat.Format32bppPBGRA, WIC.BitmapCreateCacheOption.CacheOnDemand)) using (var target = new D2D.WicRenderTarget(d2d, wicBitmap, new D2D.RenderTargetProperties())) using (var bmpPicture = D2D.Bitmap.FromWicBitmap(target, image)) using (var dwriteFactory = new DWrite.Factory()) using (var brush = new D2D.SolidColorBrush(target, new Color(colorARGB))) { target.BeginDraw(); { target.DrawBitmap(bmpPicture, new RectangleF(0, 0, target.Size.Width, target.Size.Height), 1.0f, D2D.BitmapInterpolationMode.Linear); target.DrawRectangle(new RectangleF(0, 0, target.Size.Width, target.Size.Height), brush); var textFormat = new DWrite.TextFormat(dwriteFactory, font, DWrite.FontWeight.Bold, DWrite.FontStyle.Normal, fontSize) { ParagraphAlignment = DWrite.ParagraphAlignment.Far, TextAlignment = DWrite.TextAlignment.Trailing, }; target.DrawText(watermark, textFormat, new RectangleF(0, 0, target.Size.Width, target.Size.Height), brush); } target.EndDraw(); SaveD2DBitmap(wic, wicBitmap, outputStream); } }
/// <summary> /// 作成済みの2dテクスチャーから、D2D1レンダーターゲットを作成する /// </summary> /// <param name="device"></param> /// <param name="factory"></param> /// <param name="props"></param> /// <returns></returns> internal int CreateD2D1RenderTarget(Device device, SharpDX.Direct2D1.Factory factory, RenderTargetProperties props) { if (0 != m_createdTxNum || m_aTxResourceView[0] != null) { Debug.Assert(false); throw new CreatedException(); } if (m_type != ResourceDimension.Texture2D) { Debug.Assert(false); throw new CreatedException(); } throw new Exception("作成中"); //Surface1 pSurface; //m_aTexture[0].d2. //int hr = m_aTexture[0].p2D.(__uuidof(IDXGISurface1), (void**)&pSurface); //if (MC_FAILED(hr)) return hr; //pSurface.Dispose(); //hr = pD2DFactory.CreateDCRenderTarget( // pProps, // &m_pD2RenderTarget // ); //if (MC_FAILED(hr)) return hr; //SetD2D1RenderTargetFlg(true); m_D2D1Properties = props; return(0); }
private static void DrawRestDotPart(RenderTarget renderTarget, RawVector2 pos, Color color) { PointF[] pathPoints; using (GraphicsPath path = new GraphicsPath()) { path.AddBezier(pos.X, pos.Y + 3f, pos.X - 2f, pos.Y + 6f, pos.X - 8f, pos.Y + 8f, pos.X - 12f, pos.Y + 2f); path.AddBezier((float)(pos.X - 12f), (float)(pos.Y + 2f), (float)(pos.X - 8f), (float)(pos.Y + 6.5f), (float)(pos.X - 2f), (float)(pos.Y + 5f), (float)(pos.X + 1f), (float)(pos.Y - 1f)); path.Flatten(); pathPoints = path.PathPoints; path.Dispose(); } using (SharpDX.Direct2D1.Factory factory = renderTarget.Factory) { PathGeometry geometry = new PathGeometry(factory); if (pathPoints.Length > 1) { GeometrySink sink = geometry.Open(); sink.SetSegmentFlags(PathSegment.ForceRoundLineJoin); sink.BeginFigure(new RawVector2(pathPoints[0].X, pathPoints[0].Y), FigureBegin.Filled); for (int i = 1; i < pathPoints.Length; i++) { sink.AddLine(new RawVector2(pathPoints[i].X, pathPoints[i].Y)); } sink.EndFigure(FigureEnd.Closed); sink.Close(); sink.Dispose(); } SolidColorBrush brush = new SolidColorBrush(renderTarget, color.ToRawColor4(1f)); renderTarget.FillGeometry(geometry, brush); brush.Dispose(); geometry.Dispose(); } renderTarget.FillCircle(new RawVector2(pos.X - 8f, pos.Y + 2f), 3f, color); }
/// <summary> /// Конструктор /// </summary> /// <param name="BackBuffer">Буффер на который будем рисовать, наш холст</param> /// <param name="Width">Ширина области в которую будем рисовать</param> /// <param name="Height">Высота объласти в которую будем рисовать</param> public TextWirter(SharpDX.Direct3D11.Texture2D BackBuffer, int Width, int Height) { _width = Width; _heght = Height; _sw = new Stopwatch(); _sw.Start(); _Factory2D = new SharpDX.Direct2D1.Factory(); using (var surface = BackBuffer.QueryInterface <Surface>()) { _RenderTarget2D = new RenderTarget(_Factory2D, surface, new RenderTargetProperties( new PixelFormat( Format.R8G8B8A8_UNorm, AlphaMode.Premultiplied))); } _RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive; _FactoryDWrite = new SharpDX.DirectWrite.Factory(); _SceneColorBrush = new SolidColorBrush(_RenderTarget2D, Color.White); // Initialize a TextFormat _TextFormat = new TextFormat(_FactoryDWrite, "Calibri", 14) { TextAlignment = TextAlignment.Leading, ParagraphAlignment = ParagraphAlignment.Near }; _RenderTarget2D.TextAntialiasMode = TextAntialiasMode.Cleartype; // Initialize a TextLayout _TextLayout = new TextLayout(_FactoryDWrite, "SharpDX D2D1 - DWrite", _TextFormat, Width, Height); }
private void LoadOverlay(object sender, EventArgs e) { DoubleBuffered = true; SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.Opaque | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true); _factory = new Factory(); _renderProperties = new HwndRenderTargetProperties { Hwnd = Handle, PixelSize = new SharpDX.Size2(Size.Width, Size.Height), PresentOptions = PresentOptions.None }; marg.Left = 0; marg.Top = 0; marg.Right = this.Width; marg.Bottom = this.Height; DwmExtendFrameIntoClientArea(this.Handle, ref marg); // Initialize DirectX _device = new WindowRenderTarget(_factory, new RenderTargetProperties(new PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)), _renderProperties); _threadDx = new Thread(new ParameterizedThreadStart(DirectXThread)) { Priority = ThreadPriority.Highest, IsBackground = true }; _running = true; this.TopMost = true; _threadDx.Start(); }
public Direct2DFactories() { WICFactory = new WIC.ImagingFactory(); DWFactory = new DW.Factory(); var d3DDevice = new D3D11.Device( D3D.DriverType.Hardware, D3D11.DeviceCreationFlags.BgraSupport #if DEBUG | D3D11.DeviceCreationFlags.Debug #endif , D3D.FeatureLevel.Level_11_1, D3D.FeatureLevel.Level_11_0, D3D.FeatureLevel.Level_10_1, D3D.FeatureLevel.Level_10_0, D3D.FeatureLevel.Level_9_3, D3D.FeatureLevel.Level_9_2, D3D.FeatureLevel.Level_9_1 ); var dxgiDevice = ComObject.As <SharpDX.DXGI.Device> (d3DDevice.NativePointer); var d2DDevice = new D2D1.Device(dxgiDevice); D2DFactory = d2DDevice.Factory; //_d2DDeviceContext = new D2D1.DeviceContext (d2DDevice, D2D1.DeviceContextOptions.None); //var dpi = DisplayDpi; //_d2DDeviceContext.DotsPerInch = new Size2F (dpi, dpi); }
/// <summary> /// Initialization /// </summary> public virtual void Setup() { form = new RenderForm(Window.Title); form.SetBounds(Window.Left, Window.Top, Window.Width, Window.Height); sw = new Stopwatch(); timing = new GameTime(); SwapChainDescription desc = new SwapChainDescription() { BufferCount = 1, ModeDescription = new ModeDescription(Window.Width, Window.Height, new Rational(FrameRate, 1), Format.R8G8B8A8_UNorm), IsWindowed = true, OutputHandle = form.Handle, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }; Device1.CreateWithSwapChain(SharpDX.Direct3D.DriverType.Hardware, DeviceCreationFlags.BgraSupport, desc, out device, out swapChain); D2DFactory = new SharpDX.Direct2D1.Factory(); factory = swapChain.GetParent <SharpDX.DXGI.Factory>(); factory.MakeWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll); backBuffer = Texture2D.FromSwapChain <Texture2D>(swapChain, 0); renderView = new RenderTargetView(device, backBuffer); Surface surface = backBuffer.QueryInterface <Surface>(); D2DRenderTarget = new RenderTarget(D2DFactory, surface, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied))); }
public CustomTextRenderer(SharpDX.Direct2D1.Factory factory, SharpDX.Direct2D1.DeviceContext renderTarget, SolidColorBrush outline, SolidColorBrush fill) { _d2DFactory = factory; _dc = renderTarget; _outlineBrush = outline; _fillBrush = fill; }
private static void DrawSmallRaw(Person person, WIC.ImagingFactory wic, D2D.Factory d2dFactory, WIC.FormatConverter converter) { var whRate = 1.0f * converter.Size.Width / converter.Size.Height; var smallRawSize = new Vector2(whRate * ImageDefines.SmallRawY, ImageDefines.SmallRawY); var scale = ImageDefines.SmallRawY / converter.Size.Height; using (var wicBitmap = new WIC.Bitmap(wic, (int)smallRawSize.X, (int)smallRawSize.Y, WIC.PixelFormat.Format32bppPBGRA, WIC.BitmapCreateCacheOption.CacheOnDemand)) using (var target = new D2D.WicRenderTarget(d2dFactory, wicBitmap, new D2D.RenderTargetProperties())) using (var bmp = D2D.Bitmap.FromWicBitmap(target, converter)) using (var bmpBrush = new D2D.BitmapBrush(target, bmp)) { target.BeginDraw(); target.Transform = Matrix3x2.Scaling(scale, scale); target.DrawBitmap(bmp, 1.0f, D2D.BitmapInterpolationMode.Linear); target.EndDraw(); using (var file = File.Create(person.SmallRawImage)) { WicTools.SaveD2DBitmap(wic, wicBitmap, file); } } }
/// <summary> /// 初始化<see cref="Sence" />的新实例. /// </summary> /// <param name="id">标识</param> /// <param name="control">渲染的目标控件</param> protected Sence(string id = "", [MustNotEqualNull] Control control = null) : base(id) { Control = control; Direct2D1Factory = new SharpDX.Direct2D1.Factory(); SurfaceRenderTarget = new WindowRenderTarget(Direct2D1Factory, new RenderTargetProperties ( //此处必须为B8G8R8A8格式,否则至少Win7不支持 new PixelFormat(Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Ignore) ), new HwndRenderTargetProperties { Hwnd = Control.Handle, PixelSize = new Size2(Control.Width, Control.Height), PresentOptions = PresentOptions.None, }) { AntialiasMode = AntialiasMode.PerPrimitive }; DirectWriteFactory = new SharpDX.DirectWrite.Factory(); }
public static void FillSector(this RenderTarget renderTarget, RawVector2 pos, float radius, Color color, float angleStart, float angleEnd) { PointF[] pathPoints; using (GraphicsPath path = new GraphicsPath()) { radius *= 2f; path.AddPie(pos.X - (radius / 2f), pos.Y - (radius / 2f), radius, radius, angleStart, angleEnd); path.Flatten(); pathPoints = path.PathPoints; path.Dispose(); } using (SharpDX.Direct2D1.Factory factory = renderTarget.Factory) { PathGeometry geometry = new PathGeometry(factory); if (pathPoints.Length > 1) { GeometrySink sink = geometry.Open(); sink.SetSegmentFlags(PathSegment.ForceRoundLineJoin); sink.BeginFigure(new RawVector2(pathPoints[0].X, pathPoints[0].Y), FigureBegin.Filled); for (int i = 1; i < pathPoints.Length; i++) { sink.AddLine(new RawVector2(pathPoints[i].X, pathPoints[i].Y)); } sink.EndFigure(FigureEnd.Closed); sink.Close(); sink.Dispose(); } SolidColorBrush brush = new SolidColorBrush(renderTarget, color.ToRawColor4(1f)); renderTarget.FillGeometry(geometry, brush); brush.Dispose(); geometry.Dispose(); } }
public void ComputeTransLastHitGeometry() { switch (scMgr.GraphicsType) { case GraphicsType.GDIPLUS: if (hitGraphicsPath == null) { return; } transLastHitGraphicsPath = (GraphicsPath)hitGraphicsPath.Clone(); transLastHitGraphicsPath.Transform(globalMatrix); break; case GraphicsType.D2D: if (hitPathGeometry == null) { return; } SharpDX.Direct2D1.Factory d2dFactory = D2DGraphics.d2dFactory; RawMatrix3x2 m32 = GDIDataD2DUtils.TransMatrixToRawMatrix3x2(globalMatrix); transLastHitPathGeometry = new TransformedGeometry(d2dFactory, hitPathGeometry, m32); break; } }
// ReSharper restore InconsistentNaming static CompositionEngine() { _wicFactory = new SharpDX.WIC.ImagingFactory(); _dWriteFactory = new SharpDX.DirectWrite.Factory(); var d3DDevice = new SharpDX.Direct3D11.Device( DriverType.Hardware, DeviceCreationFlags.BgraSupport #if DEBUG | DeviceCreationFlags.Debug #endif , FeatureLevel.Level_11_1, FeatureLevel.Level_11_0, FeatureLevel.Level_10_1, FeatureLevel.Level_10_0, FeatureLevel.Level_9_3, FeatureLevel.Level_9_2, FeatureLevel.Level_9_1 ); var dxgiDevice = ComObject.As <SharpDX.DXGI.Device>(d3DDevice.NativePointer); //new SharpDX.DXGI.Device2(d3DDevice.NativePointer); var d2DDevice = new SharpDX.Direct2D1.Device(dxgiDevice); _d2DFactory = d2DDevice.Factory; _d2DDeviceContext = new SharpDX.Direct2D1.DeviceContext(d2DDevice, D2D.DeviceContextOptions.None); _d2DDeviceContext.DotsPerInch = new DrawingSizeF( Windows.Graphics.Display.DisplayProperties.LogicalDpi, Windows.Graphics.Display.DisplayProperties.LogicalDpi); }
private D2D(Direct2D.Factory d2dFactory, Direct2D.RenderTarget d2dRenderTarget) { this.d2dFactory = d2dFactory; this.d2dRenderTarget = d2dRenderTarget; this.wicFactory = new WIC.ImagingFactory(); this.dwFactory = new DW.Factory(); }
protected virtual void Initialize(Configuration config) { var desc = new SwapChainDescription() { BufferCount = 1, ModeDescription = new ModeDescription(config.Width, config.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm), IsWindowed = true, OutputHandle = DisplayHandle, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }; SharpDX.Direct3D11.Device.CreateWithSwapChain( DriverType.Hardware, DeviceCreationFlags.BgraSupport, new[] { SharpDX.Direct3D.FeatureLevel.Level_10_0 }, desc, out device, out swapChain); SharpDX.DXGI.Factory factory = swapChain.GetParent <SharpDX.DXGI.Factory>(); factory.MakeWindowAssociation(DisplayHandle, WindowAssociationFlags.IgnoreAll); backBuffer = Texture2D.FromSwapChain <Texture2D>(swapChain, 0); backBufferView = new RenderTargetView(device, backBuffer); Factory2D = new SharpDX.Direct2D1.Factory(); using (var surface = BackBuffer.QueryInterface <Surface>()) { RenderTarget2D = new RenderTarget(Factory2D, surface, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied))); } RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive; FactoryDWrite = new SharpDX.DirectWrite.Factory(); SceneColorBrush = new SolidColorBrush(RenderTarget2D, SharpDX.Color.White); }
public InfoText(SharpDX.Direct3D11.Device device, int width, int height) { _immediateContext = device.ImmediateContext; _rect.Size = new Size2F(width, height); _bitmapSize = width * height * 4; IsEnabled = true; using (var factoryWic = new SharpDX.WIC.ImagingFactory()) { _wicBitmap = new SharpDX.WIC.Bitmap(factoryWic, width, height, _pixelFormat, SharpDX.WIC.BitmapCreateCacheOption.CacheOnLoad); } var renderTargetProperties = new RenderTargetProperties(RenderTargetType.Default, new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.R8G8B8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied), 0, 0, RenderTargetUsage.None, SharpDX.Direct2D1.FeatureLevel.Level_DEFAULT); using (var factory2D = new SharpDX.Direct2D1.Factory()) { _wicRenderTarget = new WicRenderTarget(factory2D, _wicBitmap, renderTargetProperties); _wicRenderTarget.TextAntialiasMode = TextAntialiasMode.Default; } using (var factoryDWrite = new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Shared)) { _textFormat = new TextFormat(factoryDWrite, "Tahoma", 20); } Color4 color = new Color4(1, 1, 1, 1); _sceneColorBrush = new SolidColorBrush(_wicRenderTarget, color); _clearColor = color; _clearColor.Alpha = 0; _renderTexture = new Texture2D(device, new Texture2DDescription() { ArraySize = 1, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.Write, Format = Format.R8G8B8A8_UNorm, Height = height, Width = width, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Dynamic }); OverlayBufferView = new ShaderResourceView(device, _renderTexture, new ShaderResourceViewDescription() { Format = _renderTexture.Description.Format, Dimension = ShaderResourceViewDimension.Texture2D, Texture2D = new ShaderResourceViewDescription.Texture2DResource() { MipLevels = 1, MostDetailedMip = 0 } }); }
/// <summary> /// Generate a PIE chart slice. /// </summary> /// <param name="factory2D"></param> /// <param name="percent"></param> /// <param name="radius"></param> /// <param name="center"></param> /// <param name="rotationAngle"></param> /// <returns></returns> public static PathGeometry CreatePieSlice(this Factory factory2D, float percent, float radius, float rotationAngle = 0) { PathGeometry g = new PathGeometry(factory2D); var startArc = new Vector2() { X = radius, Y = 0 }; var endArc = new Vector2() { X = radius * (float)Math.Cos(percent * MathUtil.TwoPi), Y = radius * (float)Math.Sin(percent * MathUtil.TwoPi) }; using (var sink = g.Open()) { sink.SetFillMode(SharpDX.Direct2D1.FillMode.Winding); sink.BeginFigure(Vector2.Zero, FigureBegin.Filled); sink.AddLine(startArc); sink.AddArc(new ArcSegment() { ArcSize = percent <= 0.5 ? ArcSize.Small : ArcSize.Large, RotationAngle = rotationAngle, Point = endArc, Size = new Size2F(radius, radius), SweepDirection = SweepDirection.Clockwise }); sink.AddLine(Vector2.Zero); sink.EndFigure(FigureEnd.Closed); sink.Close(); } return(g); }
public DeviceManager() { try { // 创建 Dierect3D 设备。 this.d3DDevice = new D3D11Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport); this.dxgiDevice = d3DDevice.QueryInterface <D3D11Device1>().QueryInterface <DXGIDevice>(); // 创建 Direct2D 设备和工厂。 this.d2DDevice = new D2D1Device(dxgiDevice); this.d2DContext = new DeviceContext(d2DDevice, DeviceContextOptions.None); this.d2DFactory = this.d2DContext.Factory; this.wicFactory = new ImagingFactory2(); } catch { this.ClearResources(); try { // 创建 D3D 设备异常,则尝试 Direct2D 单线程工厂。 this.d2DFactory = new Factory(FactoryType.SingleThreaded); this.wicFactory = new ImagingFactory(); } catch { this.ClearResources(); } } if (this.d2DFactory != null) { Dpi = d2DFactory.DesktopDpi; BitmapProps1 = new BitmapProperties1(D2PixelFormat, Dpi.Width, Dpi.Height, BitmapOptions.Target); } }
public InfoText(SharpDX.Direct3D11.Device device, int width, int height) { _immediateContext = device.ImmediateContext; _rect.Size = new Size2F(width, height); _bitmapSize = width * height * 4; IsEnabled = true; using (var factoryWic = new SharpDX.WIC.ImagingFactory()) { _wicBitmap = new SharpDX.WIC.Bitmap(factoryWic, width, height, _pixelFormat, SharpDX.WIC.BitmapCreateCacheOption.CacheOnLoad); } var renderTargetProperties = new RenderTargetProperties(RenderTargetType.Default, new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.R8G8B8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied), 0, 0, RenderTargetUsage.None, SharpDX.Direct2D1.FeatureLevel.Level_DEFAULT); using (var factory2D = new SharpDX.Direct2D1.Factory()) { _wicRenderTarget = new WicRenderTarget(factory2D, _wicBitmap, renderTargetProperties); _wicRenderTarget.TextAntialiasMode = TextAntialiasMode.Default; } using (var factoryDWrite = new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Shared)) { _textFormat = new TextFormat(factoryDWrite, "Tahoma", 20); } Color4 color = new Color4(1, 1, 1, 1); _sceneColorBrush = new SolidColorBrush(_wicRenderTarget, color); _clearColor = color; _clearColor.Alpha = 0; _renderTexture = new Texture2D(device, new Texture2DDescription() { ArraySize = 1, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.Write, Format = Format.R8G8B8A8_UNorm, Height = height, Width = width, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Dynamic }); OverlayBufferRes = new ShaderResourceView(device, _renderTexture, new ShaderResourceViewDescription() { Format = _renderTexture.Description.Format, Dimension = ShaderResourceViewDimension.Texture2D, Texture2D = new ShaderResourceViewDescription.Texture2DResource() { MipLevels = 1, MostDetailedMip = 0 } }); }
/// <summary> /// Creates an instance of this class /// </summary> /// <param name="layername">The layer name</param> /// <param name="datasource">The data source</param> public SharpDXVectorLayer(string layername, IProvider datasource) : base(layername, datasource) { _syncRoot = new object(); _d2d1Factory = new D2D1.Factory(D2D1.FactoryType.SingleThreaded); AntialiasMode = D2D1.AntialiasMode.PerPrimitive; }
static void Main() { var form = new RenderForm("KinectLight"); form.Size = new System.Drawing.Size(1920,1200); var desc = new SwapChainDescription() { BufferCount = 1, ModeDescription = new ModeDescription(form.ClientSize.Width, form.ClientSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm), IsWindowed = true, OutputHandle = form.Handle, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }; SharpDX.Direct3D10.Device1 device; SwapChain swapChain; SharpDX.Direct3D10.Device1.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, desc, SharpDX.Direct3D10.FeatureLevel.Level_10_1, out device, out swapChain); var d2dFactory = new SharpDX.Direct2D1.Factory(); var surface = Surface.FromSwapChain(swapChain, 0); RenderTarget dc = new RenderTarget(d2dFactory, surface, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied))); MainGame.Instance.Height = form.ClientSize.Height; MainGame.Instance.Width = form.ClientSize.Width; GameTime gameTime = new GameTime(); var config = new HttpSelfHostConfiguration("http://localhost:8080"); config.Routes.MapHttpRoute( "API Default", "api/{controller}/{action}/{name}", new { id = RouteParameter.Optional }); HttpSelfHostServer server = new HttpSelfHostServer(config); server.OpenAsync().Wait(); RenderLoop.Run(form, () => { gameTime.StartFrame(); MainGame.Instance.Update(gameTime); dc.BeginDraw(); dc.Clear(Colors.White); MainGame.Instance.Render(dc); var res = dc.EndDraw(); swapChain.Present(1, PresentFlags.None); //Thread.Sleep(1); }); server.Dispose(); MainGame.Instance.Dispose(); dc.Dispose(); surface.Dispose(); d2dFactory.Dispose(); device.Dispose(); swapChain.Dispose(); }
public CompositionEngine() { _dxgiFactory = new SharpDX.DXGI.Factory1(); //_dxgiFactory.Adapters1[0].Description1. //_dxgiFactory = new SharpDX.DXGI.Factory(); //new _wicFactory = new SharpDX.WIC.ImagingFactory(); _d2DFactory = new SharpDX.Direct2D1.Factory(); _dWriteFactory = new SharpDX.DirectWrite.Factory(); }
public DeviceManager() { var device = new D3D11.Device( D3D.DriverType.Hardware, /*DeviceCreationFlags.Debug |*/ D3D11.DeviceCreationFlags.BgraSupport); DeviceContext = device.ImmediateContext; Direct2dFactory = new D2D.Factory(); DirectWriteFactory = new DW.Factory(); }
public void Create3dObjects() { //Create RenderWindow RenderWindowInstance = new ModelRenderWindow(); FormInstance = RenderWindowInstance.CreateWindow(1080,1240,FormStartPosition.CenterScreen); //Create SwapChain SwapChainCreator = new ModelSwapChainDesc(); SwapChainD = SwapChainCreator.CreateSwapChain(2, Usage.RenderTargetOutput, FormInstance.Handle, true, 0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm, 1,0,SwapChainFlags.AllowModeSwitch, SwapEffect.Discard); //Create Device Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, SwapChainD, out GraphicsDevice, out NewSwapChain); //Create Back buffer BackBuffer = Surface.FromSwapChain(NewSwapChain, 0); //Create Factory FactoryD2D FactoryInstance = new FactoryD2D(); //Create RenderTarget RenderTargetInstance = new ModelRenderTarget(); RenderTarget = RenderTargetInstance.CreateRenderTarget(SharpDX.Direct2D1.FeatureLevel.Level_DEFAULT, new PixelFormat(Format.Unknown, SharpDX.Direct2D1.AlphaMode.Ignore), RenderTargetType.Default, RenderTargetUsage.None, BackBuffer, FactoryInstance); RenderLoop.Run(FormInstance, () => { RenderTarget.BeginDraw(); RenderTarget.Transform = Matrix3x2.Identity; RenderTarget.Clear(Color.White); using (var brush = new SolidColorBrush(RenderTarget, Color.Red)) { //for (int x = 0; x < RenderTarget.Size.Width; x += 10) // RenderTarget.DrawLine(new Vector2(x, 0), new Vector2(x, RenderTarget.Size.Height), brush, 0.5f); //for (int y = 0; y < RenderTarget.Size.Height; y += 10) // RenderTarget.DrawLine(new Vector2(0, y), new Vector2(RenderTarget.Size.Width, y), brush, 0.5f); RenderTarget.DrawLine(new Vector2(300, 10), new Vector2(300, 300), brush,1.5f); // RenderTarget.FillRectangle(new RectangleF(RenderTarget.Size.Width / 2 - 50, RenderTarget.Size.Height / 2 - 50, 100, 100), brush); } // RenderTarget.DrawRectangle( // new RectangleF(RenderTarget.Size.Width / 2 - 100, RenderTarget.Size.Height / 2 - 100, 200, 200), // new SolidColorBrush(RenderTarget, Color.CornflowerBlue)); RenderTarget.EndDraw(); NewSwapChain.Present(0, PresentFlags.None); }); RenderTarget.Dispose(); NewSwapChain.Dispose(); GraphicsDevice.Dispose(); }
/// <summary> /// Initializes a new DirectXGraphics class. /// </summary> public DirectXGraphics() { ResourceManager = new DirectXResourceManager(); ContentProcessors = new IContentProcessor[] {new DirectXFontContentProcessor(), new DirectXPenContentProcessor(), new DirectXTextureContentProcessor()}; SmoothingMode = SmoothingMode.AntiAlias; InterpolationMode = InterpolationMode.Linear; _graphicsDevice = SGL.QueryComponents<GraphicsDevice>(); var d2DFactory = new Factory(FactoryType.MultiThreaded); DirectXHelper.D2DFactory = d2DFactory; DirectXHelper.DirectWriteFactory = new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Shared); }
public RendererUtil() { var defaultDevice = new D3D11.Device(D3D.DriverType.Hardware, D3D11.DeviceCreationFlags.BgraSupport); d3dDevice = defaultDevice.QueryInterface<D3D11.Device1>(); dxgiDevice = d3dDevice.QueryInterface<Device>(); d2dFactory = new D2D.Factory(D2D.FactoryType.MultiThreaded); d2dDevice = new D2D.Device(dxgiDevice); d2dDeviceContext = new D2D.DeviceContext(d2dDevice, D2D.DeviceContextOptions.None); imagingFactory = new ImagingFactory2(); }
private static void Main() { var wicFactory = new ImagingFactory(); var d2dFactory = new SharpDX.Direct2D1.Factory(); string filename = "output.jpg"; const int width = 512; const int height = 512; var rectangleGeometry = new RoundedRectangleGeometry(d2dFactory, new RoundedRectangle() { RadiusX = 32, RadiusY = 32, Rect = new RectangleF(128, 128, width - 128, height-128) }); var wicBitmap = new Bitmap(wicFactory, width, height, SharpDX.WIC.PixelFormat.Format32bppBGR, BitmapCreateCacheOption.CacheOnLoad); var renderTargetProperties = new RenderTargetProperties(RenderTargetType.Default, new PixelFormat(Format.Unknown, AlphaMode.Unknown), 0, 0, RenderTargetUsage.None, FeatureLevel.Level_DEFAULT); var d2dRenderTarget = new WicRenderTarget(d2dFactory, wicBitmap, renderTargetProperties); var solidColorBrush = new SolidColorBrush(d2dRenderTarget, Color.White); d2dRenderTarget.BeginDraw(); d2dRenderTarget.Clear(Color.Black); d2dRenderTarget.FillGeometry(rectangleGeometry, solidColorBrush, null); d2dRenderTarget.EndDraw(); if (File.Exists(filename)) File.Delete(filename); var stream = new WICStream(wicFactory, filename, NativeFileAccess.Write); // Initialize a Jpeg encoder with this stream var encoder = new JpegBitmapEncoder(wicFactory); encoder.Initialize(stream); // Create a Frame encoder var bitmapFrameEncode = new BitmapFrameEncode(encoder); bitmapFrameEncode.Initialize(); bitmapFrameEncode.SetSize(width, height); var pixelFormatGuid = SharpDX.WIC.PixelFormat.FormatDontCare; bitmapFrameEncode.SetPixelFormat(ref pixelFormatGuid); bitmapFrameEncode.WriteSource(wicBitmap); bitmapFrameEncode.Commit(); encoder.Commit(); bitmapFrameEncode.Dispose(); encoder.Dispose(); stream.Dispose(); System.Diagnostics.Process.Start(Path.GetFullPath(Path.Combine(Environment.CurrentDirectory,filename))); }
public SharpDXDevice(Window window) { this.window = window; width = (int)window.ViewportSize.Width; height = (int)window.ViewportSize.Height; DxDevice.CreateWithSwapChain(DriverType.Hardware, #if DEBUG DeviceCreationFlags.Debug | #endif DeviceCreationFlags.BgraSupport, CreateSwapChainDescription(), out device, out swapChain); direct2DFactory = new D2dFactory(); backBuffer = Resource.FromSwapChain<Texture2D>(swapChain, 0); surface = backBuffer.QueryInterface<Surface>(); RenderTarget = new RenderTarget(direct2DFactory, surface, defaultRenderTargetProperties); window.ViewportSizeChanged += ResetDeviceToNewViewportSize; Screen = new ScreenSpace(window.ViewportSize); }
public RenderTarget CreateRenderTarget(SharpDX.Direct2D1.FeatureLevel PFeatureLevel, PixelFormat PPixelFormat, RenderTargetType PRenderTargetType, RenderTargetUsage PRenderTargetUsage, Surface PBackBuffer, FactoryD2D PFactory) { this._FeatureLevel = PFeatureLevel; this._PixelFormat = PPixelFormat; this._RenderType = PRenderTargetType; this._RenderUsage = PRenderTargetUsage; _DPI = PFactory.DesktopDpi; _RenderTarget = new RenderTarget(PFactory, PBackBuffer, new RenderTargetProperties() { DpiX = _DPI.Width, DpiY = _DPI.Height, MinLevel = _FeatureLevel, PixelFormat = _PixelFormat, Type = _RenderType, Usage= _RenderUsage }); return _RenderTarget; }
public D3D11_2D1(Device11 drawdevice, Device10 textdevice) : base(false) // nothing! { if (drawdevice == null || textdevice == null) { using (var dg = new DisposeGroup()) { if (drawdevice == null && textdevice == null) { Adapter a = null; foreach (var item in DeviceUtil.GetAdapters(dg)) { if (!item.IsInterfaceSupported<Device10>()) continue; if (Device11.GetSupportedFeatureLevel(item) < Direct3D.FeatureLevel.Level_10_1) continue; a = item; break; } device = new Device11(a, DeviceCreationFlags.BgraSupport | DeviceCreationFlags.SingleThreaded | DeviceCreationFlags.Debug); device10 = new Device10(a, Direct3D10.DeviceCreationFlags.BgraSupport | Direct3D10.DeviceCreationFlags.Singlethreaded | Direct3D10.DeviceCreationFlags.Debug); } else { if (drawdevice == null) { using (var xgidtext = textdevice.QueryInterface<DeviceXGI>()) device = new Device11(xgidtext.Adapter, DeviceCreationFlags.BgraSupport | DeviceCreationFlags.SingleThreaded | DeviceCreationFlags.Debug); textdevice.AddReference(); device10 = textdevice; } else { using (var xgiddraw = drawdevice.QueryInterface<DeviceXGI>()) device10 = new Device10(xgiddraw.Adapter, Direct3D10.DeviceCreationFlags.BgraSupport | Direct3D10.DeviceCreationFlags.Singlethreaded | Direct3D10.DeviceCreationFlags.Debug); drawdevice.AddReference(); device = drawdevice; } } } } else { using (var xgidev10 = device10.QueryInterface<DeviceXGI>()) using (var xgidev11 = device.QueryInterface<DeviceXGI>()) { if (xgidev10.Adapter.NativePointer != xgidev11.Adapter.NativePointer) throw new ArgumentException("drawdevice.Adapter.NativePointer != textdevice.Adapter.NativePointer"); } textdevice.AddReference(); drawdevice.AddReference(); device = drawdevice; device10 = textdevice; } factory2D = new SharpDX.Direct2D1.Factory(); factoryDW = new FactoryDW(); }
void InitD2D() { _factoryD2D = new SharpDX.Direct2D1.Factory(); _factoryDWrite = new SharpDX.DirectWrite.Factory(); HwndRenderTargetProperties properties = new HwndRenderTargetProperties(); properties.Hwnd = this.Handle; properties.PixelSize = new SharpDX.Size2(this.Width, this.Height); properties.PresentOptions = PresentOptions.Immediately; _renderTarget = new WindowRenderTarget(_factoryD2D, new RenderTargetProperties(_renderTargetType, new PixelFormat(Format.Unknown, AlphaMode.Premultiplied), 96.0f, 96.0f, RenderTargetUsage.GdiCompatible, FeatureLevel.Level_DEFAULT), properties); }
private void _initializeGraphics() { Console.Write("Initializing graphic device... "); var desc = new SwapChainDescription() { BufferCount = 1, ModeDescription = new ModeDescription( _appConfiguration.Width, _appConfiguration.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm), IsWindowed = !_appConfiguration.FullScreen, OutputHandle = DisplayHandle, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }; Device1.CreateWithSwapChain( DriverType.Hardware, #if DEBUG DeviceCreationFlags.BgraSupport | DeviceCreationFlags.Debug | DeviceCreationFlags.SingleThreaded, #else DeviceCreationFlags.BgraSupport, #endif desc, out _device, out _swapChain); if (_device == null) throw new SharpDXException("Failed to initialize graphics device."); if (_swapChain == null) throw new SharpDXException("Failed to initialize swap chain."); ToDispose<Device1>(_device); ToDispose<SwapChain>(_swapChain); Factory2D = ToDispose<Factory2D>(new Factory2D()); _factoryDXGI = ToDispose<FactoryDXGI>(_swapChain.GetParent<FactoryDXGI>()); _factoryDXGI.MakeWindowAssociation(DisplayHandle, WindowAssociationFlags.IgnoreAll); _backBuffer = ToDispose<Texture2D>(Texture2D.FromSwapChain<Texture2D>(_swapChain, 0)); _backBufferRenderTargetView = ToDispose<RenderTargetView>(new RenderTargetView(_device, _backBuffer)); Viewport = new Viewport(0, 0, _appConfiguration.Width, _appConfiguration.Height); using (var surface = _backBuffer.QueryInterface<Surface>()) { RenderTarget2D = ToDispose<RenderTarget>( new RenderTarget(Factory2D, surface, new RenderTargetProperties( new PixelFormat( Format.Unknown, AlphaMode.Premultiplied)))); } RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive; _vsync = Config.VSync; ScreenSize = new DrawingSizeF(Viewport.Width, Viewport.Height); Console.WriteLine("done."); }
private void InitD2D() { factory = new D2D.Factory(); windowRenderTarget = new D2D.WindowRenderTarget(factory, new D2D.RenderTargetProperties( new D2D.PixelFormat(Format.R8G8B8A8_UNorm, D2D.AlphaMode.Premultiplied)), new D2D.HwndRenderTargetProperties { Hwnd = Handle, PixelSize = new DrawingSize(ClientSize.Width, ClientSize.Height), PresentOptions = D2D.PresentOptions.Immediately }); }
public SharpDXStates() { d2DFactory = new D2dFactory(); }
static Direct2DPanel() { D2DFactory = new D2D.Factory(D2D.FactoryType.SingleThreaded); D2DProps = new D2D.RenderTargetProperties(); }
public Direct2DFactories() { WICFactory = new WIC.ImagingFactory (); DWFactory = new DW.Factory (); var d3DDevice = new D3D11.Device ( D3D.DriverType.Hardware, D3D11.DeviceCreationFlags.BgraSupport #if DEBUG | D3D11.DeviceCreationFlags.Debug #endif , D3D.FeatureLevel.Level_11_1, D3D.FeatureLevel.Level_11_0, D3D.FeatureLevel.Level_10_1, D3D.FeatureLevel.Level_10_0, D3D.FeatureLevel.Level_9_3, D3D.FeatureLevel.Level_9_2, D3D.FeatureLevel.Level_9_1 ); var dxgiDevice = ComObject.As<SharpDX.DXGI.Device> (d3DDevice.NativePointer); var d2DDevice = new D2D1.Device (dxgiDevice); D2DFactory = d2DDevice.Factory; //_d2DDeviceContext = new D2D1.DeviceContext (d2DDevice, D2D1.DeviceContextOptions.None); //var dpi = DisplayDpi; //_d2DDeviceContext.DotsPerInch = new Size2F (dpi, dpi); }
public OutlineRenderer(D2DFactory factory) { this.factory = factory; }
public DrawSurface(GxContext context) { DirectWriteFactory = new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Isolated); Direct2DFactory = new Factory(); mDevice = context; }
/// <summary> /// 初始化绘图有关组件 /// </summary> /// <param name="width">游戏窗口宽度</param> /// <param name="height">游戏窗口高度</param> /// <param name="title">游戏窗口标题</param> private void InitRenderComponent(int width, int height, string title) { WindowSize = new Size2(width, height); var factory = new Factory(FactoryType.SingleThreaded); var hwndRenderTargetProperties = new HwndRenderTargetProperties { Hwnd = Form.Handle, PixelSize = new Size2(Form.Width, Form.Height), PresentOptions = PresentOptions.RetainContents }; var pixelFormat = new PixelFormat(Format.B8G8R8A8_UNorm, AlphaMode.Ignore); var renderTargetProperties = new RenderTargetProperties( RenderTargetType.Hardware, pixelFormat, 0, 0, RenderTargetUsage.None, FeatureLevel.Level_DEFAULT); renderTarget = new WindowRenderTarget(factory, renderTargetProperties, hwndRenderTargetProperties); }
/// <summary> /// Inits the direct2D and direct write. /// </summary> private void InitDirect2DAndDirectWrite() { Factory2D = new SharpDX.Direct2D1.Factory(); FactoryDWrite = new SharpDX.DirectWrite.Factory(); var properties = new HwndRenderTargetProperties { Hwnd = panel1.Handle, PixelSize = new Size2(panel1.ClientSize.Width, panel1.ClientSize.Height), PresentOptions = PresentOptions.None }; RenderTarget2D = new WindowRenderTarget(Factory2D, new RenderTargetProperties(), properties) { AntialiasMode = AntialiasMode.PerPrimitive, TextAntialiasMode = TextAntialiasMode.Cleartype }; brush = new SolidColorBrush(RenderTarget2D, Color.Black); }
public Extruder(D2DFactory factory) { this.factory = factory; }
/// <summary> /// Update all resources /// </summary> /// <param name="backBuffer">BackBuffer</param> internal void UpdateResources(SharpDX.Direct3D11.Texture2D backBuffer) { var d2dFactory = new SharpDX.Direct2D1.Factory(); var d2dSurface = backBuffer.QueryInterface<Surface>(); _direct2DRenderTarget = new SharpDX.Direct2D1.RenderTarget(d2dFactory, d2dSurface, new SharpDX.Direct2D1.RenderTargetProperties(new SharpDX.Direct2D1.PixelFormat(Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied))); d2dSurface.Dispose(); d2dFactory.Dispose(); InitFont(); }
private void CreateAndBindTargets() { d3DSurface.SetRenderTarget( null ); Disposer.SafeDispose( ref d2DRenderTarget ); Disposer.SafeDispose( ref d2DFactory ); Disposer.SafeDispose( ref renderTarget ); var width = Math.Max((int)ActualWidth , 100); var height = Math.Max((int)ActualHeight, 100); var renderDesc = new Texture2DDescription { BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, Format = Format.B8G8R8A8_UNorm, Width = width, Height = height, MipLevels = 1, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, OptionFlags = ResourceOptionFlags.Shared, CpuAccessFlags = CpuAccessFlags.None, ArraySize = 1 }; renderTarget = new Texture2D( device, renderDesc ); var surface = renderTarget.QueryInterface<Surface>(); d2DFactory = new SharpDX.Direct2D1.Factory(); var rtp = new RenderTargetProperties(new PixelFormat(Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied)); d2DRenderTarget = new RenderTarget( d2DFactory, surface, rtp ); resCache.RenderTarget = d2DRenderTarget; d3DSurface.SetRenderTarget( renderTarget ); device.ImmediateContext.Rasterizer.SetViewport( 0, 0, width, height, 0.0f, 1.0f ); }
/// <summary> /// Inits the direct2D and direct write. /// </summary> private void InitDirect2DAndDirectWrite() { Factory2D = new SharpDX.Direct2D1.Factory(); FactoryDWrite = new SharpDX.DirectWrite.Factory(); var properties = new HwndRenderTargetProperties(); properties.Hwnd = renderControl.Handle; properties.PixelSize = new Size2(renderControl.ClientSize.Width, renderControl.ClientSize.Height); properties.PresentOptions = PresentOptions.None; RenderTarget2D = new WindowRenderTarget(Factory2D, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)), properties); RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive; RenderTarget2D.TextAntialiasMode = TextAntialiasMode.Cleartype; SceneColorBrush = new SolidColorBrush(RenderTarget2D, Color.Black); renderControl.Paint += new PaintEventHandler(renderControl_Paint); renderControl.Resize += new EventHandler(renderControl_Resize); }