public void NewWrappedLinesShouldNotStartOrEndWithWhiteSpace(string text, HorizontalAlignment horizontalAlignment)
        {
            Font font = CreateFont("\t x");

            var r = new GlyphRenderer();

            IReadOnlyList <GlyphLayout> layout = new TextLayout().GenerateLayout(text.AsSpan(), new TextOptions(new Font(font, 30))
            {
                WrappingLength      = 350,
                HorizontalAlignment = horizontalAlignment
            });

            float lineYPos = layout[0].Location.Y;

            for (int i = 0; i < layout.Count; i++)
            {
                GlyphLayout glyph = layout[i];
                if (lineYPos != glyph.Location.Y)
                {
                    Assert.False(glyph.IsWhiteSpace());
                    Assert.False(layout[i - 1].IsWhiteSpace());
                    lineYPos = glyph.Location.Y;
                }
            }
        }
Beispiel #2
0
        public void Dispose()
        {
            if (!disposed)
            {
                disposed = true;
                Background.Dispose();
                CompressToSwap.Dispose();

                SphereRenderer.Dispose();
                CapsuleRenderer.Dispose();

                UILineRenderer.Dispose();
                GlyphRenderer.Dispose();

                depthBuffer.Dispose();
                dsv.Dispose();
                colorBuffer.Dispose();
                rtv.Dispose();
                rasterizerState.Dispose();
                opaqueDepthState.Dispose();
                opaqueBlendState.Dispose();
                uiDepthState.Dispose();
                uiBlendState.Dispose();
            }
        }
Beispiel #3
0
        public void Dispose()
        {
            if (!disposed)
            {
                disposed = true;
                Background.Dispose();
                CompressToSwap.Dispose();

                SphereRenderer.Dispose();
                CapsuleRenderer.Dispose();
                BoxRenderer.Dispose();
                TriangleRenderer.Dispose();
                MeshRenderer.Dispose();

                UILineRenderer.Dispose();
                GlyphRenderer.Dispose();

                dsv.Dispose();
                depthBuffer.Dispose();
                rtv.Dispose();
                colorBuffer.Dispose();
                resolvedSRV.Dispose();
                resolvedRTV.Dispose();
                resolvedColorBuffer.Dispose();

                rasterizerState.Dispose();
                opaqueDepthState.Dispose();
                opaqueBlendState.Dispose();
                a2cBlendState.Dispose();
                uiDepthState.Dispose();
                uiBlendState.Dispose();

                Shapes.Dispose();
            }
        }
Beispiel #4
0
        public void NewWrappedLinesShouldNotStartOrEndWithWhiteSpace(string text, HorizontalAlignment horiAlignment)
        {
            var font = CreateFont("\t x");

            GlyphRenderer r = new GlyphRenderer();

            ImmutableArray <GlyphLayout> layout = new TextLayout().GenerateLayout(text, new RendererOptions(new Font(font, 30), 72)
            {
                WrappingWidth       = 350,
                HorizontalAlignment = horiAlignment
            });

            float lineYPos = layout[0].Location.Y;

            for (int i = 0; i < layout.Length; i++)
            {
                GlyphLayout glyph = layout[i];
                if (lineYPos != glyph.Location.Y)
                {
                    Assert.Equal(false, glyph.IsWhiteSpace);
                    Assert.Equal(false, layout[i - 1].IsWhiteSpace);
                    lineYPos = glyph.Location.Y;
                }
            }
        }
Beispiel #5
0
        public Renderer(RenderSurface surface)
        {
            Surface = surface;
            ContentArchive content;

            using (var stream = GetType().Assembly.GetManifestResourceStream("DemoRenderer.DemoRenderer.contentarchive"))
            {
                content = ContentArchive.Load(stream);
            }
            Shapes           = new ShapesExtractor(looper, pool);
            SphereRenderer   = new RayTracedRenderer <SphereInstance>(content, @"ShapeDrawing\RenderSpheres");
            CapsuleRenderer  = new RayTracedRenderer <CapsuleInstance>(content, @"ShapeDrawing\RenderCapsules");
            CylinderRenderer = new RayTracedRenderer <CylinderInstance>(content, @"ShapeDrawing\RenderCylinders");
            BoxRenderer      = new BoxRenderer(content);
            TriangleRenderer = new TriangleRenderer(content);
            MeshRenderer     = new MeshRenderer(Shapes.MeshCache, content);
            Lines            = new LineExtractor(pool, looper);
            LineRenderer     = new LineRenderer(content);
            Background       = new BackgroundRenderer(content);
            CompressToSwap   = new CompressToSwap(content);

            ImageRenderer  = new ImageRenderer(content);
            ImageBatcher   = new ImageBatcher(pool);
            GlyphRenderer  = new GlyphRenderer(content);
            TextBatcher    = new TextBatcher();
            UILineRenderer = new UILineRenderer(content);
            UILineBatcher  = new UILineBatcher();

            OnResize();
        }
