Merge pull request #4008 from pchote/r8-fix

Improved R8 support.
This commit is contained in:
Matthias Mailänder
2013-10-26 01:19:43 -07:00
6 changed files with 77 additions and 7 deletions

View File

@@ -127,6 +127,14 @@ namespace OpenRA.FileFormats
return InvalidValueAction(value, fieldType, fieldName);
}
if (fieldType == typeof(long))
{
long res;
if (long.TryParse(value, out res))
return res;
return InvalidValueAction(value, fieldType, fieldName);
}
else if (fieldType == typeof(float))
{
float res;

View File

@@ -32,7 +32,7 @@ namespace OpenRA.FileFormats.Graphics
IGraphicsDevice Create( Size size, WindowMode windowMode );
}
public enum BlendMode { None, Alpha, Additive }
public enum BlendMode { None, Alpha, Additive, Subtractive }
public interface IGraphicsDevice
{

View File

@@ -53,15 +53,11 @@ namespace OpenRA.FileFormats
// Skip alignment byte
s.ReadUInt8();
// Ignore palette header
if (type == 1 && paletteOffset != 0)
s.Seek(8, SeekOrigin.Current);
Image = s.ReadBytes(width*height);
// Ignore palette data
// Ignore palette
if (type == 1 && paletteOffset != 0)
s.Seek(512, SeekOrigin.Current);
s.Seek(520, SeekOrigin.Current);
}
}

View File

@@ -79,6 +79,7 @@
<Compile Include="Widgets\Logic\D2kInstallFromCDLogic.cs" />
<Compile Include="BuildingCaptureNotification.cs" />
<Compile Include="Render\WithCrumbleOverlay.cs" />
<Compile Include="PaletteFromR8.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>

View File

@@ -0,0 +1,55 @@
#region Copyright & License Information
/*
* Copyright 2007-2012 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. For more information,
* see COPYING.
*/
#endregion
using System.IO;
using OpenRA.FileFormats;
using OpenRA.Traits;
using OpenRA.Graphics;
namespace OpenRA.Mods.RA
{
class PaletteFromR8Info : ITraitInfo
{
[Desc("Internal palette name")]
public readonly string Name = null;
[Desc("Filename to load")]
public readonly string Filename = null;
[Desc("Palette byte offset")]
public readonly long Offset = 0;
public readonly bool AllowModifiers = true;
public object Create(ActorInitializer init) { return new PaletteFromR8(this); }
}
class PaletteFromR8 : IPalette
{
readonly PaletteFromR8Info info;
public PaletteFromR8(PaletteFromR8Info info) { this.info = info; }
public void InitPalette(WorldRenderer wr)
{
var colors = new uint[256];
using (var s = FileSystem.Open(info.Filename))
{
s.Seek(info.Offset, SeekOrigin.Begin);
for (var i = 0; i < 256; i++)
{
// The custom palette is scaled into the range 0-128.
// This makes the move-flash match the original game, but may not be correct in other cases.
var packed = s.ReadUInt16();
colors[i] = (uint)((255 << 24) | ((packed & 0xF800) << 7) | ((packed & 0x7E0) << 4) | ((packed & 0x1f) << 2));
}
}
wr.AddPalette(info.Name, new Palette(colors), info.AllowModifiers);
}
}
}

View File

@@ -154,6 +154,9 @@ namespace OpenRA.Renderer.SdlCommon
public void SetBlendMode(BlendMode mode)
{
Gl.glBlendEquation(Gl.GL_FUNC_ADD);
ErrorHandler.CheckGlError();
switch (mode)
{
case BlendMode.None:
@@ -169,6 +172,13 @@ namespace OpenRA.Renderer.SdlCommon
ErrorHandler.CheckGlError();
Gl.glBlendFunc(Gl.GL_ONE, Gl.GL_ONE);
break;
case BlendMode.Subtractive:
Gl.glEnable(Gl.GL_BLEND);
ErrorHandler.CheckGlError();
Gl.glBlendFunc(Gl.GL_ONE, Gl.GL_ONE);
ErrorHandler.CheckGlError();
Gl.glBlendEquation(Gl.GL_FUNC_REVERSE_SUBTRACT);
break;
}
ErrorHandler.CheckGlError();
}