Example #1
0
        void CreateRenderTarget()
        {
            var renderProp = new sd.RenderTargetProperties
            {
                DpiX     = 0,
                DpiY     = 0,
                MinLevel = sd.FeatureLevel.Level_DEFAULT,
                Type     = sd.RenderTargetType.Default,
                Usage    = sd.RenderTargetUsage.None
            };

            if (drawable != null)
            {
                renderProp.PixelFormat = new sd.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, sd.AlphaMode.Premultiplied);
                var winProp = new sd.HwndRenderTargetProperties
                {
                    Hwnd           = drawable.Control.Handle,
                    PixelSize      = drawable.ClientSize.ToDx(),
                    PresentOptions = sd.PresentOptions.Immediately
                };

                Control = new sd.WindowRenderTarget(SDFactory.D2D1Factory, renderProp, winProp);
            }
            else if (image != null)
            {
                var imageHandler = image.Handler as BitmapHandler;
                renderProp.PixelFormat = new sd.PixelFormat(SharpDX.DXGI.Format.Unknown, sd.AlphaMode.Unknown);
                Control = new sd.WicRenderTarget(SDFactory.D2D1Factory, imageHandler.Control, renderProp);
            }
        }
Example #2
0
    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);
    }
Example #3
0
        public Camera()
        {
            renderForm                   = new RenderForm("VirtualCamera");
            renderForm.ClientSize        = new Size(Width, Height);
            renderForm.AllowUserResizing = false;
            Position = new Vector3(0, 0, 0);
            Target   = new Vector3(0, 0, 9f);

            SceneCache = new byte[Width * Height * 4];

            RenderTargetProperties renderTargetProperties = new RenderTargetProperties()
            {
                Type        = SharpDX.Direct2D1.RenderTargetType.Hardware,
                PixelFormat = new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.R8G8B8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Ignore),
                DpiX        = 0,
                DpiY        = 0,
                Usage       = SharpDX.Direct2D1.RenderTargetUsage.None,
                MinLevel    = SharpDX.Direct2D1.FeatureLevel.Level_10
            };
            var hwndProperties = new SharpDX.Direct2D1.HwndRenderTargetProperties()
            {
                Hwnd           = renderForm.Handle,
                PixelSize      = new SharpDX.Size2(Width, Height),
                PresentOptions = SharpDX.Direct2D1.PresentOptions.Immediately
            };

            CameraView  = new WindowRenderTarget(new Factory(), renderTargetProperties, hwndProperties);
            SceneBuffer = new SharpDX.Direct2D1.Bitmap(CameraView, new SharpDX.Size2(Width, Height), new SharpDX.Direct2D1.BitmapProperties(CameraView.PixelFormat));

            SceneObjects = new List <Sphere>();
            Light        = new LightSource(0, 10, 20);
        }
        private void InitializeSharpDx()
        {
            this.Factory     = new SharpDX.Direct2D1.Factory();
            this.FontFactory = new SharpDX.DirectWrite.Factory();

            var renderProp = new SharpDX.Direct2D1.HwndRenderTargetProperties()
            {
                Hwnd           = this.Handle,
                PixelSize      = new SharpDX.Size2(this.Width, this.Height),
                PresentOptions = SharpDX.Direct2D1.PresentOptions.None
            };

            this.Device = new SharpDX.Direct2D1.WindowRenderTarget(
                this.Factory,
                new SharpDX.Direct2D1.RenderTargetProperties(
                    new SharpDX.Direct2D1.PixelFormat(
                        SharpDX.DXGI.Format.B8G8R8A8_UNorm,
                        SharpDX.Direct2D1.AlphaMode.Premultiplied)
                    ),
                renderProp);

            this.Device.TextAntialiasMode = SharpDX.Direct2D1.TextAntialiasMode.Cleartype;

            this.TimeTextFormat = new SharpDX.DirectWrite.TextFormat(this.FontFactory, "Arial", SharpDX.DirectWrite.FontWeight.DemiBold, SharpDX.DirectWrite.FontStyle.Normal, 21.35f);

            this.TimeBrush = new SharpDX.Direct2D1.SolidColorBrush(this.Device, new SharpDX.Color4(168 / 255.0f, 58 / 255.0f, 58 / 255.0f, 1.0f));

            this.DutyEntryBackgroundImage = ConvertBitmap(this.Device, dutynotifier.Properties.Resources.background);
        }
