diff --git a/OpenRA.Game/Graphics/Sheet.cs b/OpenRA.Game/Graphics/Sheet.cs index e2d2874962..0c56c15bb2 100644 --- a/OpenRA.Game/Graphics/Sheet.cs +++ b/OpenRA.Game/Graphics/Sheet.cs @@ -18,7 +18,6 @@ namespace OpenRA.Graphics { public sealed class Sheet : IDisposable { - readonly object textureLock = new object(); bool dirty; bool releaseBufferOnCommit; ITexture texture; @@ -66,33 +65,21 @@ namespace OpenRA.Graphics public ITexture GetTexture() { - // This is only called from the main thread but 'dirty' - // is set from other threads too via CommitData(). - GenerateTexture(); - return texture; - } - - void GenerateTexture() - { - lock (textureLock) + if (texture == null) { - if (texture == null) - { - texture = Game.Renderer.Device.CreateTexture(); - dirty = true; - } - - if (data != null) - { - if (dirty) - { - texture.SetData(data, Size.Width, Size.Height); - dirty = false; - if (releaseBufferOnCommit) - data = null; - } - } + texture = Game.Renderer.Device.CreateTexture(); + dirty = true; } + + if (data != null && dirty) + { + texture.SetData(data, Size.Width, Size.Height); + dirty = false; + if (releaseBufferOnCommit) + data = null; + } + + return texture; } public Bitmap AsBitmap() @@ -141,42 +128,32 @@ namespace OpenRA.Graphics public void CreateBuffer() { - lock (textureLock) - { - if (data != null) - return; - if (texture == null) - data = new byte[4 * Size.Width * Size.Height]; - else - data = texture.GetData(); - releaseBufferOnCommit = false; - } + if (data != null) + return; + if (texture == null) + data = new byte[4 * Size.Width * Size.Height]; + else + data = texture.GetData(); + releaseBufferOnCommit = false; } - public void CommitData() + public void CommitBufferedData() { - CommitData(false); + if (!Buffered) + throw new InvalidOperationException( + "This sheet is unbuffered. You cannot call CommitBufferedData on an unbuffered sheet. " + + "If you need to completely replace the texture data you should set data into the texture directly. " + + "If you need to make only small changes to the texture data consider creating a buffered sheet instead."); + + dirty = true; } public void ReleaseBuffer() { - CommitData(true); - } - - void CommitData(bool releaseBuffer) - { - lock (textureLock) - { - if (!Buffered) - throw new InvalidOperationException( - "This sheet is unbuffered. You cannot call CommitData on an unbuffered sheet. " + - "If you need to completely replace the texture data you should set data into the texture directly. " + - "If you need to make only small changes to the texture data consider creating a buffered sheet instead."); - - dirty = true; - if (releaseBuffer) - releaseBufferOnCommit = true; - } + if (!Buffered) + return; + dirty = true; + releaseBufferOnCommit = true; } public void Dispose() diff --git a/OpenRA.Game/Graphics/SheetBuilder.cs b/OpenRA.Game/Graphics/SheetBuilder.cs index 5817f91f53..d4e0d859aa 100644 --- a/OpenRA.Game/Graphics/SheetBuilder.cs +++ b/OpenRA.Game/Graphics/SheetBuilder.cs @@ -70,7 +70,7 @@ namespace OpenRA.Graphics var rect = Allocate(size, spriteOffset); Util.FastCopyIntoChannel(rect, src); - current.CommitData(); + current.CommitBufferedData(); return rect; } @@ -78,7 +78,7 @@ namespace OpenRA.Graphics { var rect = Allocate(src.Size); Util.FastCopyIntoSprite(rect, src); - current.CommitData(); + current.CommitBufferedData(); return rect; } diff --git a/OpenRA.Game/Graphics/SpriteFont.cs b/OpenRA.Game/Graphics/SpriteFont.cs index 5f796831e7..8a3c8857c3 100644 --- a/OpenRA.Game/Graphics/SpriteFont.cs +++ b/OpenRA.Game/Graphics/SpriteFont.cs @@ -136,7 +136,7 @@ namespace OpenRA.Graphics } } - s.Sheet.CommitData(); + s.Sheet.CommitBufferedData(); return g; } diff --git a/OpenRA.Game/Graphics/VoxelLoader.cs b/OpenRA.Game/Graphics/VoxelLoader.cs index f2677ddec1..8cc81fe017 100644 --- a/OpenRA.Game/Graphics/VoxelLoader.cs +++ b/OpenRA.Game/Graphics/VoxelLoader.cs @@ -86,7 +86,7 @@ namespace OpenRA.Graphics var s = sheetBuilder.Allocate(new Size(su, sv)); Util.FastCopyIntoChannel(s, 0, colors); Util.FastCopyIntoChannel(s, 1, normals); - s.Sheet.CommitData(); + s.Sheet.CommitBufferedData(); var channelP = ChannelSelect[(int)s.Channel]; var channelC = ChannelSelect[(int)s.Channel + 1]; diff --git a/OpenRA.Mods.Common/Widgets/RadarWidget.cs b/OpenRA.Mods.Common/Widgets/RadarWidget.cs index 99f9ff6f71..81c5f0aab7 100644 --- a/OpenRA.Mods.Common/Widgets/RadarWidget.cs +++ b/OpenRA.Mods.Common/Widgets/RadarWidget.cs @@ -216,7 +216,7 @@ namespace OpenRA.Mods.Common.Widgets dirtyShroudCells.Clear(); } - radarSheet.CommitData(); + radarSheet.CommitBufferedData(); var o = new float2(mapRect.Location.X, mapRect.Location.Y + world.Map.Bounds.Height * previewScale * (1 - radarMinimapHeight) / 2); var s = new float2(mapRect.Size.Width, mapRect.Size.Height * radarMinimapHeight);