Пример #1
0
        public static FontWrapper GetWrapper(DX11RenderContext context, SlimDX.DirectWrite.Factory dwFactory)
        {
            if (fontWrapper == null)
            {
                FontWrapperCreationParameters p = new FontWrapperCreationParameters()
                {
                    SheetMipLevels       = 5,
                    AnisotropicFiltering = 1,
                    DefaultFontParams    = new DirectWriteFontParameters()
                    {
                        FontFamily  = "Arial",
                        FontStretch = SharpDX.DirectWrite.FontStretch.Normal,
                        FontStyle   = SharpDX.DirectWrite.FontStyle.Normal,
                        FontWeight  = SharpDX.DirectWrite.FontWeight.Normal,
                    },
                    DisableGeometryShader = 0,
                    GlyphSheetHeight      = 0,
                    GlyphSheetWidth       = 0,
                    MaxGlyphCountPerSheet = 0,
                    MaxGlyphHeight        = 0,
                    MaxGlyphWidth         = 0,
                    VertexBufferSize      = 0
                };

                var factory = GetFactory();
                fontWrapper = factory.CreateFontWrapper(new SharpDX.Direct3D11.Device(context.Device.ComPointer), new SharpDX.DirectWrite.Factory(dwFactory.ComPointer), ref p);
            }
            return(fontWrapper);
        }
Пример #2
0
        private void InitializeDevices()
        {
            InitializeMatricies();
            //3DCGの初期化
            if (DeviceManager == null)
            {
                disposeDeviceManager = true;
                DeviceManager        = new BasicGraphicDeviceManager();
                DeviceManager.Load();
            }
            RasterizerStateDescription desc = new RasterizerStateDescription();

            desc.CullMode             = CullMode.Back;
            desc.FillMode             = FillMode.Solid;
            CullingRasterizerState    = RasterizerState.FromDescription(DeviceManager.Device, desc);
            desc.CullMode             = CullMode.None;
            NonCullingRasterizerState = RasterizerState.FromDescription(DeviceManager.Device, desc);

            //DirectWriteファクトリの作成
#if VSG_DEBUG
#else
            DWFactory  = new SlimDX.DirectWrite.Factory(FactoryType.Isolated);
            D2DFactory = new Factory(SlimDX.Direct2D.FactoryType.Multithreaded, DebugLevel.Information);
#endif
        }
Пример #3
0
        public DX11TextLayerNode(IIOFactory factory, SlimDX.DirectWrite.Factory dwFactory)
        {
            this.iofactory = factory;
            this.dwFactory = dwFactory;

            this.iofactory.PluginHost.CreateTransformInput("Transform In", TSliceMode.Dynamic, TPinVisibility.True, out this.transformIn);
            this.transformIn.Order = 1;
        }
Пример #4
0
 public DirectGraphics(SlimDX.Direct2D.WindowRenderTarget renderTarget)
 {
     this.renderTarget = renderTarget;
     try
     {
         m = new SlimDX.DirectWrite.Factory(SlimDX.DirectWrite.FactoryType.Shared);
     }
     catch { }
 }
Пример #5
0
 public DirectGraphics(SlimDX.Direct2D.WindowRenderTarget renderTarget)
 {
     this.renderTarget = renderTarget;
     try
     {
         m = new SlimDX.DirectWrite.Factory(SlimDX.DirectWrite.FactoryType.Shared);
     }
     catch { }
 }
Пример #6
0
 public RenderService()
 {
     bitmaps = new Dictionary<string, Bitmap>();
     brushes = new Dictionary<Tuple<Color4, float>, SolidColorBrush>();
     writeFactory = new SlimDX.DirectWrite.Factory(SlimDX.DirectWrite.FactoryType.Shared);
     clearColor = new Color4(1, 1, 1);
     PixelFormat pixelFormat = new PixelFormat(SlimDX.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied);
     bitmapProperties = new BitmapProperties() { PixelFormat = pixelFormat };
 }
Пример #7
0
        public void Render(Factory factory, SlimDX.DirectWrite.Factory dwFactory, RenderTarget renderTarget)
        {
            SolidColorBrush brush   = new SolidColorBrush(renderTarget, new Color4(1.0f, 1.0f, 1.0f));
            Ellipse         ellipse = new Ellipse
            {
                Center = new PointF {
                    X = position.X, Y = position.Y
                },
                RadiusX = this.radius,
                RadiusY = this.radius
            };

            renderTarget.FillEllipse(brush, ellipse);
        }
