Regenerate cached texture indices when the palette size changes.

This commit is contained in:
Paul Chote
2015-05-10 00:58:10 +01:00
parent 7eae157ad8
commit 889360d4c6
3 changed files with 37 additions and 12 deletions

View File

@@ -17,7 +17,6 @@ namespace OpenRA.Graphics
{
readonly IVertexBuffer<Vertex> vertexBuffer;
readonly Vertex[] updateCellVertices = new Vertex[4];
readonly float terrainPaletteIndex;
readonly int rowStride;
readonly WorldRenderer worldRenderer;
@@ -25,6 +24,8 @@ namespace OpenRA.Graphics
readonly CellLayer<TerrainTile> mapTiles;
readonly Map map;
float terrainPaletteIndex;
public TerrainRenderer(World world, WorldRenderer wr)
{
worldRenderer = wr;
@@ -34,21 +35,18 @@ namespace OpenRA.Graphics
terrainPaletteIndex = wr.Palette("terrain").TextureIndex;
rowStride = 4 * map.Bounds.Width;
vertexBuffer = Game.Renderer.Device.CreateVertexBuffer(rowStride * map.Bounds.Height);
var vertices = new Vertex[rowStride * map.Bounds.Height];
vertexBuffer = Game.Renderer.Device.CreateVertexBuffer(vertices.Length);
var nv = 0;
foreach (var cell in map.Cells)
{
GenerateTileVertices(vertices, nv, cell);
nv += 4;
}
vertexBuffer.SetData(vertices, nv);
UpdateMap();
map.MapTiles.Value.CellEntryChanged += UpdateCell;
map.MapHeight.Value.CellEntryChanged += UpdateCell;
wr.PaletteInvalidated += () =>
{
terrainPaletteIndex = wr.Palette("terrain").TextureIndex;
UpdateMap();
};
}
void GenerateTileVertices(Vertex[] vertices, int offset, CPos cell)
@@ -58,6 +56,19 @@ namespace OpenRA.Graphics
Util.FastCreateQuad(vertices, pos, tile, terrainPaletteIndex, offset, tile.Size);
}
void UpdateMap()
{
var nv = 0;
var vertices = new Vertex[rowStride * map.Bounds.Height];
foreach (var cell in map.Cells)
{
GenerateTileVertices(vertices, nv, cell);
nv += 4;
}
vertexBuffer.SetData(vertices, nv);
}
public void UpdateCell(CPos cell)
{
var uv = cell.ToMPos(map.TileShape);