public SharpDX.Direct2D1.DeviceContext1 CreateDrawingContext( Bitmap1 renderTarget, DeviceContextOptions options = DeviceContextOptions.None) { var drawingContext = new SharpDX.Direct2D1.DeviceContext1(d2dDevice, options); drawingContext.Target = renderTarget; return(drawingContext); }
void CreateRenderingResources(SharpDX.Direct3D11.Device device3d, SharpDX.Direct2D1.Factory2 d2dFactory) { device = device3d; Factory2D = d2dFactory; dxgiDevice = device.QueryInterface <SharpDX.DXGI.Device1>(); d2dDevice = new SharpDX.Direct2D1.Device1(Factory2D, dxgiDevice); d2dResourceCreationDeviceContext = new SharpDX.Direct2D1.DeviceContext1(d2dDevice, DeviceContextOptions.None); }
/// <summary> /// <p>Creates a device-dependent representation of the stroke of a geometry that can be subsequently rendered.</p> /// </summary> /// <param name="context">The device context where the created instance should be attached to.</param> /// <param name="geometry"><dd> <p>The geometry to realize.</p> </dd></param> /// <param name="flatteningTolerance"><dd> <p>The flattening tolerance to use when converting Beziers to line segments. This parameter shares the same units as the coordinates of the geometry.</p> </dd></param> /// <param name="strokeWidth"><dd> <p>The width of the stroke. This parameter shares the same units as the coordinates of the geometry.</p> </dd></param> /// <param name="strokeStyle"><dd> <p>The stroke style (optional).</p> </dd></param> /// <returns><p>The method returns an <strong><see cref="SharpDX.Result"/></strong>. Possible values include, but are not limited to, those in the following table.</p><table> <tr><th><see cref="SharpDX.Result"/></th><th>Description</th></tr> <tr><td><see cref="SharpDX.Result.Ok"/></td><td>No error occurred.</td></tr> <tr><td>E_OUTOFMEMORY</td><td>Direct2D could not allocate sufficient memory to complete the call.</td></tr> <tr><td>E_INVALIDARG</td><td>An invalid value was passed to the method.</td></tr> </table><p>?</p></returns> /// <remarks> /// <p>This method is used in conjunction with <strong><see cref="SharpDX.Direct2D1.DeviceContext1.DrawGeometryRealization"/></strong>. The <strong>D2D1::ComputeFlatteningTolerance</strong> helper API may be used to determine the proper flattening tolerance.</p><p>If the provided stroke style specifies a stroke transform type other than <strong><see cref="SharpDX.Direct2D1.StrokeTransformType.Normal"/></strong>, then the stroke will be realized assuming the identity transform and a DPI of 96.</p> /// </remarks> /// <include file='.\Documentation\CodeComments.xml' path="/comments/comment[@id='ID2D1DeviceContext1::CreateStrokedGeometryRealization']/*"/> /// <msdn-id>dn280463</msdn-id> /// <unmanaged>HRESULT ID2D1DeviceContext1::CreateStrokedGeometryRealization([In] ID2D1Geometry* geometry,[In] float flatteningTolerance,[In] float strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle,[Out, Fast] ID2D1GeometryRealization** geometryRealization)</unmanaged> /// <unmanaged-short>ID2D1DeviceContext1::CreateStrokedGeometryRealization</unmanaged-short> public GeometryRealization(DeviceContext1 context, Geometry geometry, float flatteningTolerance, float strokeWidth, StrokeStyle strokeStyle) : this(IntPtr.Zero) { context.CreateStrokedGeometryRealization(geometry, flatteningTolerance, strokeWidth, strokeStyle, this); }
/// <summary> /// <p>Creates a device-dependent representation of the fill of the geometry that can be subsequently rendered.</p> /// </summary> /// <param name="context">The device context where the created instance should be attached to.</param> /// <param name="geometry"><dd> <p>The geometry to realize.</p> </dd></param> /// <param name="flatteningTolerance"><dd> <p>The flattening tolerance to use when converting Beziers to line segments. This parameter shares the same units as the coordinates of the geometry.</p> </dd></param> /// <returns><p>The method returns an <strong><see cref="SharpDX.Result"/></strong>. Possible values include, but are not limited to, those in the following table.</p><table> <tr><th><see cref="SharpDX.Result"/></th><th>Description</th></tr> <tr><td><see cref="SharpDX.Result.Ok"/></td><td>No error occurred.</td></tr> <tr><td>E_OUTOFMEMORY</td><td>Direct2D could not allocate sufficient memory to complete the call.</td></tr> <tr><td>E_INVALIDARG</td><td>An invalid value was passed to the method.</td></tr> </table><p>?</p></returns> /// <remarks> /// <p>This method is used in conjunction with <strong><see cref="SharpDX.Direct2D1.DeviceContext1.DrawGeometryRealization"/></strong>. The <strong>D2D1::ComputeFlatteningTolerance</strong> helper API may be used to determine the proper flattening tolerance.</p><p>If the provided stroke style specifies a stroke transform type other than <strong><see cref="SharpDX.Direct2D1.StrokeTransformType.Normal"/></strong>, then the stroke will be realized assuming the identity transform and a DPI of 96.</p> /// </remarks> /// <include file='.\Documentation\CodeComments.xml' path="/comments/comment[@id='ID2D1DeviceContext1::CreateFilledGeometryRealization']/*"/> /// <msdn-id>dn280462</msdn-id> /// <unmanaged>HRESULT ID2D1DeviceContext1::CreateFilledGeometryRealization([In] ID2D1Geometry* geometry,[In] float flatteningTolerance,[Out, Fast] ID2D1GeometryRealization** geometryRealization)</unmanaged> /// <unmanaged-short>ID2D1DeviceContext1::CreateFilledGeometryRealization</unmanaged-short> public GeometryRealization(DeviceContext1 context, Geometry geometry, float flatteningTolerance) : this(IntPtr.Zero) { context.CreateFilledGeometryRealization(geometry, flatteningTolerance, this); }
void CreateRenderingResources (SharpDX.Direct3D11.Device device3d, SharpDX.Direct2D1.Factory2 d2dFactory) { device = device3d; Factory2D = d2dFactory; dxgiDevice = device.QueryInterface<SharpDX.DXGI.Device1>(); d2dDevice = new SharpDX.Direct2D1.Device1(Factory2D, dxgiDevice); d2dResourceCreationDeviceContext = new SharpDX.Direct2D1.DeviceContext1(d2dDevice, DeviceContextOptions.None); }
public SharpDX.Direct2D1.DeviceContext1 CreateDrawingContext( Bitmap1 renderTarget, DeviceContextOptions options = DeviceContextOptions.None) { var drawingContext = new SharpDX.Direct2D1.DeviceContext1(d2dDevice, options); drawingContext.Target = renderTarget; return drawingContext; }
private static void CreateDevices(int graphicsAdapter) { var deviceCreationFlags = DeviceCreationFlags.BgraSupport; #if DEBUG deviceCreationFlags |= DeviceCreationFlags.Debug; #endif Logger.Info("Attempting to create device."); var adapter = Factory.GetAdapter(graphicsAdapter); var levels = new[] { FeatureLevel.Level_11_1, FeatureLevel.Level_11_0, FeatureLevel.Level_10_1, FeatureLevel.Level_10_0, FeatureLevel.Level_9_3 }; var device = new SharpDX.Direct3D11.Device(adapter, deviceCreationFlags, levels) { DebugName = adapter.Description.Description }; Logger.Info( $"GPU{graphicsAdapter}: {device.DebugName} ({((long)adapter.Description.DedicatedVideoMemory).ToPrettySize()} VRAM)"); Device = device.QueryInterface <DeviceD3D>(); Device.DebugName = device.DebugName; Logger.Info("D3D Device created."); if (deviceCreationFlags.HasFlag(DeviceCreationFlags.Debug)) { DeviceDebug = new DeviceDebug(Device); Logger.Info("Debug device created."); } DxgiDevice = Device.QueryInterface <Device>(); Context = Device.ImmediateContext; Device2D = new DeviceD2D(Factory2D, DxgiDevice); Context2D = new ContextD2D(Device2D, DeviceContextOptions.EnableMultithreadedOptimizations) { TextAntialiasMode = RenderSettings.UseClearTypeRendering ? TextAntialiasMode.Cleartype : (RenderSettings.GuiAntiAliasing ? TextAntialiasMode.Grayscale : TextAntialiasMode.Aliased), AntialiasMode = RenderSettings.GuiAntiAliasing ? AntialiasMode.PerPrimitive : AntialiasMode.Aliased, UnitMode = UnitMode.Pixels }; Logger.Info("D2D Device created."); Logger.Info("Filling out DebugSettings GPU info."); DebugSettings.FillGpuInfo(adapter); #if DEBUG try { DeviceDebug = new DeviceDebug(Device); Logger.Info("Debug device created."); } catch (SharpDXException) { Logger.Warn("DeviceDebug not supported."); } #endif Logger.Info("Renderer initialized."); }
/// <summary> /// Initializes a new instance of the <see cref="Renderer" /> class. /// </summary> /// <param name="gameEngine">The game engine.</param> /// <param name="form">The form.</param> /// <param name="width">The primary width of the view in pixels.</param> /// <param name="height">The primary height of the view in pixels.</param> public Renderer(IGameEngine gameEngine, GameForm form, int width, int height) { if (gameEngine == null) { throw new ArgumentNullException(nameof(gameEngine)); } if (form == null) { throw new ArgumentNullException(nameof(form)); } _form = form; _resize = false; _scale = 1.0f; _width = width; _height = height; _dwFactory = new SharpDX.DirectWrite.Factory(); InitFonts(); // DeviceCreationFlags.BgraSupport must be enabled to allow Direct2D interop. SharpDX.Direct3D11.Device defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport); // Query the default device for the supported device and context interfaces. _device = defaultDevice.QueryInterface <SharpDX.Direct3D11.Device1>(); _d3dContext = _device.ImmediateContext.QueryInterface <SharpDX.Direct3D11.DeviceContext1>(); // Query for the adapter and more advanced DXGI objects. using (var dxgiDevice2 = _device.QueryInterface <SharpDX.DXGI.Device2>()) { _d2dFactory = new SharpDX.Direct2D1.Factory2(SharpDX.Direct2D1.FactoryType.SingleThreaded); // Get the default Direct2D device and create a context. using (var d2dDevice = new SharpDX.Direct2D1.Device1(_d2dFactory, dxgiDevice2)) { _d2dContext = new SharpDX.Direct2D1.DeviceContext1(d2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None); } } CreateSizeDependentResources(); _d2dContext.TextAntialiasMode = SharpDX.Direct2D1.TextAntialiasMode.Aliased; _d2dContext.AntialiasMode = AntialiasMode.Aliased; _d2dContext.UnitMode = UnitMode.Pixels; _hudYellow = new SolidColorBrush(_d2dContext, new Color4(1.0f, 1.0f, 0.0f, 1.0f)); _hudWhite = new SolidColorBrush(_d2dContext, new Color4(1.0f, 1.0f, 1.0f, 1.0f)); _hudTextFormat = new TextFormat(_dwFactory, "Sonic Genesis/Mega Drive Font", _fontCollection, FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 14); // init game stuff _game = gameEngine; _texResMan = new TextureResourceManager(gameEngine, _d2dContext); _spriteResMan = new SpriteResourceManager(gameEngine, _d2dContext); // get the services _mapService = _game.GetService <IMapService>(); _varService = _game.GetService <IVariableService>(); _entityService = _game.GetService <IEntityService>(); _renderService = _game.GetService <IRenderService>(); _collisionService = _game.GetService <ICollisionService>(); _varShowCollisionMaps = _varService.GetVar <bool>("r_showcollisionmaps"); _varShowTileFrames = _varService.GetVar <bool>("r_showtileframes"); _varShowEntityOrigins = _varService.GetVar <bool>("r_showentityorigins"); _varShowTraceLines = _varService.GetVar <bool>("r_showtracelines"); _varShowCollisionBoxes = _varService.GetVar <bool>("r_showcollisionboxes"); _rc = new RenderContext(); _spriteRenderList = new List <Animatable>(25); }