Beispiel #6
0
        protected override void DoDispose()
        {
            Background.Dispose();
            CompressToSwap.Dispose();

            Lines.Dispose();

            SphereRenderer.Dispose();
            CapsuleRenderer.Dispose();
            CylinderRenderer.Dispose();
            BoxRenderer.Dispose();
            TriangleRenderer.Dispose();
            MeshRenderer.Dispose();

            UILineRenderer.Dispose();
            GlyphRenderer.Dispose();

            GL.DeleteFramebuffer(framebuffer);
            GL.DeleteTexture(depthBuffer);
            GL.DeleteTexture(colorBuffer);
            GL.DeleteFramebuffer(resolvedFramebuffer);
            GL.DeleteTexture(resolvedColorBuffer);

            Shapes.Dispose();
        }
Beispiel #7
0
        public void RenderingEmptyString_DoesNotThrow()
        {
            Font font = CreateFont("\t x");

            var r = new GlyphRenderer();

            new TextRenderer(r).RenderText("", new RendererOptions(new Font(font, 30), 72));
        }
        public void BleadingFonts()
        {
            // wendy one returns wrong points for 'o'
            Font font = new FontCollection().Add(TestFonts.WendyOneFile).CreateFont(12);

            var r = new GlyphRenderer();

            new TextRenderer(r).RenderText("o", new TextOptions(new Font(font, 30)));

            Assert.DoesNotContain(System.Numerics.Vector2.Zero, r.ControlPoints);
        }
Beispiel #9
0
        public void Render(Camera camera)
        {
            if (Surface.Resolution.X != depthBuffer.Description.Width || Surface.Resolution.Y != depthBuffer.Description.Height)
            {
                OnResize();
            }
            var context = Surface.Context;

            Shapes.MeshCache.FlushPendingUploads(context);

            context.Rasterizer.SetViewport(0, 0, Surface.Resolution.X, Surface.Resolution.Y, 0.0f, 1.0f);

            //Note reversed depth.
            context.ClearDepthStencilView(dsv, DepthStencilClearFlags.Depth, 0, 0);
            context.ClearRenderTargetView(rtv, new SharpDX.Mathematics.Interop.RawColor4());
            context.OutputMerger.SetRenderTargets(dsv, rtv);
            context.Rasterizer.State = rasterizerState;
            context.OutputMerger.SetDepthStencilState(opaqueDepthState);

            //All ray traced shapes use analytic coverage writes to get antialiasing.
            context.OutputMerger.SetBlendState(a2cBlendState);
            SphereRenderer.Render(context, camera, Surface.Resolution, SpanConverter.AsSpan(Shapes.spheres.Span), 0, Shapes.spheres.Count);
            CapsuleRenderer.Render(context, camera, Surface.Resolution, SpanConverter.AsSpan(Shapes.capsules.Span), 0, Shapes.capsules.Count);
            CylinderRenderer.Render(context, camera, Surface.Resolution, SpanConverter.AsSpan(Shapes.cylinders.Span), 0, Shapes.cylinders.Count);

            //Non-raytraced shapes just use regular opaque rendering.
            context.OutputMerger.SetBlendState(opaqueBlendState);
            BoxRenderer.Render(context, camera, Surface.Resolution, SpanConverter.AsSpan(Shapes.boxes.Span), 0, Shapes.boxes.Count);
            TriangleRenderer.Render(context, camera, Surface.Resolution, SpanConverter.AsSpan(Shapes.triangles.Span), 0, Shapes.triangles.Count);
            MeshRenderer.Render(context, camera, Surface.Resolution, SpanConverter.AsSpan(Shapes.meshes.Span), 0, Shapes.meshes.Count);
            LineRenderer.Render(context, camera, Surface.Resolution, SpanConverter.AsSpan(Lines.lines.Span), 0, Lines.lines.Count);

            Background.Render(context, camera);

            //Resolve MSAA rendering down to a single sample buffer for screenspace work.
            //Note that we're not bothering to properly handle tonemapping during the resolve. That's going to hurt quality a little, but the demos don't make use of very wide ranges.
            //(If for some reason you end up expanding the demos to make use of wider HDR, you can make this a custom resolve pretty easily.)
            context.ResolveSubresource(colorBuffer, 0, resolvedColorBuffer, 0, Format.R16G16B16A16_Float);
            context.OutputMerger.SetRenderTargets(resolvedRTV);

            //Glyph and screenspace line drawing rely on the same premultiplied alpha blending transparency. We'll handle their state out here.
            context.OutputMerger.SetBlendState(uiBlendState);
            context.OutputMerger.SetDepthStencilState(uiDepthState);
            ImageRenderer.PreparePipeline(context);
            ImageBatcher.Flush(context, Surface.Resolution, ImageRenderer);
            UILineBatcher.Flush(context, Surface.Resolution, UILineRenderer);
            GlyphRenderer.PreparePipeline(context);
            TextBatcher.Flush(context, Surface.Resolution, GlyphRenderer);

            //Note that, for now, the compress to swap handles its own depth state since it's the only post processing stage.
            context.OutputMerger.SetBlendState(opaqueBlendState);
            context.Rasterizer.State = rasterizerState;
            CompressToSwap.Render(context, resolvedSRV, Surface.RTV);
        }