Example #5
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            if (_osuModel != null)
            {
                LogUtil.LogInfo("Form loads normally.");
            }
            else
            {
                LogUtil.LogError("Form loads without real-time instance.");
                return;
            }

            Paint += OnPaint;
            // Initial settings
            var pixelFormat = new D2D.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D.AlphaMode.Premultiplied);
            var winProp     = new D2D.HwndRenderTargetProperties
            {
                Hwnd           = Handle,
                PixelSize      = new DX.Size2(ClientSize.Width, ClientSize.Height),
                PresentOptions = _useVsync ? D2D.PresentOptions.None : D2D.PresentOptions.Immediately
            };
            var renderProp = new D2D.RenderTargetProperties(D2D.RenderTargetType.Hardware, pixelFormat, 96, 96,
                                                            D2D.RenderTargetUsage.ForceBitmapRemoting, D2D.FeatureLevel.Level_DEFAULT);

            RenderTarget = new D2D.WindowRenderTarget(Factory, renderProp, winProp)
            {
                AntialiasMode     = D2D.AntialiasMode.PerPrimitive,
                TextAntialiasMode = D2D.TextAntialiasMode.Grayscale,
                Transform         = new Mathe.RawMatrix3x2(1, 0, 0, 1, 0, 0)
            };

            LayerList = new List <DxLayer>
            {
                new BgDxLayer(RenderTarget, _obj, _osuModel),
                new SongInfoDxLayer(RenderTarget, _obj, _osuModel),
                new FpsDxLayer(RenderTarget, _obj, _osuModel),
                //new TestLayer(RenderTarget, _obj, _osuModel),
            };

            _renderTask = new Task[LayerList.Count];

            // Avoid artifacts
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);

            Text = "Osu!Live Player (DX)";
            LogUtil.LogInfo("Form loaded.");
        }
Example #6
0
        public RenderTarget(D2D.Factory factory, IntPtr hwnd, int width, int height)
        {
            D2D.RenderTargetProperties renderTargetProperties = new D2D.RenderTargetProperties
            {
            };

            D2D.HwndRenderTargetProperties hwndProperties = new D2D.HwndRenderTargetProperties
            {
                Hwnd           = hwnd,
                PixelSize      = new SharpDX.Size2(width, height),
                PresentOptions = D2D.PresentOptions.Immediately
            };

            _renderTarget = new D2D.WindowRenderTarget(
                factory,
                renderTargetProperties,
                hwndProperties);
        }
Example #7
0
        public RenderTarget(D2D.Factory factory,IntPtr hwnd, int width, int height)
        {

            D2D.RenderTargetProperties renderTargetProperties = new D2D.RenderTargetProperties
            {
            };

            D2D.HwndRenderTargetProperties hwndProperties = new D2D.HwndRenderTargetProperties
            {
                Hwnd = hwnd,
                PixelSize = new SharpDX.Size2(width, height),
                PresentOptions = D2D.PresentOptions.Immediately
            };

            _renderTarget = new D2D.WindowRenderTarget(
                factory,
                renderTargetProperties,
                hwndProperties);
        }
Example #8
0
        private void LoadTarget(object sender, EventArgs e)
        {
            // Initial settings
            var pixelFormat = new D2D.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D.AlphaMode.Premultiplied);
            var winProp     = new D2D.HwndRenderTargetProperties
            {
                Hwnd           = Handle,
                PixelSize      = new DX.Size2(ClientSize.Width, ClientSize.Height),
                PresentOptions = Program.MainSettings.LimitFps ? D2D.PresentOptions.None : D2D.PresentOptions.Immediately
            };
            var renderProp = new D2D.RenderTargetProperties(D2D.RenderTargetType.Default, pixelFormat, 96, 96,
                                                            D2D.RenderTargetUsage.None, D2D.FeatureLevel.Level_DEFAULT);

            RenderTarget = new D2D.WindowRenderTarget(Factory, renderProp, winProp)
            {
                AntialiasMode     = D2D.AntialiasMode.PerPrimitive,
                TextAntialiasMode = D2D.TextAntialiasMode.Grayscale,
                Transform         = new Mathe.RawMatrix3x2 {
                    M11 = 1f, M12 = 0f, M21 = 0f, M22 = 1f, M31 = 0, M32 = 0
                }
            };

            // Create colors
            _colorBack = new Mathe.RawColor4(0, 0, 0, 1);

            LayerList = new Dictionary <string, ILayer>();
            LayerList.Add("back", new Background());
            if (Program.MainSettings.UseParticle)
            {
                LayerList.Add("particle", new Particle(500));
            }
            LayerList.Add("chess", new Chessboard());

            // Create brushes
            _whiteBrush = new D2D.SolidColorBrush(RenderTarget, new Mathe.RawColor4(1, 1, 1, 1));

            // Create text formats
            _textFormat = new DW.TextFormat(FactoryWrite, "Microsoft YaHei", 12);

            // Avoid artifacts
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
        }
