diff --git a/Graphics/Renderers/RendererManager.cs b/Graphics/Renderers/RendererManager.cs index 94541b4e7b..f3019bea4a 100644 --- a/Graphics/Renderers/RendererManager.cs +++ b/Graphics/Renderers/RendererManager.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using CalamityMod.Enums; +using CalamityMod.Utilities.Daybreak; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -88,9 +89,17 @@ namespace CalamityMod.Graphics.Renderers if (!renderer.ShouldDraw) continue; - var matrix = Main.GameViewMatrix.TransformationMatrix; - using (new CalamityUtils.SpritebatchScope(Main.spriteBatch, SpriteSortMode.Deferred, BatchSetting.AlphaBlend, null, matrix, true)) + using (Main.spriteBatch.Scope()) { + Main.spriteBatch.Begin( + SpriteSortMode.Deferred, + BlendState.AlphaBlend, + SamplerState.PointClamp, + DepthStencilState.None, + Main.Rasterizer, + null, + Main.GameViewMatrix.TransformationMatrix + ); renderer.MainTarget.SwapTo(Color.Transparent); renderer.DrawToTarget(Main.spriteBatch); } diff --git a/ILEditing/MechanicILChanges.cs b/ILEditing/MechanicILChanges.cs index c2764c3ad2..7843559592 100644 --- a/ILEditing/MechanicILChanges.cs +++ b/ILEditing/MechanicILChanges.cs @@ -30,6 +30,7 @@ using CalamityMod.Systems; using CalamityMod.Systems.Graphic.PixelationSystem; using CalamityMod.Systems.Mechanic; using CalamityMod.Tiles; +using CalamityMod.Utilities.Daybreak; using CalamityMod.Walls; using CalamityMod.Walls.UnsafeWalls; using CalamityMod.Waterfalls; diff --git a/Systems/TileMerging/TileBlendTexture_Baking.cs b/Systems/TileMerging/TileBlendTexture_Baking.cs index 1209b8c1cc..21cdafefbf 100644 --- a/Systems/TileMerging/TileBlendTexture_Baking.cs +++ b/Systems/TileMerging/TileBlendTexture_Baking.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using CalamityMod.Utilities.Daybreak; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -35,8 +36,18 @@ namespace CalamityMod.Systems graphicsDevice.Clear(Color.Transparent); - using (new CalamityUtils.SpritebatchScope(Main.spriteBatch, SpriteSortMode.Immediate, BatchSetting.AlphaBlend, null, Matrix.Identity)) + using (Main.spriteBatch.Scope()) { + Main.spriteBatch.Begin( + SpriteSortMode.Immediate, + BlendState.AlphaBlend, + SamplerState.PointClamp, + DepthStencilState.None, + Main.Rasterizer, + null, + Matrix.Identity + ); + for (int i = 0; i < 256; i++) { var drawPos = SideFlagsToPositionInSheet((byte)i); @@ -58,6 +69,8 @@ namespace CalamityMod.Systems } } } + + Main.spriteBatch.End(); } // TODO: [SAFEACTION] bandaid fix diff --git a/Utilities/Daybreak/SpriteBatchScope.cs b/Utilities/Daybreak/SpriteBatchScope.cs index 36430fb2bc..161d7ee583 100644 --- a/Utilities/Daybreak/SpriteBatchScope.cs +++ b/Utilities/Daybreak/SpriteBatchScope.cs @@ -40,11 +40,6 @@ internal readonly struct SpriteBatchScope : IDisposable /// public void Dispose() { - if (spriteBatch.beginCalled) - { - spriteBatch.End(); - } - if (oldState.HasValue) { spriteBatch.Begin(oldState.Value); diff --git a/Utilities/DrawingUtils.BatchSetting.cs b/Utilities/DrawingUtils.BatchSetting.cs index 5b0fd2da15..ef5962c1ce 100644 --- a/Utilities/DrawingUtils.BatchSetting.cs +++ b/Utilities/DrawingUtils.BatchSetting.cs @@ -1,7 +1,9 @@ -using Microsoft.Xna.Framework.Graphics; +using System; +using Microsoft.Xna.Framework.Graphics; namespace CalamityMod { + [Obsolete("Use SpriteBatchParameters/SpriteBatchSnapshot")] public class BatchSetting(BlendState blend, SamplerState sampler, DepthStencilState depthStencil, RasterizerState rasterizer) { public readonly BlendState blendState = blend; diff --git a/Utilities/DrawingUtils.SpriteBatch.cs b/Utilities/DrawingUtils.SpriteBatch.cs index 96df255246..0f034177ae 100644 --- a/Utilities/DrawingUtils.SpriteBatch.cs +++ b/Utilities/DrawingUtils.SpriteBatch.cs @@ -1,5 +1,6 @@ using System; using System.Reflection; +using CalamityMod.Utilities.Daybreak; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -51,12 +52,11 @@ namespace CalamityMod if (spriteBatch is null) return; - spriteBatch.GetParameters(out var parameters); - spriteBatch.End(); + spriteBatch.End(out var ss); spriteBatch.Begin(sortMode, settings.blendState, settings.samplerState, settings.depthStencilState, settings.rasterizerState ?? Main.Rasterizer, effect, transformMatrix); batchCallback?.Invoke(); - spriteBatch.Restart(parameters); + spriteBatch.Restart(ss); } [Obsolete("This is violative of spritebatch's control flow and will eventually be removed")]