Beispiel #10
0
        public void Render(Camera camera)
        {
            if (Surface.Resolution.X != width || Surface.Resolution.Y != height)
            {
                OnResize();
            }
            Shapes.MeshCache.FlushPendingUploads();

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, framebuffer);
            //Note reversed depth.
            GL.ClearDepth(0.0f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.Enable(EnableCap.CullFace);
            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Greater);

            //All ray traced shapes use analytic coverage writes to get antialiasing.
            GL.Enable(EnableCap.SampleAlphaToCoverage);
            SphereRenderer.Render(camera, Surface.Resolution, SpanConverter.AsSpan(Shapes.spheres.Span), 0, Shapes.spheres.Count);
            CapsuleRenderer.Render(camera, Surface.Resolution, SpanConverter.AsSpan(Shapes.capsules.Span), 0, Shapes.capsules.Count);
            CylinderRenderer.Render(camera, Surface.Resolution, SpanConverter.AsSpan(Shapes.cylinders.Span), 0, Shapes.cylinders.Count);

            //Non-raytraced shapes just use regular opaque rendering.
            GL.Disable(EnableCap.SampleAlphaToCoverage);
            BoxRenderer.Render(camera, Surface.Resolution, SpanConverter.AsSpan(Shapes.boxes.Span), 0, Shapes.boxes.Count);
            TriangleRenderer.Render(camera, Surface.Resolution, SpanConverter.AsSpan(Shapes.triangles.Span), 0, Shapes.triangles.Count);
            MeshRenderer.Render(camera, Surface.Resolution, SpanConverter.AsSpan(Shapes.meshes.Span), 0, Shapes.meshes.Count);
            LineRenderer.Render(camera, Surface.Resolution, SpanConverter.AsSpan(Lines.lines.Span), 0, Lines.lines.Count);

            Background.Render(camera);
            GL.Disable(EnableCap.CullFace);
            GL.Disable(EnableCap.DepthTest);

            //Resolve MSAA rendering down to a single sample buffer for screenspace work.
            //Note that we're not bothering to properly handle tonemapping during the resolve. That's going to hurt quality a little, but the demos don't make use of very wide ranges.
            //(If for some reason you end up expanding the demos to make use of wider HDR, you can make this a custom resolve pretty easily.)
            GL.BlitNamedFramebuffer(framebuffer, resolvedFramebuffer, 0, 0, width, height, 0, 0, width, height, ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Nearest);
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, resolvedFramebuffer);

            //Glyph and screenspace line drawing rely on the same premultiplied alpha blending transparency. We'll handle their state out here.
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.OneMinusSrcAlpha);
            GL.BlendEquation(BlendEquationMode.FuncAdd);
            ImageRenderer.PreparePipeline();
            ImageBatcher.Flush(Surface.Resolution, ImageRenderer);
            UILineBatcher.Flush(Surface.Resolution, UILineRenderer);
            GlyphRenderer.PreparePipeline();
            TextBatcher.Flush(Surface.Resolution, GlyphRenderer);
            GL.Disable(EnableCap.Blend);

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            CompressToSwap.Render(resolvedColorBuffer);
        }
