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(); } }
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); }
void TryEnd() { if (mLastParameters != null) { End(); mLastParameters = null; } }
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); }
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(); } }
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(); }
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(); }
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; } }
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(); }
internal void ClearPerformanceRecordingVariables() { currentParameters = null; beginParametersUsedThisFrame.Clear(); }
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; } }
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); }