예제 #1
0
        public void PopRenderStates()
        {
            var parameters = mStateStack.Last();

            mStateStack.RemoveAt(mStateStack.Count - 1);


            if (parameters.HasValue)
            {
                ReplaceRenderStates(parameters.Value.SortMode, parameters.Value.BlendState,
                                    parameters.Value.SamplerState, parameters.Value.DepthStencilState,
                                    parameters.Value.RasterizerState, parameters.Value.Effect,
                                    parameters.Value.TransformMatrix, parameters.Value.ScissorRectangle);
            }
            else
            {
                if (currentParameters != null)
                {
                    beginParametersUsedThisFrame.Add(currentParameters.Value);
                }
                // this is the end
                currentParameters = null;
                End();
            }
        }
예제 #2
0
        public void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState,
                          DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix transformMatrix,
                          Rectangle scissorRectangle)
        {
            bool isNewRender = mLastParameters.HasValue == false;

            var newParameters = new BeginParameters();

            newParameters.SortMode          = sortMode;
            newParameters.BlendState        = blendState;
            newParameters.SamplerState      = samplerState;
            newParameters.DepthStencilState = depthStencilState;
            newParameters.RasterizerState   = rasterizerState;
            newParameters.Effect            = effect;
            newParameters.TransformMatrix   = transformMatrix;
            newParameters.ScissorRectangle  = scissorRectangle;

            mLastParameters = newParameters;

            if (!isNewRender)
            {
                SpriteBatch.End();
            }

            SpriteBatch.GraphicsDevice.ScissorRectangle = scissorRectangle;

            SpriteBatch.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, transformMatrix);
        }
예제 #3
0
 void TryEnd()
 {
     if (mLastParameters != null)
     {
         End();
         mLastParameters = null;
     }
 }
예제 #4
0
        public void ReplaceRenderStates(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState,
                                        DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix transformMatrix,
                                        Rectangle scissorRectangle)
        {
            bool isNewRender = currentParameters.HasValue == false;

            var newParameters = new BeginParameters();

            newParameters.ChangeRecord = StateChangeInfoListPool.GetNextAvailable();
            newParameters.ChangeRecord.Clear();

            newParameters.SortMode          = sortMode;
            newParameters.BlendState        = blendState;
            newParameters.SamplerState      = samplerState;
            newParameters.DepthStencilState = depthStencilState;
            newParameters.RasterizerState   = rasterizerState;
            newParameters.Effect            = effect;
            newParameters.TransformMatrix   = transformMatrix;

            try
            {
                newParameters.ScissorRectangle = scissorRectangle;
            }
            catch (Exception e)
            {
                throw new Exception("Could not set scissor rectangle to:" + scissorRectangle.ToString(), e);
            }
            if (currentParameters != null)
            {
                beginParametersUsedThisFrame.Add(currentParameters.Value);
            }

            currentParameters = newParameters;

            if (beginEndState == SpriteBatchBeginEndState.Began)
            {
                SpriteBatch.End();
            }

            try
            {
                SpriteBatch.GraphicsDevice.ScissorRectangle = scissorRectangle;
            }
            catch (Exception e)
            {
                throw new Exception("Error trying to set scissor rectangle:" + scissorRectangle.ToString());
            }
            beginEndState = SpriteBatchBeginEndState.Began;
            SpriteBatch.Begin(sortMode,
                              blendState,
                              samplerState, depthStencilState, rasterizerState, effect, transformMatrix);
        }
예제 #5
0
        public void Pop()
        {
            mLastParameters = mStateStack.Last();
            mStateStack.RemoveAt(mStateStack.Count - 1);


            if (mLastParameters.HasValue)
            {
                Begin(mLastParameters.Value.SortMode, mLastParameters.Value.BlendState, mLastParameters.Value.SamplerState, mLastParameters.Value.DepthStencilState,
                      mLastParameters.Value.RasterizerState, mLastParameters.Value.Effect, mLastParameters.Value.TransformMatrix, mLastParameters.Value.ScissorRectangle);
            }
            else
            {
                // this is the end
                End();
            }
        }
예제 #6
0
        public void Begin()
        {
            var beginParams = new BeginParameters();

            beginParams.ChangeRecord = new List <StateChangeInfo>();

            beginParams.IsDefault = true;
            currentParameters     = beginParams;

            if (beginEndState == SpriteBatchBeginEndState.Began)
            {
                SpriteBatch.End();
            }

            beginEndState = SpriteBatchBeginEndState.Began;
            SpriteBatch.Begin();
        }
예제 #7
0
        public void Begin()
        {
            var beginParams = new BeginParameters();

            beginParams.ChangeRecord = StateChangeInfoListPool.GetNextAvailable();
            beginParams.ChangeRecord.Clear();

            beginParams.IsDefault = true;
            currentParameters     = beginParams;

            if (beginEndState == SpriteBatchBeginEndState.Began)
            {
                SpriteBatch.End();
            }

            beginEndState = SpriteBatchBeginEndState.Began;
            SpriteBatch.Begin();
        }
예제 #8
0
        private void AdjustCurrentParametersDrawCall(Texture2D texture, SpriteFont spriteFont, object objectRequestingChange)
        {
            var paramsValue = currentParameters.Value;

            bool shouldRecordChange = paramsValue.ChangeRecord.Count == 0;

            if (!shouldRecordChange)
            {
                var last = paramsValue.ChangeRecord.Last();

                shouldRecordChange = last.Texture != texture || last.SpriteFont != spriteFont;
            }

            if (shouldRecordChange)
            {
                var newChange = new StateChangeInfo();
                newChange.Texture                = texture;
                newChange.SpriteFont             = spriteFont;
                newChange.ObjectRequestingChange = objectRequestingChange;

                paramsValue.ChangeRecord.Add(newChange);
                currentParameters = paramsValue;
            }
        }