Beispiel #11
0
        public void ThrowsMeasureingWhitespace()
        {
            // wendy one returns wrong points for 'o'
            Font font = new FontCollection().Install(TestFonts.WendyOneFile).CreateFont(12);

            var r = new GlyphRenderer();

            FontRectangle size = TextMeasurer.MeasureBounds("          ", new RendererOptions(new Font(font, 30), 72));

            Assert.Equal(60, size.Width, 1);
            Assert.Equal(31.6, size.Height, 1);
        }
Beispiel #12
0
        public void WhiteSpaceAtStartOfTextShouldNotBeTrimmed()
        {
            Font   font = CreateFont("\t x");
            string text = "   hello world hello world hello world";

            var r = new GlyphRenderer();

            IReadOnlyList <GlyphLayout> layout = new TextLayout().GenerateLayout(text, new RendererOptions(new Font(font, 30), 72)
            {
                WrappingWidth = 350
            });

            Assert.True(layout[0].IsWhiteSpace);
            Assert.True(layout[1].IsWhiteSpace);
            Assert.True(layout[2].IsWhiteSpace);
        }
        public void WhiteSpaceAtTheEndOfTextShouldBeTrimmed()
        {
            Font   font = CreateFont("\t x");
            string text = "hello world hello world hello world   ";

            var r = new GlyphRenderer();

            IReadOnlyList <GlyphLayout> layout = new TextLayout().GenerateLayout(text.AsSpan(), new TextOptions(new Font(font, 30))
            {
                WrappingLength = 350
            });

            Assert.False(layout[layout.Count - 1].IsWhiteSpace());
            Assert.False(layout[layout.Count - 2].IsWhiteSpace());
            Assert.False(layout[layout.Count - 3].IsWhiteSpace());
        }
Beispiel #14
0
        public void WhiteSpaceAtTheEndOfTextShouldBeTrimmed()
        {
            var font = CreateFont("\t x");
            var text = "hello world hello world hello world   ";

            GlyphRenderer r = new GlyphRenderer();

            ImmutableArray <GlyphLayout> layout = new TextLayout().GenerateLayout(text, new RendererOptions(new Font(font, 30), 72)
            {
                WrappingWidth = 350
            });

            Assert.Equal(false, layout[layout.Length - 1].IsWhiteSpace);
            Assert.Equal(false, layout[layout.Length - 2].IsWhiteSpace);
            Assert.Equal(false, layout[layout.Length - 3].IsWhiteSpace);
        }
Beispiel #15
0
        public Image LoadGlyph(string glyph, System.Drawing.FontFamily fontFamily, int fontSizeEm)
        {
            try
            {
                return(LoadImage($"glyph_{fontFamily.Name}_{fontSizeEm}_{glyph}", loader =>
                {
                    var img = GlyphRenderer.RenderGlyph(glyph, fontFamily, fontSizeEm, System.Drawing.Color.White);

                    return loader.Load(img.ToByteArray());
                }));
            }
            catch (Exception ex)
            {
                _log.Error($"Could not load glyph: '{ex.Message}'", ex);
                return(DefaultImage);
            }
        }
