Beispiel #1
0
        /**
            Create a drawing target from an already existing RenderTarget.

            Note that the RenderTarget must use the the same Factory the
            drawing backend does.
        **/
        public IDrawingTarget CreateDrawingTarget(RenderTarget renderTarget)
        {
            var width = renderTarget.Size.Width;
            var height = renderTarget.Size.Height;

            var state = new DrawingState();
            var transform = new DrawingTransform();
            var drawingTarget = new DrawingTarget(state, transform, renderTarget, (int)Math.Floor(width), (int)Math.Floor(height));

            var target = new DrawingTargetSplitter(
                this,
                state,
                transform,
                drawingTarget,
                drawingTarget,
                drawingTarget,
                drawingTarget,
                drawingTarget,
                () =>
                {
                    drawingTarget.Dispose();
                });

            var pixelAligner = PixelAligningDrawingTarget.Create(target, target.Dispose, state, transform);
            return pixelAligner;
        }
Beispiel #2
0
        public IDrawingTarget BeginDraw(Color? clearColor)
        {
            #if NETFX_CORE
            var surface = _texture.QueryInterface<Surface>();
            #else
            var surface = _texture.AsSurface();
            #endif

            var rtProperties = new RenderTargetProperties
            {
                DpiX = 96,
                DpiY = 96,
                Type = RenderTargetType.Default,
                PixelFormat = new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)
            };

            var renderTarget = new RenderTarget(_factory, surface, rtProperties);

            renderTarget.BeginDraw();
            // required to clear the render target
            // not required on all machines, seems to be a driver decision.
            renderTarget.Clear(clearColor != null ? clearColor.Value.import() : (Color4?)null);

            var state = new DrawingState();
            var transform = new DrawingTransform();
            var drawingTarget = new DrawingTarget(state, transform, renderTarget, _width, _height);

            var target = new DrawingTargetSplitter(
                _backend,
                state,
                transform,
                drawingTarget,
                drawingTarget,
                drawingTarget,
                drawingTarget,
                drawingTarget,
                () =>
                    {
                        drawingTarget.Dispose();

                        renderTarget.EndDraw();
                        renderTarget.Dispose();
                        surface.Dispose();
                    });

            var pixelAligner = PixelAligningDrawingTarget.Create(target, target.Dispose, state, transform);
            return pixelAligner;
        }