Beispiel #1
0
 internal CommandConsole(LuaEnvironment lua, DrawingSizeF screenSize, GameApplication.OutputStreams streams, int maxLines = 500)
 {
     Debug.Assert(lua != null, "Lua environment can not be null");
     Debug.Assert(streams != null, "Streams can not be null");
     _streams = streams;
     _lua = lua;
     _outputView = ToDispose<OutputView>(new OutputView(screenSize));
     _inputView = ToDispose<InputView>(new InputView(_outputView));
 }
Beispiel #2
0
 public override void PrepareResources(DateTime presentTargetTime, ref DrawingSizeF desiredRenderTargetSize)
 {
     WindowsPhoneGameWindow.Width  = desiredRenderTargetSize.Width;
     WindowsPhoneGameWindow.Height = desiredRenderTargetSize.Height;
 }
        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.");
        }
Beispiel #4
0
 public override void PrepareResources(DateTime presentTargetTime, ref DrawingSizeF desiredRenderTargetSize)
 {
 }
Beispiel #5
0
        internal void GetTexture(DrawingSizeF surfaceSize, DrawingSurfaceSynchronizedTexture synchronizedTexture, RectangleF textureSubRectangle)
        {
            _timer.Update();
            _renderer.Update(_timer.Total, _timer.Delta);
            _renderer.Render();

            if (RequestAdditionalFrame!=null) RequestAdditionalFrame();

        }
 public abstract void PrepareResources(DateTime presentTargetTime, DrawingSizeF desiredRenderTargetSize);
 /// <summary>	
 ///  Creates a bitmap render target for use during intermediate offscreen drawing that is compatible with the current render target.	
 /// </summary>	
 /// <remarks>	
 /// The pixel size and DPI of the new render target can be altered by specifying values for desiredSize or desiredPixelSize:  If desiredSize is specified but desiredPixelSize is not, the pixel size is computed from the desired size using the parent target DPI. If the desiredSize maps to a integer-pixel size, the DPI of the compatible render target is the same as the DPI of the parent target.  If desiredSize maps to a fractional-pixel size, the pixel size is rounded up to the nearest integer and the DPI for the compatible render target is slightly higher than the DPI of the parent render target. In all cases, the coordinate (desiredSize.width, desiredSize.height) maps to the lower-right corner of the compatible render target.If the desiredPixelSize is specified and desiredSize is not, the DPI of the new render target is the same as the original render target.If both desiredSize and desiredPixelSize are specified, the DPI of the new render target is computed to account for the difference in scale.If neither desiredSize nor desiredPixelSize is specified, the new render target size and DPI match the original render target. 	
 /// </remarks>	
 /// <param name="renderTarget">an instance of <see cref = "SharpDX.Direct2D1.RenderTarget" /></param>
 /// <param name="desiredSize">The desired size of the new render target in device-independent pixels if it should be different from the original render target. For more information, see the Remarks section.</param>
 /// <param name="desiredPixelSize">The desired size of the new render target in pixels if it should be different from the original render target. For more information, see the Remarks section.</param>
 /// <param name="desiredFormat">The desired pixel format and alpha mode of the new render target. If the pixel format is set to DXGI_FORMAT_UNKNOWN, the new render target uses the same pixel format as the original render target. If the alpha mode is <see cref="SharpDX.Direct2D1.AlphaMode.Unknown"/>, the alpha mode of the new render target defaults to D2D1_ALPHA_MODE_PREMULTIPLIED. For information about supported pixel formats, see  {{Supported Pixel  Formats and Alpha Modes}}.</param>
 /// <param name="options">A value that specifies whether the new render target must be compatible with GDI.</param>
 /// <unmanaged>HRESULT CreateCompatibleRenderTarget([In, Optional] const D2D1_SIZE_F* desiredSize,[In, Optional] const D2D1_SIZE_U* desiredPixelSize,[In, Optional] const D2D1_PIXEL_FORMAT* desiredFormat,[None] D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS options,[Out] ID2D1BitmapRenderTarget** bitmapRenderTarget)</unmanaged>
 public BitmapRenderTarget(RenderTarget renderTarget, SharpDX.Direct2D1.CompatibleRenderTargetOptions options, DrawingSizeF? desiredSize, DrawingSize? desiredPixelSize, SharpDX.Direct2D1.PixelFormat? desiredFormat) : base(IntPtr.Zero)
 {
     renderTarget.CreateCompatibleRenderTarget(desiredSize, desiredPixelSize, desiredFormat, options, this);
 }
 void IDrawingSurfaceBackgroundContentProviderNative.PrepareResources(DateTime presentTargetTime, DrawingSizeF desiredRenderTargetSize)
 {
     
 }