Example #9
0
        public HwndRenderBase(Control control)
        {
            var hwndProp = new D2D.HwndRenderTargetProperties
            {
                Hwnd           = control.Handle,
                PixelSize      = new DX.Size2(control.ClientSize.Width, control.ClientSize.Height),
                PresentOptions = Vsync ? D2D.PresentOptions.None : D2D.PresentOptions.Immediately
            };

            var pixelFormat = new D2D.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D.AlphaMode.Premultiplied);
            var renderProp  = new D2D.RenderTargetProperties(D2D.RenderTargetType.Hardware, pixelFormat, 96, 96,
                                                             D2D.RenderTargetUsage.ForceBitmapRemoting, D2D.FeatureLevel.Level_DEFAULT);

            RenderTarget = new D2D.WindowRenderTarget(Factory, renderProp, hwndProp)
            {
                AntialiasMode     = D2D.AntialiasMode.Aliased,
                TextAntialiasMode = D2D.TextAntialiasMode.Default,
                Transform         = new Mathe.RawMatrix3x2(1, 0, 0, 1, 0, 0)
            };
        }
Example #10
0
        void CreateRenderTarget()
        {
#if WINFORMS
            if (drawable != null)
            {
                var renderProp = CreateRenderProperties();
                renderProp.PixelFormat = new sd.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, sd.AlphaMode.Premultiplied);
                var winProp = new sd.HwndRenderTargetProperties
                {
                    Hwnd           = drawable.Control.Handle,
                    PixelSize      = drawable.ClientSize.ToDx(),
                    PresentOptions = sd.PresentOptions.Immediately
                };

                Control = new sd.WindowRenderTarget(SDFactory.D2D1Factory, renderProp, winProp);
                return;
            }
#endif
            CreateWicTarget();             // this is executed in winforms if not created from a drawable, and always in Xaml.
        }
Example #11
0
        private void CreateTarget(int width, int height, System.IntPtr hwnd)
        {
            RenderTarget?.Dispose();
            var hwndProp = new D2D.HwndRenderTargetProperties
            {
                Hwnd           = hwnd,
                PixelSize      = new DX.Size2(width, height),
                PresentOptions = Vsync ? D2D.PresentOptions.None : D2D.PresentOptions.Immediately
            };

            var pixelFormat = new D2D.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D.AlphaMode.Premultiplied);
            var renderProp  = new D2D.RenderTargetProperties(D2D.RenderTargetType.Hardware, pixelFormat, 96, 96,
                                                             D2D.RenderTargetUsage.ForceBitmapRemoting, D2D.FeatureLevel.Level_DEFAULT);

            RenderTarget = new D2D.WindowRenderTarget(Factory, renderProp, hwndProp)
            {
                AntialiasMode     = D2D.AntialiasMode.Aliased,
                TextAntialiasMode = D2D.TextAntialiasMode.Default,
                Transform         = new Mathe.RawMatrix3x2(1, 0, 0, 1, 0, 0)
            };
        }
Example #12
0
        private void LoadTarget(object sender, EventArgs e)
        {
            var pixelFormat = new D2D.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D.AlphaMode.Premultiplied);

            var winProp = new D2D.HwndRenderTargetProperties
            {
                Hwnd           = this.Handle,
                PixelSize      = new DX.Size2(this.ClientSize.Width, this.ClientSize.Height),
                PresentOptions = D2D.PresentOptions.Immediately
            };

            var renderProp = new D2D.RenderTargetProperties(D2D.RenderTargetType.Default, pixelFormat,
                                                            96, 96, D2D.RenderTargetUsage.None, D2D.FeatureLevel.Level_DEFAULT);

            RenderTarget = new D2D.WindowRenderTarget(Factory, renderProp, winProp)
            {
                AntialiasMode     = D2D.AntialiasMode.PerPrimitive,
                TextAntialiasMode = D2D.TextAntialiasMode.Grayscale,
                Transform         = new Mathe.RawMatrix3x2
                {
                    M11 = 1,
                    M12 = 0,
                    M21 = 0,
                    M22 = 1,
                    M31 = 0,
                    M32 = 0
                }
            };

            // Create colors
            colorBack = new Mathe.RawColor4(0, 0, 0, 1);

            // Initialize layers
            layerClock    = new Layer.Clock(this.ClientSize);
            layerParticle = new Layer.Particles(500, 200);
            layerBack     = new Layer.Background();

            // Avoid artifacts
            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
        }