Beispiel #16
0
        public void Render(Camera camera)
        {
            if (Surface.Resolution.X != depthBuffer.Description.Width || Surface.Resolution.Y != depthBuffer.Description.Height)
            {
                OnResize();
            }
            var context = Surface.Context;

            context.Rasterizer.SetViewport(0, 0, Surface.Resolution.X, Surface.Resolution.Y, 0.0f, 1.0f);

            //Note reversed depth.
            context.ClearDepthStencilView(dsv, DepthStencilClearFlags.Depth, 0, 0);
            //The background render is going to fill out the entire color buffer, but having a clear can be useful- e.g. clearing out MSAA history.
            //We don't use MSAA right now, but the cost of doing this clear is negligible and it avoids a surprise later.
            context.ClearRenderTargetView(rtv, new SharpDX.Mathematics.Interop.RawColor4());
            context.OutputMerger.SetRenderTargets(dsv, rtv);
            context.Rasterizer.State = rasterizerState;
            context.OutputMerger.SetBlendState(opaqueBlendState);
            context.OutputMerger.SetDepthStencilState(opaqueDepthState);

            SphereRenderer.Render(context, camera, Surface.Resolution, Shapes.spheres.Span.Memory, 0, Shapes.spheres.Count);
            CapsuleRenderer.Render(context, camera, Surface.Resolution, Shapes.capsules.Span.Memory, 0, Shapes.capsules.Count);
            BoxRenderer.Render(context, camera, Surface.Resolution, Shapes.boxes.Span.Memory, 0, Shapes.boxes.Count);
            LineRenderer.Render(context, camera, Surface.Resolution, Lines.lines.Span.Memory, 0, Lines.lines.Count);

            Background.Render(context, camera);

            //Glyph and screenspace line drawing rely on the same premultiplied alpha blending transparency. We'll handle their state out here.
            context.OutputMerger.SetBlendState(uiBlendState);
            context.OutputMerger.SetDepthStencilState(uiDepthState);
            UILineBatcher.Flush(context, Surface.Resolution, UILineRenderer);
            GlyphRenderer.PreparePipeline(context);
            TextBatcher.Flush(context, Surface.Resolution, GlyphRenderer);

            //Note that, for now, the compress to swap handles its own depth state since it's the only post processing stage.
            context.OutputMerger.SetBlendState(opaqueBlendState);
            context.Rasterizer.State = rasterizerState;
            CompressToSwap.Render(context, srv, Surface.RTV);
        }
Beispiel #17
0
        public void LeftAlignedTextNewLineShouldNotStartWithWhiteSpace(string text)
        {
            var font = CreateFont("\t x");

            GlyphRenderer r = new GlyphRenderer();

            ImmutableArray <GlyphLayout> layout = new TextLayout().GenerateLayout(text, new RendererOptions(new Font(font, 30), 72)
            {
                WrappingWidth       = 350,
                HorizontalAlignment = HorizontalAlignment.Left
            });

            float lineYPos = layout[0].Location.Y;

            foreach (GlyphLayout glyph in layout)
            {
                if (lineYPos != glyph.Location.Y)
                {
                    Assert.Equal(false, glyph.IsWhiteSpace);
                    lineYPos = glyph.Location.Y;
                }
            }
        }
        public void LeftAlignedTextNewLineShouldNotStartWithWhiteSpace(string text)
        {
            Font font = CreateFont("\t x");

            var r = new GlyphRenderer();

            IReadOnlyList <GlyphLayout> layout = new TextLayout().GenerateLayout(text.AsSpan(), new TextOptions(new Font(font, 30))
            {
                WrappingLength      = 350,
                HorizontalAlignment = HorizontalAlignment.Left
            });

            float lineYPos = layout[0].Location.Y;

            foreach (GlyphLayout glyph in layout)
            {
                if (lineYPos != glyph.Location.Y)
                {
                    Assert.False(glyph.IsWhiteSpace());
                    lineYPos = glyph.Location.Y;
                }
            }
        }
Beispiel #19
0
 private void CreateGlyphSprites()
 {
     if (data != null)
     {
         Vector2 pivot = new Vector2(0, 1);
         glyph = new Dictionary<char, GlyphRenderer>();
         foreach (Glyph g in data.Glyphs.Glyph)
         {
             Sprite[] sprites = new Sprite[g.images];
             Vector2[] offs = new Vector2[g.images];
             bool valid = true;
             for (int i = 0; i < g.images; ++i)
             {
                 Graphic gr = g.Graphic[i];
                 Texture2D page = pages[gr.page];
                 if (page != null)
                 {
                     float th = (float)page.height;
                     Rect r = new Rect(gr.x, th - gr.y - gr.h, gr.w, gr.h);
                     offs[i] = new Vector2(gr.offsetX, gr.offsetY);
                     sprites[i] = Sprite.Create(pages[gr.page], r, pivot);
                 }
                 else
                 {
                     valid = false;
                     break;
                 }
             }
             if (valid)
             {
                 GlyphRenderer glr = new GlyphRenderer(g.images, g.advance, sprites, offs);
                 glyph.Add((char)g.charcode, glr);
             }
         }
     }
 }