Beispiel #9
0
        private static D2D.PathGeometry GetBorderFillGeometry(
            CompositionEngine compositionEngine, Border border, RectangleF rect)
        {
            var topLeftCornerSize = new DrawingSizeF(
                (float)border.CornerRadius.TopLeft,
                (float)border.CornerRadius.TopLeft);
            var topRightCornerSize = new DrawingSizeF(
                (float)border.CornerRadius.TopRight,
                (float)border.CornerRadius.TopRight);
            var bottomLeftCornerSize = new DrawingSizeF(
                (float)border.CornerRadius.BottomLeft,
                (float)border.CornerRadius.BottomLeft);
            var bottomRightCornerSize = new DrawingSizeF(
                (float)border.CornerRadius.BottomRight,
                (float)border.CornerRadius.BottomRight);

            var topCornersWidth = topLeftCornerSize.Width + topRightCornerSize.Width;

            if (topCornersWidth > rect.Width)
            {
                var scale = rect.Width / topCornersWidth;
                topLeftCornerSize.Width  *= scale;
                topRightCornerSize.Width *= scale;
            }

            var bottomCornersWidth = bottomLeftCornerSize.Width + bottomRightCornerSize.Width;

            if (bottomCornersWidth > rect.Width)
            {
                var scale = rect.Width / bottomCornersWidth;
                bottomLeftCornerSize.Width  *= scale;
                bottomRightCornerSize.Width *= scale;
            }

            var leftCornersHeight = topLeftCornerSize.Height + bottomLeftCornerSize.Height;

            if (leftCornersHeight > rect.Height)
            {
                var scale = rect.Height / leftCornersHeight;
                topLeftCornerSize.Height    *= scale;
                bottomLeftCornerSize.Height *= scale;
            }

            var rightCornersHeight = topRightCornerSize.Height + bottomRightCornerSize.Height;

            if (rightCornersHeight > rect.Height)
            {
                var scale = rect.Height / rightCornersHeight;
                topRightCornerSize.Height    *= scale;
                bottomRightCornerSize.Height *= scale;
            }

            var geometry = new D2D.PathGeometry(compositionEngine.D2DFactory);

            // Create the geometry of the irregular rounded rectangle.
            var geometrySink = geometry.Open();

            // Start to the right of the topleft corner.
            geometrySink.BeginFigure(
                new DrawingPointF(
                    rect.Left + topLeftCornerSize.Width,
                    rect.Top + 0),
                D2D.FigureBegin.Filled);

            //if (topCornersWidth < rect.Width)
            {
                // Top edge
                geometrySink.AddLine(
                    new DrawingPointF(
                        rect.Left + rect.Width - topRightCornerSize.Width,
                        rect.Top + 0));
            }

            //if (topRightCornerSize.Width > 0)

            // Top-right corner
            geometrySink.AddArc(
                new D2D.ArcSegment
            {
                Point = new DrawingPointF(
                    rect.Left + rect.Width,
                    rect.Top + topRightCornerSize.Height),
                Size           = topRightCornerSize,
                RotationAngle  = 0,
                SweepDirection = D2D.SweepDirection.Clockwise,
                ArcSize        = D2D.ArcSize.Small
            });

            // Right edge
            geometrySink.AddLine(
                new DrawingPointF(
                    rect.Left + rect.Width,
                    rect.Top + rect.Height - bottomRightCornerSize.Height));

            // Bottom-right corner
            geometrySink.AddArc(
                new D2D.ArcSegment
            {
                Point = new DrawingPointF(
                    rect.Left + rect.Width - bottomRightCornerSize.Width,
                    rect.Top + rect.Height),
                Size           = bottomRightCornerSize,
                RotationAngle  = 0,
                SweepDirection = D2D.SweepDirection.Clockwise,
                ArcSize        = D2D.ArcSize.Small
            });

            // Bottom edge
            geometrySink.AddLine(
                new DrawingPointF(
                    rect.Left + bottomLeftCornerSize.Width,
                    rect.Top + rect.Height));

            // Bottom-left corner
            geometrySink.AddArc(
                new D2D.ArcSegment
            {
                Point = new DrawingPointF(
                    rect.Left + 0,
                    rect.Top + rect.Height - bottomLeftCornerSize.Height),
                Size           = bottomLeftCornerSize,
                RotationAngle  = 0,
                SweepDirection = D2D.SweepDirection.Clockwise,
                ArcSize        = D2D.ArcSize.Small
            });

            // Left edge
            geometrySink.AddLine(
                new DrawingPointF(
                    rect.Left + 0,
                    rect.Top + topLeftCornerSize.Height));

            // Top-left corner
            geometrySink.AddArc(
                new D2D.ArcSegment
            {
                Point = new DrawingPointF(
                    rect.Left + topLeftCornerSize.Width,
                    rect.Top + 0),
                Size           = topLeftCornerSize,
                RotationAngle  = 0,
                SweepDirection = D2D.SweepDirection.Clockwise,
                ArcSize        = D2D.ArcSize.Small
            });

            geometrySink.EndFigure(D2D.FigureEnd.Closed);
            geometrySink.Close();
            return(geometry);
        }
