コード例 #1
0
        public static void SetOpacity(float opacity)
        {
            if (Opacity == opacity)
            {
                return;
            }

            Sprite.End();

            if (opacity >= 1 || opacity < 0)
            {
                PipelineState.State.BlendState.AlphaToCoverageEnable               = false;
                PipelineState.State.BlendState.RenderTarget0.ColorSourceBlend      = Blend.SourceAlpha;
                PipelineState.State.BlendState.RenderTarget0.ColorDestinationBlend = Blend.InverseSourceAlpha;
                PipelineState.State.BlendState.RenderTarget0.AlphaSourceBlend      = Blend.One;
                GraphicsContext.CommandList.SetBlendFactor(Color4.White);
            }
            else
            {
                PipelineState.State.BlendState.AlphaToCoverageEnable               = true;
                PipelineState.State.BlendState.RenderTarget0.ColorSourceBlend      = Blend.BlendFactor;
                PipelineState.State.BlendState.RenderTarget0.ColorDestinationBlend = Blend.InverseBlendFactor;
                PipelineState.State.BlendState.RenderTarget0.AlphaSourceBlend      = Blend.SourceAlpha;
                GraphicsContext.CommandList.SetBlendFactor(new Color4(opacity));
            }
            UpdatePipelineState();

            Sprite.Begin(GraphicsContext, SpriteSortMode.Deferred, PipelineState.State.BlendState);

            Opacity = opacity;
        }
コード例 #2
0
        public static void SetBlend(bool value, float rate = 1F, Blend?colorSourceBlendOverride = null)
        {
            if (value == Blending)
            {
                return;
            }

            Blending  = value;
            BlendRate = 1F;

            Sprite.End();

            if (Blending)
            {
                PipelineState.State.BlendState.AlphaToCoverageEnable               = true;
                PipelineState.State.BlendState.RenderTarget0.ColorSourceBlend      = colorSourceBlendOverride ?? Blend.BlendFactor;
                PipelineState.State.BlendState.RenderTarget0.ColorDestinationBlend = Blend.One;
                GraphicsContext.CommandList.SetBlendFactor(new Color4(rate));
                UpdatePipelineState();

                Sprite.Begin(GraphicsContext, SpriteSortMode.Deferred, PipelineState.State.BlendState);
            }
            else
            {
                PipelineState.State.BlendState.RenderTarget0.ColorSourceBlend      = Blend.One;
                PipelineState.State.BlendState.RenderTarget0.ColorDestinationBlend = Blend.InverseSourceAlpha;

                GraphicsContext.CommandList.SetBlendFactor(Color4.White);
                UpdatePipelineState();

                Sprite.Begin(GraphicsContext, SpriteSortMode.Deferred, PipelineState.State.BlendState);
            }

            if (CurrentRenderTarget == null)
            {
                GraphicsContext.CommandList.SetRenderTarget(Device.Presenter.DepthStencilBuffer, Device.Presenter.BackBuffer);
            }
            else
            {
                GraphicsContext.CommandList.SetRenderTarget(Device.Presenter.DepthStencilBuffer, CurrentRenderTarget);
            }
        }
コード例 #3
0
        public static void SetRenderTarget(Texture renderTarget = null)
        {
            if (CurrentRenderTarget == renderTarget)
            {
                return;
            }

            Sprite.End();
            Sprite.Begin(GraphicsContext, SpriteSortMode.Deferred, PipelineState.State.BlendState);

            CurrentRenderTarget = renderTarget;

            if (renderTarget == null)
            {
                GraphicsContext.CommandList.SetRenderTarget(Device.Presenter.DepthStencilBuffer, Device.Presenter.BackBuffer);
            }
            else
            {
                GraphicsContext.CommandList.SetRenderTarget(Device.Presenter.DepthStencilBuffer, renderTarget);
            }
        }
コード例 #4
0
        public static void AttemptRecovery()
        {
            Sprite.End();

            GraphicsContext.CommandList.SetRenderTarget(Device.Presenter.DepthStencilBuffer, Device.Presenter.BackBuffer);
        }