Beispiel #20
0
        public Renderer(RenderSurface surface)
        {
            looper  = new ParallelLooper();
            Surface = surface;
            using (var stream = new MemoryStream(Resources.DemoRendererShaders))
            {
                ShaderCache = ShaderCache.Load(stream);
            }
            Shapes         = new ShapesExtractor(looper);
            SphereRenderer = new SphereRenderer(surface.Device, ShaderCache);
            Lines          = new LineExtractor(looper);
            LineRenderer   = new LineRenderer(surface.Device, ShaderCache);
            Background     = new BackgroundRenderer(surface.Device, ShaderCache);
            CompressToSwap = new CompressToSwap(surface.Device, ShaderCache);

            GlyphRenderer  = new GlyphRenderer(surface.Device, surface.Context, ShaderCache);
            TextBatcher    = new TextBatcher();
            UILineRenderer = new UILineRenderer(surface.Device, ShaderCache);
            UILineBatcher  = new UILineBatcher();

            OnResize();
            var rasterizerStateDescription = RasterizerStateDescription.Default();

            rasterizerStateDescription.IsFrontCounterClockwise = true;
            rasterizerStateDescription.CullMode = CullMode.None;
            rasterizerState           = new RasterizerState(Surface.Device, rasterizerStateDescription);
            rasterizerState.DebugName = "Default Rasterizer State";

            var opaqueDepthStencilDescription = new DepthStencilStateDescription
            {
                IsDepthEnabled = true,
                DepthWriteMask = DepthWriteMask.All,
                //Note depth reversal.
                DepthComparison  = Comparison.Greater,
                IsStencilEnabled = false
            };

            opaqueDepthState           = new DepthStencilState(Surface.Device, opaqueDepthStencilDescription);
            opaqueDepthState.DebugName = "Opaque Depth State";

            var opaqueBlendStateDescription = BlendStateDescription.Default();

            opaqueBlendState           = new BlendState(Surface.Device, opaqueBlendStateDescription);
            opaqueBlendState.DebugName = "Opaque Blend State";

            var uiDepthStateDescription = new DepthStencilStateDescription
            {
                IsDepthEnabled = false,
                DepthWriteMask = DepthWriteMask.Zero,
                //Note depth reversal.
                DepthComparison  = Comparison.Greater,
                IsStencilEnabled = false
            };

            uiDepthState           = new DepthStencilState(Surface.Device, uiDepthStateDescription);
            uiDepthState.DebugName = "UI Depth State";

            //The UI will use premultiplied alpha.
            var uiBlendStateDescription = BlendStateDescription.Default();

            uiBlendStateDescription.RenderTarget[0].IsBlendEnabled        = true;
            uiBlendStateDescription.RenderTarget[0].SourceBlend           = BlendOption.One;
            uiBlendStateDescription.RenderTarget[0].SourceAlphaBlend      = BlendOption.One;
            uiBlendStateDescription.RenderTarget[0].DestinationBlend      = BlendOption.InverseSourceAlpha;
            uiBlendStateDescription.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseSourceAlpha;
            uiBlendStateDescription.RenderTarget[0].BlendOperation        = BlendOperation.Add;
            uiBlendStateDescription.RenderTarget[0].AlphaBlendOperation   = BlendOperation.Add;
            uiBlendStateDescription.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
            uiBlendState           = new BlendState(Surface.Device, uiBlendStateDescription);
            uiBlendState.DebugName = "UI Blend State";
        }