Beispiel #10
0
 /// <summary>
 /// Creates a new D2dBitmapGraphics with specified DIP size for use during intermediate offscreen drawing
 /// that is compatible with the current D2dGraphics and has the same DPI, and pixel format
 /// as the current D2dGraphics and with the specified options</summary>        
 /// <param name="size">The desired size of the new D2dGraphics in pixels</param>
 /// <param name="options">Whether the new D2dBitmapGraphics must be compatible with GDI</param>        
 public D2dBitmapGraphics CreateCompatibleGraphics(SizeF size, D2dCompatibleGraphicsOptions options)
 {
     var dsize = new DrawingSizeF(size.Width, size.Height);
     var rt = new BitmapRenderTarget(m_renderTarget, (CompatibleRenderTargetOptions)options, dsize, null, null);
     return new D2dBitmapGraphics(rt);
 }
 public OutputView(DrawingSizeF bounds)
 {
     Bounds = bounds;
     OutputRectangle.Right = Bounds.Width;
 }
        void IDrawingSurfaceContentProviderNative.GetTexture(DrawingSizeF surfaceSize, out DrawingSurfaceSynchronizedTexture synchronizedTexture, out RectangleF textureSubRectangle)
        {
            try
            {
                if (!Exiting)
                {
                    if (GraphicsDevice == null)
                    {
                        GraphicsDevice = GraphicsDevice.New();

                        var renderTargetDesc = new Texture2DDescription
                                               {
                                                   Format = DXGI.Format.B8G8R8A8_UNorm,
                                                   Width = (int)surfaceSize.Width,
                                                   Height = (int)surfaceSize.Height,
                                                   ArraySize = 1,
                                                   MipLevels = 1,
                                                   BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
                                                   Usage = ResourceUsage.Default,
                                                   CpuAccessFlags = CpuAccessFlags.None,
                                                   OptionFlags = ResourceOptionFlags.SharedKeyedmutex | ResourceOptionFlags.SharedNthandle,
                                                   SampleDescription = new DXGI.SampleDescription(1, 0)
                                               };

                        renderTarget = ToDispose(Graphics.Texture2D.New(GraphicsDevice, renderTargetDesc));
                        BackBuffer = ToDispose(RenderTarget2D.New(GraphicsDevice, new RenderTargetView(GraphicsDevice, renderTarget)));

                        graphicsPresenter = new RenderTargetGraphicsPresenter(GraphicsDevice, BackBuffer);
                        GraphicsDevice.Presenter = graphicsPresenter;
                        InitCallback();
                    }

                    if(this.synchronizedTexture == null)
                        this.synchronizedTexture = host.CreateSynchronizedTexture((Texture2D)renderTarget);

                    this.synchronizedTexture.BeginDraw();

                    RunCallback();

                    host.RequestAdditionalFrame();

                    this.synchronizedTexture.EndDraw();
                }
            }
            catch (Exception ex)
            {
                // TODO: As we are in a callback from a native code, we cannot pass back this exception,
                // so how to pass back this exception to the user at an appropriate time?
                drawException = ex;
                Debug.WriteLine(drawException);
            }

            // Set output parameters.
            textureSubRectangle = new RectangleF(0f, 0f, surfaceSize.Width, surfaceSize.Height);
            synchronizedTexture = this.synchronizedTexture;
        }
