add alpha channel to every possible blend mode
This commit is contained in:
@@ -42,9 +42,7 @@ namespace OpenRA
|
||||
Subtractive,
|
||||
Multiply,
|
||||
SoftAdditive,
|
||||
Translucency25,
|
||||
Translucency50,
|
||||
Translucency75,
|
||||
Translucency,
|
||||
Multiplicative,
|
||||
DoubleMultiplicative
|
||||
}
|
||||
@@ -72,7 +70,7 @@ namespace OpenRA
|
||||
void EnableDepthBuffer();
|
||||
void DisableDepthBuffer();
|
||||
|
||||
void SetBlendMode(BlendMode mode);
|
||||
void SetBlendMode(BlendMode mode, float alpha = 1f);
|
||||
|
||||
void GrabWindowMouseFocus();
|
||||
void ReleaseWindowMouseFocus();
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace OpenRA.Graphics
|
||||
public readonly Rectangle Bounds;
|
||||
public readonly Sheet Sheet;
|
||||
public readonly BlendMode BlendMode;
|
||||
public readonly float Alpha;
|
||||
public readonly TextureChannel Channel;
|
||||
public readonly float2 Size;
|
||||
public readonly float2 Offset;
|
||||
@@ -24,12 +25,9 @@ namespace OpenRA.Graphics
|
||||
public readonly float Top, Left, Bottom, Right;
|
||||
|
||||
public Sprite(Sheet sheet, Rectangle bounds, TextureChannel channel)
|
||||
: this(sheet, bounds, float2.Zero, channel, BlendMode.Alpha) { }
|
||||
: this(sheet, bounds, float2.Zero, channel) { }
|
||||
|
||||
public Sprite(Sheet sheet, Rectangle bounds, TextureChannel channel, BlendMode blendMode)
|
||||
: this(sheet, bounds, float2.Zero, channel, blendMode) { }
|
||||
|
||||
public Sprite(Sheet sheet, Rectangle bounds, float2 offset, TextureChannel channel, BlendMode blendMode)
|
||||
public Sprite(Sheet sheet, Rectangle bounds, float2 offset, TextureChannel channel, BlendMode blendMode = BlendMode.Alpha, float alpha = 1f)
|
||||
{
|
||||
Sheet = sheet;
|
||||
Bounds = bounds;
|
||||
@@ -37,6 +35,7 @@ namespace OpenRA.Graphics
|
||||
Channel = channel;
|
||||
Size = new float2(bounds.Size);
|
||||
BlendMode = blendMode;
|
||||
Alpha = alpha;
|
||||
|
||||
FractionalOffset = offset / Size;
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace OpenRA.Graphics
|
||||
readonly Vertex[] vertices;
|
||||
Sheet currentSheet;
|
||||
BlendMode currentBlend = BlendMode.Alpha;
|
||||
float currentAlpha = 1f;
|
||||
int nv = 0;
|
||||
|
||||
public SpriteRenderer(Renderer renderer, IShader shader)
|
||||
@@ -36,14 +37,14 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
shader.SetTexture("DiffuseTexture", currentSheet.GetTexture());
|
||||
|
||||
renderer.Device.SetBlendMode(currentBlend);
|
||||
renderer.Device.SetBlendMode(currentBlend, currentAlpha);
|
||||
shader.Render(() =>
|
||||
{
|
||||
var vb = renderer.GetTempVertexBuffer();
|
||||
vb.SetData(vertices, nv);
|
||||
renderer.DrawBatch(vb, 0, nv, PrimitiveType.QuadList);
|
||||
});
|
||||
renderer.Device.SetBlendMode(BlendMode.None);
|
||||
renderer.Device.SetBlendMode(BlendMode.None, currentAlpha);
|
||||
|
||||
nv = 0;
|
||||
currentSheet = null;
|
||||
@@ -54,9 +55,10 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
renderer.CurrentBatchRenderer = this;
|
||||
|
||||
if (s.Sheet != currentSheet || s.BlendMode != currentBlend || nv + 4 > renderer.TempBufferSize)
|
||||
if (s.Alpha != currentAlpha || s.BlendMode != currentBlend || s.Sheet != currentSheet || nv + 4 > renderer.TempBufferSize)
|
||||
Flush();
|
||||
|
||||
currentAlpha = s.Alpha;
|
||||
currentBlend = s.BlendMode;
|
||||
currentSheet = s.Sheet;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user