Merge RGBA sprite rendering into SpriteRenderer.

Renderer.RgbaSpriteRenderer is kept as a thin
wrapper to maintain compatibility with consumer
code.
This commit is contained in:
Paul Chote
2018-05-31 22:07:40 +00:00
committed by reaperrr
parent ba38878933
commit 131496ebf8
10 changed files with 95 additions and 92 deletions

View File

@@ -0,0 +1,52 @@
#region Copyright & License Information
/*
* Copyright 2007-2018 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
namespace OpenRA.Graphics
{
public class RgbaSpriteRenderer
{
readonly SpriteRenderer parent;
public RgbaSpriteRenderer(SpriteRenderer parent)
{
this.parent = parent;
}
public void DrawSprite(Sprite s, float3 location, float3 size)
{
if (s.Channel != TextureChannel.RGBA)
throw new InvalidOperationException("DrawRGBASprite requires a RGBA sprite.");
parent.DrawSprite(s, location, 0, size);
}
public void DrawSprite(Sprite s, float3 location)
{
if (s.Channel != TextureChannel.RGBA)
throw new InvalidOperationException("DrawRGBASprite requires a RGBA sprite.");
parent.DrawSprite(s, location, 0, s.Size);
}
public void DrawSprite(Sprite s, float3 a, float3 b, float3 c, float3 d)
{
if (s.Channel != TextureChannel.RGBA)
throw new InvalidOperationException("DrawRGBASprite requires a RGBA sprite.");
parent.DrawSprite(s, a, b, c, d);
}
}
}

View File

@@ -59,6 +59,13 @@ namespace OpenRA.Graphics
currentSheet = s.Sheet;
}
internal void DrawSprite(Sprite s, float3 location, float paletteTextureIndex, float3 size)
{
SetRenderStateForSprite(s);
Util.FastCreateQuad(vertices, location + s.FractionalOffset * size, s, paletteTextureIndex, nv, size);
nv += 6;
}
public void DrawSprite(Sprite s, float3 location, PaletteReference pal)
{
DrawSprite(s, location, pal.TextureIndex, s.Size);
@@ -69,24 +76,6 @@ namespace OpenRA.Graphics
DrawSprite(s, location, pal.TextureIndex, size);
}
void DrawSprite(Sprite s, float3 location, float paletteTextureIndex, float3 size)
{
SetRenderStateForSprite(s);
Util.FastCreateQuad(vertices, location + s.FractionalOffset * size, s, paletteTextureIndex, nv, size);
nv += 6;
}
// For RGBASpriteRenderer, which doesn't use palettes
public void DrawSprite(Sprite s, float3 location)
{
DrawSprite(s, location, 0, s.Size);
}
public void DrawSprite(Sprite s, float3 location, float3 size)
{
DrawSprite(s, location, 0, size);
}
public void DrawSprite(Sprite s, float3 a, float3 b, float3 c, float3 d)
{
SetRenderStateForSprite(s);
@@ -94,13 +83,6 @@ namespace OpenRA.Graphics
nv += 6;
}
public void DrawSprite(Sprite s, Vertex[] sourceVertices, int offset)
{
SetRenderStateForSprite(s);
Array.Copy(sourceVertices, offset, vertices, nv, 6);
nv += 6;
}
public void DrawVertexBuffer(IVertexBuffer<Vertex> buffer, int start, int length, PrimitiveType type, Sheet sheet, BlendMode blendMode)
{
shader.SetTexture("DiffuseTexture", sheet.GetTexture());

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Graphics
float sb = 0;
// See shp.vert for documentation on the channel attribute format
var attribC = ((byte)r.Channel) << 1 | 0x01;
var attribC = r.Channel == TextureChannel.RGBA ? 0x02 : ((byte)r.Channel) << 1 | 0x01;
var ss = r as SpriteWithSecondaryData;
if (ss != null)

View File

@@ -169,7 +169,6 @@ namespace OpenRA.Graphics
{
lastDepthPreviewEnabled = debugVis.Value.DepthBuffer;
Game.Renderer.WorldSpriteRenderer.SetDepthPreviewEnabled(lastDepthPreviewEnabled);
Game.Renderer.WorldRgbaSpriteRenderer.SetDepthPreviewEnabled(lastDepthPreviewEnabled);
}
RefreshPalette();