Example #1
0
        protected override void AfterDraw(RendererBatch batch)
        {
            BlendState        = null;
            DepthStencilState = new DepthStencilState()
            {
                DepthBufferEnable = false,
                StencilEnable     = true,
                StencilFunction   = Reverse
                    ? CompareFunction.Equal
                    : CompareFunction.NotEqual,
                StencilPass      = StencilOperation.Keep,
                ReferenceStencil = 0
            };
            Effect = null;

            batch.Configure(BlendState, DepthStencilState, Effect, Matrix);
            batch.Begin();
            batch.DrawPrimitives(primitive =>
            {
                primitive.FillRectangle(
                    View.Location.ToVector2(),
                    View.Size.ToVector2(),
                    ClearColor);
            });
            batch.End();
        }
Example #2
0
        protected sealed override void Draw(RendererBatch batch)
        {
            if (Scene?.Entities == null)
            {
                return;
            }

            Scene.Entities.State = ManagerState.ThrowError;
            batch.Configure(BlendState, DepthStencilState, Effect, Matrix);
            batch.Begin();

            foreach (var entity in Scene.Entities.OnLayer(this))
            {
                if (entity.IsVisible)
                {
                    entity.DrawInternally(batch);
                }
            }

            batch.End();
            Scene.Entities.State = ManagerState.Opened;
        }
Example #3
0
        internal void Draw(
            DisplayAdapter display,
            RendererBatch batch,
            out RenderTarget2D renderTarget)
        {
            renderTarget = _renderTarget;

            var projection   = new Rectangle(Point.Zero, display.Size);
            var clearOptions = ClearOptions.Target
                               | ClearOptions.Stencil
                               | ClearOptions.DepthBuffer;

            display.GraphicsDevice.SetRenderTarget(renderTarget);
            display.GraphicsDevice.Viewport = new Viewport(projection);
            display.GraphicsDevice.Clear(clearOptions, ClearColor, 0, 0);

            BeforeDraw(batch);

            Entities.State = ManagerState.ThrowError;
            batch.Configure(transformMatrix: Camera.Matrix);
            batch.Begin();

            foreach (var entity in Entities.OnLayer(null))
            {
                if (entity.IsVisible)
                {
                    entity.DrawInternally(batch);
                }
            }

            batch.End();
            Entities.State = ManagerState.Opened;

            Layers.State = ManagerState.ThrowError;

            foreach (var layer in Layers)
            {
                display.GraphicsDevice.SetRenderTarget(layer.RenderTarget);
                display.GraphicsDevice.Clear(clearOptions, Color.Transparent, 0, 0);

                if (!layer.RenderBeforeMerge)
                {
                    batch.Sprite.Begin(samplerState: SamplerState.PointClamp);
                    batch.Sprite.Draw(renderTarget, Vector2.Zero, Color.White);
                    batch.Sprite.End();
                }

                if (layer.IsVisible)
                {
                    layer.DrawInternally(batch);
                }

                display.GraphicsDevice.SetRenderTarget(_backupRenderTarget);
                display.GraphicsDevice.Clear(clearOptions, Color.Transparent, 0, 0);

                if (layer.RenderBeforeMerge)
                {
                    batch.Sprite.Begin(samplerState: SamplerState.PointClamp);
                    batch.Sprite.Draw(renderTarget, Vector2.Zero, Color.White);
                    batch.Sprite.End();
                }

                batch.Sprite.Begin(
                    samplerState: SamplerState.PointClamp,
                    effect: layer.Effect);
                batch.Sprite.Draw(layer.RenderTarget, Vector2.Zero, layer.Color);
                batch.Sprite.End();

                display.GraphicsDevice.SetRenderTarget(layer.RenderTarget);
                display.GraphicsDevice.Clear(clearOptions, Color.Transparent, 0, 0);

                batch.Sprite.Begin(samplerState: SamplerState.PointClamp);
                batch.Sprite.Draw(_backupRenderTarget, Vector2.Zero, Color.White);
                batch.Sprite.End();

                renderTarget = layer.RenderTarget;
            }

            Layers.State = ManagerState.Opened;

            AfterDraw(batch);
        }