예제 #9
0
        public void Begin()
        {
            var beginParams = new BeginParameters();
            beginParams.ChangeRecord = new List<StateChangeInfo>();

            beginParams.IsDefault = true;
            currentParameters = beginParams;

            if (beginEndState == SpriteBatchBeginEndState.Began)
            {
                SpriteBatch.End();
            }

            beginEndState = SpriteBatchBeginEndState.Began;
            SpriteBatch.Begin();
        }
예제 #10
0
        public void Pop()
        {
            mLastParameters = mStateStack.Last();
            mStateStack.RemoveAt(mStateStack.Count - 1);

            if (mLastParameters.HasValue)
            {
                Begin(mLastParameters.Value.SortMode, mLastParameters.Value.BlendState, mLastParameters.Value.SamplerState, mLastParameters.Value.DepthStencilState,
                    mLastParameters.Value.RasterizerState, mLastParameters.Value.Effect, mLastParameters.Value.TransformMatrix, mLastParameters.Value.ScissorRectangle);
            }
            else
            {
                // this is the end
                End();
            }
        }
예제 #11
0
        public void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState,
            DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix transformMatrix,
            Rectangle scissorRectangle)
        {
            bool isNewRender = mLastParameters.HasValue == false;

            var newParameters = new BeginParameters();

            newParameters.SortMode = sortMode;
            newParameters.BlendState = blendState;
            newParameters.SamplerState = samplerState;
            newParameters.DepthStencilState = depthStencilState;
            newParameters.RasterizerState = rasterizerState;
            newParameters.Effect = effect;
            newParameters.TransformMatrix = transformMatrix;
            newParameters.ScissorRectangle = scissorRectangle;

            mLastParameters = newParameters;

            if (!isNewRender)
            {
                SpriteBatch.End();
            }

            SpriteBatch.GraphicsDevice.ScissorRectangle = scissorRectangle;

            SpriteBatch.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, transformMatrix);
        }
예제 #12
0
 internal void ClearPerformanceRecordingVariables()
 {
     currentParameters = null;
     beginParametersUsedThisFrame.Clear();
 }
예제 #13
0
        public void PopRenderStates()
        {

            var parameters = mStateStack.Last();
            mStateStack.RemoveAt(mStateStack.Count - 1);


            if (parameters.HasValue)
            {
                ReplaceRenderStates(parameters.Value.SortMode, parameters.Value.BlendState,
                    parameters.Value.SamplerState, parameters.Value.DepthStencilState,
                    parameters.Value.RasterizerState, parameters.Value.Effect,
                    parameters.Value.TransformMatrix, parameters.Value.ScissorRectangle);
            }
            else
            {
                if (currentParameters != null)
                {
                    beginParametersUsedThisFrame.Add(currentParameters.Value);
                }
                // this is the end
                currentParameters = null;
                End();
            }
        }
예제 #14
0
        private void AdjustCurrentParametersDrawCall(Texture2D texture, SpriteFont spriteFont, object objectRequestingChange)
        {
            var paramsValue = currentParameters.Value;

            bool shouldRecordChange = paramsValue.ChangeRecord.Count == 0;

            if(!shouldRecordChange)
            {
                var last = paramsValue.ChangeRecord.Last();

                shouldRecordChange = last.Texture != texture || last.SpriteFont != spriteFont;
            }

            if (shouldRecordChange)
            {
                var newChange = new StateChangeInfo();
                newChange.Texture = texture;
                newChange.SpriteFont = spriteFont;
                newChange.ObjectRequestingChange = objectRequestingChange;

                paramsValue.ChangeRecord.Add(newChange);
                currentParameters = paramsValue;
            }
        }
예제 #15
0
        public void ReplaceRenderStates(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState,
            DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix transformMatrix,
            Rectangle scissorRectangle)
        {
            bool isNewRender = currentParameters.HasValue == false;

            var newParameters = new BeginParameters();
            newParameters.ChangeRecord = new List<StateChangeInfo>();

            newParameters.SortMode = sortMode;
            newParameters.BlendState = blendState;
            newParameters.SamplerState = samplerState;
            newParameters.DepthStencilState = depthStencilState;
            newParameters.RasterizerState = rasterizerState;
            newParameters.Effect = effect;
            newParameters.TransformMatrix = transformMatrix;

            try
            {
                newParameters.ScissorRectangle = scissorRectangle;
            }
            catch(Exception e)
            {
                throw new Exception("Could not set scissor rectangle to:" + scissorRectangle.ToString(), e);
            }
            if (currentParameters != null)
            {
                beginParametersUsedThisFrame.Add(currentParameters.Value);
            }

            currentParameters = newParameters;

            if (beginEndState == SpriteBatchBeginEndState.Began)
            {
                SpriteBatch.End();
            }

            try
            {
                SpriteBatch.GraphicsDevice.ScissorRectangle = scissorRectangle;
            }
            catch(Exception e)
            {
                throw new Exception("Error trying to set scissor rectangle:" + scissorRectangle.ToString());
            }
            beginEndState = SpriteBatchBeginEndState.Began;
            SpriteBatch.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, transformMatrix);

        }
예제 #16
0
 internal void ClearPerformanceRecordingVariables()
 {
     currentParameters = null;
     beginParametersUsedThisFrame.Clear();
 }
예제 #17
0
 void TryEnd()
 {
     if (mLastParameters != null)
     {
         End();
         mLastParameters = null;
     }
 }