PushRenderStates() public method

public PushRenderStates ( SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix transformMatrix, Rectangle scissorRectangle ) : void
sortMode SpriteSortMode
blendState Microsoft.Xna.Framework.Graphics.BlendState
samplerState Microsoft.Xna.Framework.Graphics.SamplerState
depthStencilState Microsoft.Xna.Framework.Graphics.DepthStencilState
rasterizerState Microsoft.Xna.Framework.Graphics.RasterizerState
effect Microsoft.Xna.Framework.Graphics.Effect
transformMatrix Matrix
scissorRectangle Microsoft.Xna.Framework.Rectangle
return void
Beispiel #1
0
        public void BeginSpriteBatch(RenderStateVariables renderStates, Layer layer, BeginType beginType, Camera camera)
        {
            Matrix matrix = GetZoomAndMatrix(layer, camera);

            SamplerState samplerState = GetSamplerState(renderStates);


            bool isFullscreen = renderStates.ClipRectangle == null;

            RasterizerState rasterizerState;

            if (isFullscreen)
            {
                rasterizerState = scissorTestDisabled;
            }
            else
            {
                rasterizerState = scissorTestEnabled;
            }


            Rectangle scissorRectangle = new Rectangle();

            if (rasterizerState.ScissorTestEnable)
            {
                scissorRectangle = renderStates.ClipRectangle.Value;

                // make sure values of with and height are never less than 0:
                if (scissorRectangle.Width < 0)
                {
                    scissorRectangle.Width = 0;
                }
                if (scissorRectangle.Height < 0)
                {
                    scissorRectangle.Height = 0;
                }
            }


            DepthStencilState depthStencilState = DepthStencilState.DepthRead;

            if (beginType == BeginType.Begin)
            {
                mSpriteBatch.ReplaceRenderStates(SpriteSortMode.Immediate, renderStates.BlendState,
                                                 samplerState,
                                                 depthStencilState,
                                                 rasterizerState,
                                                 null, matrix,
                                                 scissorRectangle);
            }
            else
            {
                mSpriteBatch.PushRenderStates(SpriteSortMode.Immediate, renderStates.BlendState,
                                              samplerState,
                                              depthStencilState,
                                              rasterizerState,
                                              null, matrix,
                                              scissorRectangle);
            }
        }
Beispiel #2
0
        public void BeginSpriteBatch(RenderStateVariables renderStates, Layer layer, BeginType beginType, Camera camera)
        {
            Matrix matrix = Renderer.UseBasicEffectRendering ?
                            Matrix.Identity : GetZoomAndMatrix(layer, camera);

            SamplerState samplerState = GetSamplerState(renderStates);


            bool isFullscreen = renderStates.ClipRectangle == null;

            RasterizerState rasterizerState;

            if (isFullscreen)
            {
                rasterizerState = scissorTestDisabled;
            }
            else
            {
                rasterizerState = scissorTestEnabled;
            }


            Rectangle scissorRectangle = new Rectangle();

            if (rasterizerState.ScissorTestEnable)
            {
                scissorRectangle = renderStates.ClipRectangle.Value;

                // make sure values of with and height are never less than 0:
                if (scissorRectangle.Width < 0)
                {
                    scissorRectangle.Width = 0;
                }
                if (scissorRectangle.Height < 0)
                {
                    scissorRectangle.Height = 0;
                }
            }


            DepthStencilState depthStencilState = DepthStencilState.DepthRead;

            var width  = camera.ClientWidth;
            var height = camera.ClientHeight;

            BasicEffect effectiveEffect = null;

            if (Renderer.UseBasicEffectRendering)
            {
                if (Renderer.ApplyCameraZoomOnWorldTranslation)
                {
                    basicEffect.World = Matrix.CreateTranslation(
                        -width / (2f * camera.Zoom),
                        -height / (2f * camera.Zoom),
                        0);
                }
                else
                {
                    basicEffect.World = Matrix.CreateTranslation(
                        -width / (2f),
                        -height / (2f),
                        0);
                }
                //effect.Projection = Matrix.CreateOrthographic(100, 100, 0.0001f, 1000);
                basicEffect.Projection = Matrix.CreateOrthographic(
                    width,
                    -height,
                    -1, 1);

                basicEffect.View =
                    GetZoomAndMatrix(layer, camera);

                effectiveEffect =
                    Renderer.UseBasicEffectRendering ? basicEffect : null;
            }

            switch (renderStates.ColorOperation)
            {
            case ColorOperation.ColorTextureAlpha:
                basicEffect.TextureEnabled     = true;
                basicEffect.VertexColorEnabled = true;

                // Since MonoGame doesn't use custom shaders, we have to hack this
                // using Fog. It works...but it's slow and introduces a lot of render breaks.
                // At some point in the future we should try to fix this.
                basicEffect.FogEnabled = true;
                basicEffect.FogStart   = 0;
                basicEffect.FogEnd     = 0;
                break;

            case ColorOperation.Modulate:

                basicEffect.VertexColorEnabled = true;

                basicEffect.FogEnabled     = false;
                basicEffect.TextureEnabled = true;
                break;
            }


            if (beginType == BeginType.Begin)
            {
                mSpriteBatch.ReplaceRenderStates(SpriteSortMode.Immediate,
                                                 renderStates.BlendState,
                                                 samplerState,
                                                 depthStencilState,
                                                 rasterizerState,
                                                 effectiveEffect,
                                                 matrix,
                                                 scissorRectangle);
            }
            else
            {
                mSpriteBatch.PushRenderStates(SpriteSortMode.Immediate,
                                              renderStates.BlendState,
                                              samplerState,
                                              depthStencilState,
                                              rasterizerState,
                                              effectiveEffect,
                                              matrix,
                                              scissorRectangle);
            }
        }