Beispiel #21
0
        public Renderer(RenderSurface surface)
        {
            looper  = new ParallelLooper();
            Surface = surface;
            using (var stream = GetType().Assembly.GetManifestResourceStream("DemoRenderer.DemoRenderer.shaderarchive"))
            {
                ShaderCache = ShaderCache.Load(stream);
            }
            pool             = new BufferPool();
            Shapes           = new ShapesExtractor(Surface.Device, looper, pool);
            SphereRenderer   = new RayTracedRenderer <SphereInstance>(surface.Device, ShaderCache, @"ShapeDrawing\RenderSpheres.hlsl");
            CapsuleRenderer  = new RayTracedRenderer <CapsuleInstance>(surface.Device, ShaderCache, @"ShapeDrawing\RenderCapsules.hlsl");
            BoxRenderer      = new BoxRenderer(surface.Device, ShaderCache);
            TriangleRenderer = new TriangleRenderer(surface.Device, ShaderCache);
            MeshRenderer     = new MeshRenderer(surface.Device, Shapes.MeshCache, ShaderCache);
            Lines            = new LineExtractor(pool, looper);
            LineRenderer     = new LineRenderer(surface.Device, ShaderCache);
            Background       = new BackgroundRenderer(surface.Device, ShaderCache);
            CompressToSwap   = new CompressToSwap(surface.Device, ShaderCache);

            GlyphRenderer  = new GlyphRenderer(surface.Device, surface.Context, ShaderCache);
            TextBatcher    = new TextBatcher();
            UILineRenderer = new UILineRenderer(surface.Device, ShaderCache);
            UILineBatcher  = new UILineBatcher();

            OnResize();
            var rasterizerStateDescription = RasterizerStateDescription.Default();

            rasterizerStateDescription.IsFrontCounterClockwise = true;
            rasterizerStateDescription.CullMode = CullMode.Back;
            rasterizerState           = new RasterizerState(Surface.Device, rasterizerStateDescription);
            rasterizerState.DebugName = "Default Rasterizer State";

            var opaqueDepthStencilDescription = new DepthStencilStateDescription
            {
                IsDepthEnabled = true,
                DepthWriteMask = DepthWriteMask.All,
                //Note depth reversal.
                DepthComparison  = Comparison.Greater,
                IsStencilEnabled = false
            };

            opaqueDepthState           = new DepthStencilState(Surface.Device, opaqueDepthStencilDescription);
            opaqueDepthState.DebugName = "Opaque Depth State";

            var opaqueBlendStateDescription = BlendStateDescription.Default();

            opaqueBlendState           = new BlendState(Surface.Device, opaqueBlendStateDescription);
            opaqueBlendState.DebugName = "Opaque Blend State";

            var a2cBlendStateDescription = BlendStateDescription.Default();

            a2cBlendStateDescription.AlphaToCoverageEnable = true;
            a2cBlendState           = new BlendState(Surface.Device, a2cBlendStateDescription);
            a2cBlendState.DebugName = "A2C Blend State";

            var uiDepthStateDescription = new DepthStencilStateDescription
            {
                IsDepthEnabled = false,
                DepthWriteMask = DepthWriteMask.Zero,
                //Note depth reversal.
                DepthComparison  = Comparison.Greater,
                IsStencilEnabled = false
            };

            uiDepthState           = new DepthStencilState(Surface.Device, uiDepthStateDescription);
            uiDepthState.DebugName = "UI Depth State";

            //The UI will use premultiplied alpha.
            var uiBlendStateDescription = BlendStateDescription.Default();

            uiBlendStateDescription.RenderTarget[0].IsBlendEnabled        = true;
            uiBlendStateDescription.RenderTarget[0].SourceBlend           = BlendOption.One;
            uiBlendStateDescription.RenderTarget[0].SourceAlphaBlend      = BlendOption.One;
            uiBlendStateDescription.RenderTarget[0].DestinationBlend      = BlendOption.InverseSourceAlpha;
            uiBlendStateDescription.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseSourceAlpha;
            uiBlendStateDescription.RenderTarget[0].BlendOperation        = BlendOperation.Add;
            uiBlendStateDescription.RenderTarget[0].AlphaBlendOperation   = BlendOperation.Add;
            uiBlendStateDescription.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
            uiBlendState           = new BlendState(Surface.Device, uiBlendStateDescription);
            uiBlendState.DebugName = "UI Blend State";
        }
Beispiel #22
0
 static FontAwesome()
 {
     _brands  = GlyphRenderer.LoadFontFamily(Deps.FontAwesome.FA.fa_brands_400);
     _regular = GlyphRenderer.LoadFontFamily(Deps.FontAwesome.FA.fa_regular_400);
     _solid   = GlyphRenderer.LoadFontFamily(Deps.FontAwesome.FA.fa_solid_900);
 }