Exemple #1
0
        /// <summary>
        /// Creates a default D3D11 Texture with forced Shared-Flag
        /// </summary>
        /// <param name="device"></param>
        /// <param name="description"></param>
        /// <param name="D3D10Dev"> </param>
        /// <param name="D2DFactory"> </param>
        public SharedTexture(D2DInteropHandler handler, Texture2DDescription description)
        {
            As11Tex = new Texture2D(handler.D3DDevice11, new Texture2DDescription()
                {
                    ArraySize = description.ArraySize,
                    BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
                    CpuAccessFlags = description.CpuAccessFlags,
                    Format = description.Format,
                    Height = description.Height,
                    MipLevels = description.MipLevels,
                    OptionFlags = ResourceOptionFlags.KeyedMutex,
                    SampleDescription = description.SampleDescription,
                    Usage = description.Usage,
                    Width = description.Width
                });

            Mutex11 = new KeyedMutex(As11Tex);
            AsResource = new SlimDX.DXGI.Resource(As11Tex);

            As10Tex = handler.D3DDevice10.OpenSharedResource<SlimDX.Direct3D10.Texture2D>(AsResource.SharedHandle);
            Mutex10 = new KeyedMutex(As10Tex);
            AsSurface = As10Tex.AsSurface();
            As2DTarget = SlimDX.Direct2D.RenderTarget.FromDXGI(handler.D2DFactory, AsSurface, new RenderTargetProperties()
                                                                                                            {
                                                                                                                MinimumFeatureLevel = FeatureLevel.Direct3D10,
                                                                                                                Usage = RenderTargetUsage.None,
                                                                                                                Type = RenderTargetType.Hardware,
                                                                                                                PixelFormat = new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)
                                                                                                            });
        }
Exemple #2
0
        public void Draw(D2D.RenderTarget target, float fontSize, string text, PointF point, DW.TextAlignment alignment,
                         D2D.SolidColorBrush fillBrush, D2D.SolidColorBrush edgeBrush, float edgeWidth)
        {
            D2D.Geometry geometry = CreateGeometry(fontSize, text);

            switch (alignment)
            {
            case DW.TextAlignment.Leading:
                target.Transform = Matrix3x2.Translation(point);
                break;

            case DW.TextAlignment.Center:
            {
                RectangleF bounds = D2D.Geometry.GetBounds(geometry);
                target.Transform = Matrix3x2.Translation(point.X - bounds.Width / 2f, point.Y);
            }
            break;

            case DW.TextAlignment.Trailing:
            {
                RectangleF bounds = D2D.Geometry.GetBounds(geometry);
                target.Transform = Matrix3x2.Translation(point.X - bounds.Width, point.Y);
            }
            break;
            }

            target.DrawGeometry(geometry, edgeBrush, edgeWidth);
            target.FillGeometry(geometry, fillBrush);
        }
        /// <summary>
        ///     レンダーターゲットを初期化します.
        /// </summary>
        private void InitializeTargets()
        {
            {
                // Direct3D レンダーターゲットの作成
                var desc = new D3D.Texture2DDescription
                {
                    Width             = size.Width,
                    Height            = size.Height,
                    MipLevels         = 1,
                    ArraySize         = 1,
                    Format            = Format.B8G8R8A8_UNorm,
                    SampleDescription = new SampleDescription(1, 0),
                    Usage             = D3D.ResourceUsage.Default,
                    BindFlags         = D3D.BindFlags.RenderTarget,
                    CpuAccessFlags    = D3D.CpuAccessFlags.None,
                    OptionFlags       = D3D.ResourceOptionFlags.GdiCompatible
                };
                d3dRenderTarget = new D3D.Texture2D(deviceManager.Device, desc);
            }
            {
                // レンダーターゲットビューの作成
                D3D.Texture2D target = D3DRenderTarget;
                var           desc   = new D3D.RenderTargetViewDescription
                {
                    Format    = target.Description.Format,
                    Dimension =
                        target.Description.SampleDescription.Count > 1
                            ? D3D.RenderTargetViewDimension.Texture2DMultisampled
                            : D3D.RenderTargetViewDimension.Texture2D,
                    MipSlice = 0
                };
                d3dRenderTargetView = new D3D.RenderTargetView(deviceManager.Device, target, desc);
            }
            // DXGIサーフェスの取得
            dxgiSurface = d3dRenderTarget.AsSurface();
            {
                // レンダーターゲットの作成
                var properties = new D2D.RenderTargetProperties
                {
                    Type                = D2D.RenderTargetType.Default,
                    PixelFormat         = new D2D.PixelFormat(dxgiSurface.Description.Format, D2D.AlphaMode.Premultiplied),
                    HorizontalDpi       = 0,
                    VerticalDpi         = 0,
                    Usage               = D2D.RenderTargetUsage.GdiCompatible,
                    MinimumFeatureLevel = D2D.FeatureLevel.Direct3D10
                };
                d2dRenderTarget           = D2D.RenderTarget.FromDXGI(deviceManager.D2DFactory, dxgiSurface, properties);
                d2dGdiInteropRenderTarget = new D2D.GdiInteropRenderTarget(d2dRenderTarget);
            }

            if (TargetsInitialized != null)
            {
                TargetsInitialized(this, new EventArgs());
            }
        }
        /// <summary>
        ///     レンダーターゲットを破棄します.
        /// </summary>
        private void DestroyTargets()
        {
            if (DXGISurface != null && TargetsDestroying != null)
            {
                TargetsDestroying(this, new EventArgs());
            }

            SafeRelease(d2dGdiInteropRenderTarget);
            SafeRelease(d2dRenderTarget);
            SafeRelease(dxgiSurface);
            SafeRelease(d3dRenderTargetView);
            SafeRelease(d3dRenderTarget);

            d2dGdiInteropRenderTarget = null;
            d2dRenderTarget           = null;
            dxgiSurface         = null;
            d3dRenderTargetView = null;
            d3dRenderTarget     = null;
        }