Beispiel #13
0
        public static DrawingSizeF ToSizeF(this Size size)
        {
            DrawingSizeF result = new DrawingSizeF { Width = size.Width, Height = size.Height };

            return result;
        }
 public abstract void GetTexture(DrawingSizeF surfaceSize, out DrawingSurfaceSynchronizedTexture synchronizedTexture, out RectangleF textureSubRectangle);
 /// <summary>	
 ///  Creates a bitmap render target for use during intermediate offscreen drawing that is compatible with the current render target with same pixel size and pixel format.
 /// </summary>	
 /// <param name="renderTarget">an instance of <see cref = "SharpDX.Direct2D1.RenderTarget" /></param>
 /// <param name="options">A value that specifies whether the new render target must be compatible with GDI.</param>
 /// <param name="desiredSize">The desired size of the new render target in device-independent pixels if it should be different from the original render target. For more information, see the Remarks section.</param>
 /// <unmanaged>HRESULT CreateCompatibleRenderTarget([In, Optional] const D2D1_SIZE_F* desiredSize,[In, Optional] const D2D1_SIZE_U* desiredPixelSize,[In, Optional] const D2D1_PIXEL_FORMAT* desiredFormat,[None] D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS options,[Out] ID2D1BitmapRenderTarget** bitmapRenderTarget)</unmanaged>
 public BitmapRenderTarget(RenderTarget renderTarget, SharpDX.Direct2D1.CompatibleRenderTargetOptions options, DrawingSizeF desiredSize)
     : this(renderTarget, options, desiredSize, null, null)
 {
 }