Пример #8
0
        private void InitializeDirect2D()
        {
            Size drawingPanelSize = this.ClientSize;

            Debug.WriteLine("Width " + drawingPanelSize.Width + ", Height " + drawingPanelSize.Height + ", HWND " + this.Handle);

            factory   = new Factory();
            dwFactory = new SlimDX.DirectWrite.Factory();
            SlimDX.DirectWrite.FontCollection installedFonts = dwFactory.GetSystemFontCollection(false);

            renderTarget = new WindowRenderTarget(factory, new WindowRenderTargetProperties
            {
                Handle    = this.Handle,
                PixelSize = new Size(drawingPanelSize.Width, drawingPanelSize.Height)
            });
        }
Пример #9
0
        public static void SetFontEnum(IHDEHost host, DWriteFactory dwfactory)
        {
            Factory f = new Factory(dwfactory.ComPointer);

            var fontCollection = f.GetSystemFontCollection(false);

            List<string> familyNames = new List<string>();
            for (int i = 0; i < fontCollection.FontFamilyCount; i++)
            {
                var family = fontCollection.GetFontFamily(i);
                if (family.FamilyNames.Count > 0)
                {
                    familyNames.Add(family.FamilyNames.GetString(0));
                }
            }
            familyNames.Sort();
            host.UpdateEnum("DirectWrite_Font_Families", "Arial", familyNames.ToArray());
        }
Пример #10
0
        public static void SetFontEnum(IHDEHost host, DWriteFactory dwfactory)
        {
            Factory f = new Factory(dwfactory.ComPointer);

            var fontCollection = f.GetSystemFontCollection(false);

            List <string> familyNames = new List <string>();

            for (int i = 0; i < fontCollection.FontFamilyCount; i++)
            {
                var family = fontCollection.GetFontFamily(i);
                if (family.FamilyNames.Count > 0)
                {
                    familyNames.Add(family.FamilyNames.GetString(0));
                }
            }
            familyNames.Sort();
            host.UpdateEnum("DirectWrite_Font_Families", "Arial", familyNames.ToArray());
        }
Пример #11
0
        public void Render(Factory factory, SlimDX.DirectWrite.Factory dwFactory, RenderTarget renderTarget)
        {
            SolidColorBrush brush = new SolidColorBrush(renderTarget, new Color4(1.0f, 1.0f, 1.0f));

            renderTarget.FillRectangle(brush, rect);
        }