Exemple #5
0
        /// <summary>
        ///     描画処理
        /// </summary>
        public void Render(IDemeanor demeanor)
        {
            // ワールドを更新
            _renderContext.UpdateWorlds();

            if (IsVisible)
            {
                // 描画前の処理を行います.
                RectangleF regionInWorld;
                demeanor.PreRender(out regionInWorld);
                var workingArea =
                    Screen.FromPoint(new Point((int)(regionInWorld.X * _globalConfig.PixelPerUnitLength), 0)).WorkingArea;
                var regionInScreen = WorldToScreen(regionInWorld, workingArea);
                // ウィンドウの位置
                var windowPos  = new Point((int)regionInScreen.X, (int)regionInScreen.Y);
                var windowSize = new Size(
                    (int)Math.Ceiling(regionInScreen.Right) - windowPos.X,
                    (int)Math.Ceiling(regionInScreen.Bottom) - windowPos.Y);
                if (Size != windowSize)
                {
                    //int deltaWidth = Size.Width - windowSize.Width;
                    //int deltaHeight = Size.Height - windowSize.Height;
                    //if (deltaWidth < -10 || deltaWidth > 0
                    //    || deltaHeight < -10 || deltaHeight > 0)
                    {
                        Size = windowSize;
                        _textureTargetContext.MatrixManager.ProjectionMatrixManager.InitializeProjection(
                            windowSize.Width / _globalConfig.PixelPerUnitLength,
                            windowSize.Height / _globalConfig.PixelPerUnitLength, 1, 2000);
                    }
                    // else
                    // {
                    //     windowSize = Size;
                    // }
                }
                // カメラ位置
                var cameraInScreen = new PointF(
                    windowPos.X + windowSize.Width / 2.0f,
                    windowPos.Y + windowSize.Height / 2.0f);
                var cameraInWorld = ScreenToWorld(cameraInScreen, workingArea);
                // レンダーターゲットサイズ・カメラ位置を設定
                Position = windowPos;
                _textureTargetContext.MatrixManager.ViewMatrixManager.CameraPosition
                    = new Vector3(cameraInWorld.X, cameraInWorld.Y, -1000);
                _textureTargetContext.MatrixManager.ViewMatrixManager.CameraLookAt
                    = new Vector3(cameraInWorld.X, cameraInWorld.Y, 0);

                // 描画
                _textureTargetContext.Render();

                // バルーン基準点(描画した後)
                BaloonReferencePoint = WorldToScreen(demeanor.BaloonReferencePoint, workingArea);

                // 描画内容をGDI互換コンテクストにコピー
                D2D.RenderTarget target = _gdiContext.D2DRenderTarget;
                target.BeginDraw();
                if (_textureTargetContext.SampleDesc.Count > 1)
                {
                    _gdiContext.DeviceManager.Context.ResolveSubresource(
                        _textureTargetContext.RenderTarget, 0,
                        _gdiContext.D3DRenderTarget, 0,
                        _gdiContext.D3DRenderTarget.Description.Format);
                }
                else
                {
                    _gdiContext.DeviceManager.Context.CopyResource(
                        _textureTargetContext.RenderTarget, _gdiContext.D3DRenderTarget);
                }

#if DEBUG
                // Direct2Dの描画
                target.DrawText(string.Format("{0:0.0}FPS", App.Current.Renderer.FpsCounter.FPS), _textFormat,
                                new Rectangle(0, 0, Size.Width, (int)(_textFormat.FontSize + 1)), _textBrush);
#endif

                // ウィンドウに表示
                using (var dc = new RenderTargetDC(_gdiContext.D2DGdiInteropRenderTarget))
                    UpdateLayeredWindow(dc);
                target.EndDraw();
            }

            if (Rendered != null)
            {
                Rendered(this, new EventArgs());
            }
        }
        protected override void OnRender(RenderTarget renderTarget)
        {
            fillBrush = renderManager.GetSolidColorBrush(FillColor, Opacity);
            lineBrush = renderManager.GetSolidColorBrush(LineColor, Opacity);

            if (Shape == ShapeType.Ellipse)
            {
                ellipse.Center = new PointF(transformComponent.X, transformComponent.Y);
                ellipse.RadiusX = transformComponent.Width / 2.0f;
                ellipse.RadiusY = transformComponent.Height / 2.0f;

                renderTarget.FillEllipse(fillBrush, ellipse);
                renderTarget.DrawEllipse(lineBrush, ellipse, LineThickness);
            }
            else if (Shape == ShapeType.Rectangle)
            {
                rectangle.X = transformComponent.X - transformComponent.Width / 2.0f;
                rectangle.Y = transformComponent.Y - transformComponent.Height / 2.0f;
                rectangle.Width = transformComponent.Width;
                rectangle.Height = transformComponent.Height;

                renderTarget.FillRectangle(fillBrush, rectangle);
                renderTarget.DrawRectangle(lineBrush, rectangle, LineThickness);
            }
        }
        protected override void OnRender(RenderTarget renderTarget)
        {
            layoutRectangle.X = transformComponent.X;
            layoutRectangle.Y = transformComponent.Y;
            layoutRectangle.Width = transformComponent.Width;
            layoutRectangle.Height = transformComponent.Height;

            renderTarget.DrawText(Value, textFormat, layoutRectangle, brush);
        }