Made Sheet.Texture into Sheet.GetTexture() since we will want to call it for side-effects.

Do the same for Sheet.Data since it has the side effect of generating a buffer.
This commit is contained in:
RoosterDragon
2014-10-14 17:02:48 +01:00
committed by RoosterDragon
parent ff16690b86
commit a6f5a21ed4
9 changed files with 25 additions and 31 deletions

View File

@@ -25,10 +25,8 @@ namespace OpenRA.Graphics
byte[] data;
public readonly Size Size;
public byte[] Data
public byte[] GetData()
{
get
{
if (data != null)
return data;
if (texture == null)
@@ -36,8 +34,7 @@ namespace OpenRA.Graphics
else
data = texture.GetData();
releaseBufferOnCommit = false;
return data;
}
return data;
}
public bool Buffered { get { return data != null || texture == null; } }
@@ -72,15 +69,12 @@ namespace OpenRA.Graphics
ReleaseBuffer();
}
public ITexture Texture
public ITexture GetTexture()
{
// This is only called from the main thread but 'dirty'
// is set from other threads too via CommitData().
get
{
GenerateTexture();
return texture;
}
GenerateTexture();
return texture;
}
void GenerateTexture()
@@ -108,7 +102,7 @@ namespace OpenRA.Graphics
public Bitmap AsBitmap()
{
var d = Data;
var d = GetData();
var dataStride = 4 * Size.Width;
var bitmap = new Bitmap(Size.Width, Size.Height);
@@ -123,7 +117,7 @@ namespace OpenRA.Graphics
public Bitmap AsBitmap(TextureChannel channel, IPalette pal)
{
var d = Data;
var d = GetData();
var dataStride = 4 * Size.Width;
var bitmap = new Bitmap(Size.Width, Size.Height);
var channelOffset = (int)channel;

View File

@@ -118,7 +118,7 @@ namespace OpenRA.Graphics
unsafe
{
var p = (byte*)bitmap.Buffer;
var dest = s.sheet.Data;
var dest = s.sheet.GetData();
var destStride = s.sheet.Size.Width * 4;
for (var j = 0; j < s.size.Y; j++)

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Graphics
{
if (nv > 0)
{
shader.SetTexture("DiffuseTexture", currentSheet.Texture);
shader.SetTexture("DiffuseTexture", currentSheet.GetTexture());
renderer.Device.SetBlendMode(currentBlend);
shader.Render(() =>
@@ -109,7 +109,7 @@ namespace OpenRA.Graphics
public void DrawVertexBuffer(IVertexBuffer<Vertex> buffer, int start, int length, PrimitiveType type, Sheet sheet)
{
shader.SetTexture("DiffuseTexture", sheet.Texture);
shader.SetTexture("DiffuseTexture", sheet.GetTexture());
renderer.Device.SetBlendMode(BlendMode.Alpha);
shader.Render(() => renderer.DrawBatch(buffer, start, length, type));
renderer.Device.SetBlendMode(BlendMode.None);

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Graphics
public static void FastCopyIntoChannel(Sprite dest, byte[] src) { FastCopyIntoChannel(dest, 0, src); }
public static void FastCopyIntoChannel(Sprite dest, int channelOffset, byte[] src)
{
var data = dest.sheet.Data;
var data = dest.sheet.GetData();
var srcStride = dest.bounds.Width;
var destStride = dest.sheet.Size.Width * 4;
var destOffset = destStride * dest.bounds.Top + dest.bounds.Left * 4 + channelMasks[(int)dest.channel + channelOffset];
@@ -64,7 +64,7 @@ namespace OpenRA.Graphics
public static void FastCopyIntoSprite(Sprite dest, Bitmap src)
{
var data = dest.sheet.Data;
var data = dest.sheet.GetData();
var dataStride = dest.sheet.Size.Width * 4;
var x = dest.bounds.Left * 4;
var width = dest.bounds.Width * 4;

View File

@@ -257,7 +257,7 @@ namespace OpenRA.Graphics
float[] ambientLight, float[] diffuseLight,
int colorPalette, int normalsPalette)
{
shader.SetTexture("DiffuseTexture", renderData.Sheet.Texture);
shader.SetTexture("DiffuseTexture", renderData.Sheet.GetTexture());
shader.SetVec("PaletteRows", (colorPalette + 0.5f) / HardwarePalette.MaxPalettes,
(normalsPalette + 0.5f) / HardwarePalette.MaxPalettes);
shader.SetMatrix("TransformMatrix", t);