Skip to content

Commit

Permalink
Merge pull request #5456 from nkast/tnc_SpriteBatch_transformMatrix
Browse files Browse the repository at this point in the history
SpriteBatch Begin/End. Do not Multiply with Identity when transformMatrix is null
  • Loading branch information
tomspilman committed Feb 4, 2017
2 parents aac29ca + 4877b85 commit e155a38
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions MonoGame.Framework/Graphics/SpriteBatch.cs
Expand Up @@ -27,7 +27,7 @@ public class SpriteBatch : GraphicsResource
readonly EffectParameter _matrixTransform;
readonly EffectPass _spritePass;

Matrix _matrix;
Matrix? _matrix;
Rectangle _tempRect = new Rectangle (0,0,0,0);
Vector2 _texCoordTL = new Vector2 (0,0);
Vector2 _texCoordBR = new Vector2 (0,0);
Expand Down Expand Up @@ -93,7 +93,7 @@ public void Begin
_depthStencilState = depthStencilState ?? DepthStencilState.None;
_rasterizerState = rasterizerState ?? RasterizerState.CullCounterClockwise;
_effect = effect;
_matrix = transformMatrix ?? Matrix.Identity;
_matrix = transformMatrix;

// Setup things now so a user can change them.
if (sortMode == SpriteSortMode.Immediate)
Expand Down Expand Up @@ -143,7 +143,11 @@ void Setup()
projection.M42 += -0.5f * projection.M22;
}

Matrix.Multiply(ref _matrix, ref projection, out projection);
if (_matrix.HasValue)
{
var transformMatrix = _matrix.GetValueOrDefault();
Matrix.Multiply(ref transformMatrix, ref projection, out projection);
}

_matrixTransform.SetValue(projection);
_spritePass.Apply();
Expand Down

0 comments on commit e155a38

Please sign in to comment.