Пример #12
0
        public DX11NodesFactory(IHDEHost hdehost, DotNetPluginFactory dnfactory, INodeInfoFactory ni, IORegistry ioreg, ILogger logger)
        {
            //Attach lib core path and plugins path

            string path     = Path.GetDirectoryName(typeof(DX11DeviceRenderer).Assembly.Location);
            string vvvvpath = Path.GetDirectoryName(Application.ExecutablePath);

            string varpath = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Process);

            varpath += ";" + path;

            vvvvpath = Path.Combine(vvvvpath, "packs\\dx11\\nodes\\plugins");
            varpath += ";" + path;

            Environment.SetEnvironmentVariable("Path", varpath, EnvironmentVariableTarget.Process);

            DX11EnumFormatHelper.CreateNullDeviceFormat();


            this.hdehost = hdehost;
            this.ioreg   = ioreg;
            this.logger  = logger;

            //Workaround for vvvv < 35.6
            var versionProperty = hdehost.GetType().GetProperty("Version");

            if (versionProperty == null)
            {
                this.hdehost.RootNode.Removed += new Core.CollectionDelegate <INode2>(RootNode_Removed);
            }

            DX11ResourceRegistry reg = new DX11ResourceRegistry();

            this.ioreg.Register(reg, true);

            this.hdehost.MainLoop.OnPresent      += GraphEventService_OnPresent;
            this.hdehost.MainLoop.OnPrepareGraph += GraphEventService_OnPrepareGraph;
            this.hdehost.MainLoop.OnRender       += GraphEventService_OnRender;

            this.displaymanager = new DX11DisplayManager();

            this.DirectWriteFactory = new DWriteFactory(SlimDX.DirectWrite.FactoryType.Shared);
            DirectWriteFontUtils.SetFontEnum(this.hdehost, this.DirectWriteFactory);

            string[] args = Environment.GetCommandLineArgs();

            foreach (string s in args)
            {
                string sl = s.ToLower();
                if (sl.StartsWith("/dx11mode:"))
                {
                    sl = sl.Replace("/dx11mode:", "");

                    if (sl == "permonitor")
                    {
                        this.devicemanager = new DX11PerMonitorDeviceManager(this.logger, this.displaymanager);
                    }
                    else if (sl == "nvidia")
                    {
                        this.devicemanager = new DX11AutoAdapterDeviceManager(this.logger, this.displaymanager);
                    }
                    else if (sl == "peradapter")
                    {
                        this.devicemanager = new DX11PerAdapterDeviceManager(this.logger, this.displaymanager);
                    }
                    else if (sl == "all")
                    {
                        this.devicemanager = new DX11AllAdapterDeviceManager(this.logger, this.displaymanager);
                    }
                    else if (sl.StartsWith("force"))
                    {
                        sl = sl.Replace("force", "");
                        try
                        {
                            int i = int.Parse(sl);
                            if (i >= 0 && i < this.displaymanager.AdapterCount)
                            {
                                this.devicemanager = new DX11AutoAdapterDeviceManager(this.logger, this.displaymanager, i);
                            }
                        }
                        catch
                        {
                        }
                    }
                    else if (sl.StartsWith("pooled"))
                    {
                        sl = sl.Replace("pooled", "");
                        try
                        {
                            int i = 0;
                            int.TryParse(sl, out i);

                            this.devicemanager = new DX11PooledAdapterDeviceManager(this.logger, this.displaymanager, i);
                        }
                        catch
                        {
                        }
                    }
                }
            }

            if (this.devicemanager == null)
            {
                this.devicemanager = new DX11AutoAdapterDeviceManager(this.logger, this.displaymanager);
            }

            this.graphbuilder = new DX11GraphBuilder(hdehost, reg);
            this.graphbuilder.RenderRequest += graphbuilder_OnRenderRequest;
            this.rendermanager = new DX11RenderManager(this.devicemanager, this.graphbuilder, this.logger);

            DX11GlobalDevice.DeviceManager = this.devicemanager;
            DX11GlobalDevice.RenderManager = this.rendermanager;

            this.BuildAAEnum();
            this.RegisterStateEnums();
            this.BuildVertexLayoutsEnum();
        }
Пример #13
0
 public DX11TextSettingsNode(SlimDX.DirectWrite.Factory dwFactory)
 {
     this.dwFactory = dwFactory;
 }
Пример #14
0
 public void Initialize()
 {
     D3DDevice10  = new SlimDX.Direct3D10_1.Device1(SlimDX.Direct3D10.DeviceCreationFlags.BgraSupport, SlimDX.Direct3D10_1.FeatureLevel.Level_10_0);
     WriteFactory = new SlimDX.DirectWrite.Factory(SlimDX.DirectWrite.FactoryType.Shared);
     D2DFactory   = new SlimDX.Direct2D.Factory(SlimDX.Direct2D.FactoryType.SingleThreaded);
 }