Beispiel #16
0
 /// <summary>	
 /// Creates a layer resource that can be used with this render target and its compatible render targets. The new layer has the specified initial size.  	
 /// </summary>	
 /// <remarks>	
 /// Regardless of whether a size is initially specified, the layer automatically resizes as needed.	
 /// </remarks>	
 /// <param name="renderTarget">an instance of <see cref = "SharpDX.Direct2D1.RenderTarget" /></param>
 /// <param name="size">If (0, 0) is specified, no backing store is created behind the layer resource. The layer resource is allocated to the minimum size when {{PushLayer}} is called.</param>
 /// <unmanaged>HRESULT CreateLayer([In, Optional] const D2D1_SIZE_F* size,[Out] ID2D1Layer** layer)</unmanaged>
 public Layer(RenderTarget renderTarget, DrawingSizeF? size) : base(IntPtr.Zero)
 {
     renderTarget.CreateLayer(size, this);
 }
        private static D2D.PathGeometry GetBorderFillGeometry(
            CompositionEngine compositionEngine, Border border, RectangleF rect)
        {
            var topLeftCornerSize = new DrawingSizeF(
                (float)border.CornerRadius.TopLeft,
                (float)border.CornerRadius.TopLeft);
            var topRightCornerSize = new DrawingSizeF(
                (float)border.CornerRadius.TopRight,
                (float)border.CornerRadius.TopRight);
            var bottomLeftCornerSize = new DrawingSizeF(
                (float)border.CornerRadius.BottomLeft,
                (float)border.CornerRadius.BottomLeft);
            var bottomRightCornerSize = new DrawingSizeF(
                (float)border.CornerRadius.BottomRight,
                (float)border.CornerRadius.BottomRight);

            var topCornersWidth = topLeftCornerSize.Width + topRightCornerSize.Width;

            if (topCornersWidth > rect.Width)
            {
                var scale = rect.Width / topCornersWidth;
                topLeftCornerSize.Width *= scale;
                topRightCornerSize.Width *= scale;
            }

            var bottomCornersWidth = bottomLeftCornerSize.Width + bottomRightCornerSize.Width;

            if (bottomCornersWidth > rect.Width)
            {
                var scale = rect.Width / bottomCornersWidth;
                bottomLeftCornerSize.Width *= scale;
                bottomRightCornerSize.Width *= scale;
            }

            var leftCornersHeight = topLeftCornerSize.Height + bottomLeftCornerSize.Height;

            if (leftCornersHeight > rect.Height)
            {
                var scale = rect.Height / leftCornersHeight;
                topLeftCornerSize.Height *= scale;
                bottomLeftCornerSize.Height *= scale;
            }

            var rightCornersHeight = topRightCornerSize.Height + bottomRightCornerSize.Height;

            if (rightCornersHeight > rect.Height)
            {
                var scale = rect.Height / rightCornersHeight;
                topRightCornerSize.Height *= scale;
                bottomRightCornerSize.Height *= scale;
            }

            var geometry = new D2D.PathGeometry(compositionEngine.D2DFactory);

            // Create the geometry of the irregular rounded rectangle.
            var geometrySink = geometry.Open();

            // Start to the right of the topleft corner.
            geometrySink.BeginFigure(
                new DrawingPointF(
                    rect.Left + topLeftCornerSize.Width,
                    rect.Top + 0),
                D2D.FigureBegin.Filled);

            //if (topCornersWidth < rect.Width)
            {
                // Top edge
                geometrySink.AddLine(
                    new DrawingPointF(
                        rect.Left + rect.Width - topRightCornerSize.Width,
                        rect.Top + 0));
            }

            //if (topRightCornerSize.Width > 0)

            // Top-right corner
            geometrySink.AddArc(
                new D2D.ArcSegment
                {
                    Point = new DrawingPointF(
                        rect.Left + rect.Width,
                        rect.Top + topRightCornerSize.Height),
                    Size = topRightCornerSize,
                    RotationAngle = 0,
                    SweepDirection = D2D.SweepDirection.Clockwise,
                    ArcSize = D2D.ArcSize.Small
                });

            // Right edge
            geometrySink.AddLine(
                new DrawingPointF(
                    rect.Left + rect.Width,
                    rect.Top + rect.Height - bottomRightCornerSize.Height));

            // Bottom-right corner
            geometrySink.AddArc(
                new D2D.ArcSegment
                {
                    Point = new DrawingPointF(
                        rect.Left + rect.Width - bottomRightCornerSize.Width,
                        rect.Top + rect.Height),
                    Size = bottomRightCornerSize,
                    RotationAngle = 0,
                    SweepDirection = D2D.SweepDirection.Clockwise,
                    ArcSize = D2D.ArcSize.Small
                });

            // Bottom edge
            geometrySink.AddLine(
                new DrawingPointF(
                    rect.Left + bottomLeftCornerSize.Width,
                    rect.Top + rect.Height));

            // Bottom-left corner
            geometrySink.AddArc(
                new D2D.ArcSegment
                {
                    Point = new DrawingPointF(
                        rect.Left + 0,
                        rect.Top + rect.Height - bottomLeftCornerSize.Height),
                    Size = bottomLeftCornerSize,
                    RotationAngle = 0,
                    SweepDirection = D2D.SweepDirection.Clockwise,
                    ArcSize = D2D.ArcSize.Small
                });

            // Left edge
            geometrySink.AddLine(
                new DrawingPointF(
                    rect.Left + 0,
                    rect.Top + topLeftCornerSize.Height));

            // Top-left corner
            geometrySink.AddArc(
                new D2D.ArcSegment
                {
                    Point = new DrawingPointF(
                        rect.Left + topLeftCornerSize.Width,
                        rect.Top + 0),
                    Size = topLeftCornerSize,
                    RotationAngle = 0,
                    SweepDirection = D2D.SweepDirection.Clockwise,
                    ArcSize = D2D.ArcSize.Small
                });

            geometrySink.EndFigure(D2D.FigureEnd.Closed);
            geometrySink.Close();
            return geometry;
        }