Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batcher: Removed half pixel offset calculation. #846

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Nez.Portable/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public Core(int width = 1280, int height = 720, bool isFullScreen = false, strin
SynchronizeWithVerticalRetrace = true,
#if MONOGAME_38
HardwareModeSwitch = hardwareModeSwitch,
PreferHalfPixelOffset = true
PreferHalfPixelOffset = false
#endif
};
graphicsManager.DeviceReset += OnGraphicsDeviceReset;
Expand Down
26 changes: 5 additions & 21 deletions Nez.Portable/Graphics/Batcher/Batcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ public class Batcher : GraphicsResource


#region static variables and constants

/// if true, the older FNA half-pixel offset will be used when creating the ortho matrix. Autoset to true for FNA.
public static bool UseFnaHalfPixelMatrix = false;


const int MAX_SPRITES = 2048;
const int MAX_VERTICES = MAX_SPRITES * 4;
const int MAX_INDICES = MAX_SPRITES * 6;
Expand All @@ -83,10 +80,6 @@ public class Batcher : GraphicsResource
static readonly short[] _indexData = GenerateIndexArray();

#endregion

#if FNA
static Batcher() => UseFnaHalfPixelMatrix = true;
#endif

public Batcher(GraphicsDevice graphicsDevice)
{
Expand Down Expand Up @@ -1065,19 +1058,10 @@ void PrepRenderState()
var viewport = GraphicsDevice.Viewport;

// inlined CreateOrthographicOffCenter
if (UseFnaHalfPixelMatrix)
{
_projectionMatrix.M11 = (float)(2.0 / (double)(viewport.Width / 2 * 2 - 1));
_projectionMatrix.M22 = (float)(-2.0 / (double)(viewport.Height / 2 * 2 - 1));
}
else
{
_projectionMatrix.M11 = (float)(2.0 / (double)viewport.Width);
_projectionMatrix.M22 = (float)(-2.0 / (double)viewport.Height);
}

_projectionMatrix.M41 = -1 - 0.5f * _projectionMatrix.M11;
_projectionMatrix.M42 = 1 - 0.5f * _projectionMatrix.M22;
_projectionMatrix.M11 = (float)(2.0 / (double)viewport.Width);
_projectionMatrix.M22 = (float)(-2.0 / (double)viewport.Height);
_projectionMatrix.M41 = -1;
_projectionMatrix.M42 = 1;

Matrix.Multiply(ref _transformMatrix, ref _projectionMatrix, out _matrixTransformMatrix);
_spriteEffect.SetMatrixTransform(ref _matrixTransformMatrix);
Expand Down