예제 #1
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();
        }
예제 #2
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";
        }
예제 #3
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";
        }