Пример #15
0
        public TextRenderer(Device device)
        {
            using (var factory = new SlimDX.DXGI.Factory1())
            {
                using (var adapter = factory.GetAdapter1(0))
                {
                    this.device = new SlimDX.Direct3D10_1.Device1(
                        adapter,
                        SlimDX.Direct3D10.DriverType.Hardware,
                        SlimDX.Direct3D10.DeviceCreationFlags.BgraSupport,
                        SlimDX.Direct3D10_1.FeatureLevel.Level_10_0
                    );

                    // Create the DirectX11 texture2D. This texture will be shared with the DirectX10
                    // device. The DirectX10 device will be used to render text onto this texture. DirectX11
                    // will then draw this texture (blended) onto the screen.
                    // The KeyedMutex flag is required in order to share this resource.
                    textureD3D11 = new SlimDX.Direct3D11.Texture2D(device.Handle, new SlimDX.Direct3D11.Texture2DDescription
                    {
                        Width = device.Form.Width,
                        Height = device.Form.Height,
                        MipLevels = 1,
                        ArraySize = 1,
                        Format = SlimDX.DXGI.Format.B8G8R8A8_UNorm,
                        SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0),
                        Usage = SlimDX.Direct3D11.ResourceUsage.Default,
                        BindFlags = SlimDX.Direct3D11.BindFlags.RenderTarget | SlimDX.Direct3D11.BindFlags.ShaderResource,
                        CpuAccessFlags = SlimDX.Direct3D11.CpuAccessFlags.None,
                        OptionFlags = SlimDX.Direct3D11.ResourceOptionFlags.KeyedMutex
                    });

                    // A DirectX10 Texture2D sharing the DirectX11 Texture2D
                    var sharedResource = new SlimDX.DXGI.Resource(textureD3D11);
                    var textureD3D10 = this.device.OpenSharedResource<SlimDX.Direct3D10.Texture2D>(sharedResource.SharedHandle);

                    // The KeyedMutex is used just prior to writing to textureD3D11 or textureD3D10.
                    // This is how DirectX knows which DirectX (10 or 11) is supposed to be writing
                    // to the shared texture.  The keyedMutex is just defined here, they will be used
                    // a bit later.
                    mutex10 = new SlimDX.DXGI.KeyedMutex(textureD3D10);
                    mutex11 = new SlimDX.DXGI.KeyedMutex(textureD3D11);

                    // Direct2D Factory
                    SlimDX.Direct2D.Factory d2Factory = new SlimDX.Direct2D.Factory(
                        SlimDX.Direct2D.FactoryType.SingleThreaded,
                        SlimDX.Direct2D.DebugLevel.Information
                    );

                    // Direct Write factory
                    SlimDX.DirectWrite.Factory dwFactory = new SlimDX.DirectWrite.Factory(
                        SlimDX.DirectWrite.FactoryType.Isolated
                    );

                    // The textFormat we will use to draw text with
                    textFormat = new SlimDX.DirectWrite.TextFormat(
                        dwFactory,
                        "Arial",
                        SlimDX.DirectWrite.FontWeight.Normal,
                        SlimDX.DirectWrite.FontStyle.Normal,
                        SlimDX.DirectWrite.FontStretch.Normal,
                        24,
                        "en-US"
                    );
                    textFormat.TextAlignment = SlimDX.DirectWrite.TextAlignment.Center;
                    textFormat.ParagraphAlignment = SlimDX.DirectWrite.ParagraphAlignment.Center;

                    // Query for a IDXGISurface.
                    // DirectWrite and DirectX10 can interoperate thru DXGI.
                    var surface = textureD3D10.AsSurface();
                    var rtp = new SlimDX.Direct2D.RenderTargetProperties();
                    rtp.MinimumFeatureLevel = SlimDX.Direct2D.FeatureLevel.Direct3D10;
                    rtp.Type = SlimDX.Direct2D.RenderTargetType.Hardware;
                    rtp.Usage = SlimDX.Direct2D.RenderTargetUsage.None;
                    rtp.PixelFormat = new SlimDX.Direct2D.PixelFormat(SlimDX.DXGI.Format.Unknown, SlimDX.Direct2D.AlphaMode.Premultiplied);
                    dwRenderTarget = SlimDX.Direct2D.RenderTarget.FromDXGI(d2Factory, surface, rtp);

                    // Brush used to DrawText
                    brushSolidWhite = new SlimDX.Direct2D.SolidColorBrush(
                        dwRenderTarget,
                        new SlimDX.Color4(1, 1, 1, 1)
                    );

                    // Think of the shared textureD3D10 as an overlay.
                    // The overlay needs to show the text but let the underlying triangle (or whatever)
                    // show thru, which is accomplished by blending.
                    var bsd = new SlimDX.Direct3D11.BlendStateDescription();
                    bsd.RenderTargets[0].BlendEnable = true;
                    bsd.RenderTargets[0].SourceBlend = SlimDX.Direct3D11.BlendOption.SourceAlpha;
                    bsd.RenderTargets[0].DestinationBlend = SlimDX.Direct3D11.BlendOption.InverseSourceAlpha;
                    bsd.RenderTargets[0].BlendOperation = SlimDX.Direct3D11.BlendOperation.Add;
                    bsd.RenderTargets[0].SourceBlendAlpha = SlimDX.Direct3D11.BlendOption.One;
                    bsd.RenderTargets[0].DestinationBlendAlpha = SlimDX.Direct3D11.BlendOption.Zero;
                    bsd.RenderTargets[0].BlendOperationAlpha = SlimDX.Direct3D11.BlendOperation.Add;
                    bsd.RenderTargets[0].RenderTargetWriteMask = SlimDX.Direct3D11.ColorWriteMaskFlags.All;
                    BlendState_Transparent = SlimDX.Direct3D11.BlendState.FromDescription(device.Handle, bsd);

                    // Load Effect. This includes both the vertex and pixel shaders.
                    // Also can include more than one technique.
                    var shaderByteCode = SlimDX.D3DCompiler.ShaderBytecode.CompileFromFile(
                        "texteffect.fx",
                        "fx_5_0",
                        SlimDX.D3DCompiler.ShaderFlags.EnableStrictness,
                        SlimDX.D3DCompiler.EffectFlags.None);

                    effect = new SlimDX.Direct3D11.Effect(device.Handle, shaderByteCode);

                    // create triangle vertex data, making sure to rewind the stream afterward
                    var verticesTriangle = new SlimDX.DataStream(30 * 3, true, true);
                    verticesTriangle.Write(new SlimDX.Vector3(0.0f, 0.5f, 0.5f));
                    verticesTriangle.Write(new SlimDX.Color4(1.0f, 0.0f, 0.0f, 1.0f));
                    verticesTriangle.Write(new SlimDX.Vector3(0.5f, -0.5f, 0.5f));
                    verticesTriangle.Write(new SlimDX.Color4(0.0f, 1.0f, 0.0f, 1.0f));
                    verticesTriangle.Write(new SlimDX.Vector3(-0.5f, -0.5f, 0.5f));
                    verticesTriangle.Write(new SlimDX.Color4(0.0f, 0.0f, 1.0f, 1.0f));
                    verticesTriangle.Position = 0;

                    // create the triangle vertex layout and buffer
                    var inputElements = new SlimDX.Direct3D11.InputElement[] {
                new SlimDX.Direct3D11.InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32A32_Float, 0, 0),
                new SlimDX.Direct3D11.InputElement("COLOR",0,SlimDX.DXGI.Format.R32G32B32A32_Float,16,0)
            };
                    var layoutColor = new SlimDX.Direct3D11.InputLayout(device.Handle, effect.GetTechniqueByName("Color").GetPassByIndex(0).Description.Signature, inputElements);
                    var vertexBufferColor = new SlimDX.Direct3D11.Buffer(device.Handle, verticesTriangle, (int)verticesTriangle.Length, SlimDX.Direct3D11.ResourceUsage.Default, SlimDX.Direct3D11.BindFlags.VertexBuffer, SlimDX.Direct3D11.CpuAccessFlags.None, SlimDX.Direct3D11.ResourceOptionFlags.None, 0);
                    verticesTriangle.Close();

                    // create text vertex data, making sure to rewind the stream afterward
                    // Top Left of screen is -1, +1
                    // Bottom Right of screen is +1, -1
                    var verticesText = new SlimDX.DataStream(30 * 4, true, true);
                    verticesText.Write(new SlimDX.Vector3(-1, 1, 0));
                    verticesText.Write(new SlimDX.Vector2(0, 0f));
                    verticesText.Write(new SlimDX.Vector3(1, 1, 0));
                    verticesText.Write(new SlimDX.Vector2(1, 0));
                    verticesText.Write(new SlimDX.Vector3(-1, -1, 0));
                    verticesText.Write(new SlimDX.Vector2(0, 1));
                    verticesText.Write(new SlimDX.Vector3(1, -1, 0));
                    verticesText.Write(new SlimDX.Vector2(1, 1));
                    verticesText.Position = 0;

                    // create the text vertex layout and buffer
                    layoutText = new SlimDX.Direct3D11.InputLayout(device.Handle, effect.GetTechniqueByName("Text").GetPassByIndex(0).Description.Signature, inputElements);
                    vertexBufferText = new SlimDX.Direct3D11.Buffer(device.Handle, verticesText, (int)verticesText.Length, SlimDX.Direct3D11.ResourceUsage.Default, SlimDX.Direct3D11.BindFlags.VertexBuffer, SlimDX.Direct3D11.CpuAccessFlags.None, SlimDX.Direct3D11.ResourceOptionFlags.None, 0);
                    verticesText.Close();

                }
            }
        }