FAST vqa render
This commit is contained in:
@@ -71,6 +71,7 @@ namespace OpenRA.FileFormats.Graphics
|
|||||||
public interface ITexture
|
public interface ITexture
|
||||||
{
|
{
|
||||||
void SetData( Bitmap bitmap );
|
void SetData( Bitmap bitmap );
|
||||||
|
void SetData(int[,] colors);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IFont
|
public interface IFont
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace OpenRA.FileFormats
|
|||||||
byte cbParts;
|
byte cbParts;
|
||||||
int2 blocks;
|
int2 blocks;
|
||||||
UInt32[] offsets;
|
UInt32[] offsets;
|
||||||
Color[] palette;
|
int[] palette;
|
||||||
|
|
||||||
// Stores a list of subpixels, referenced by the VPTZ chunk
|
// Stores a list of subpixels, referenced by the VPTZ chunk
|
||||||
byte[] cbf;
|
byte[] cbf;
|
||||||
@@ -42,7 +42,10 @@ namespace OpenRA.FileFormats
|
|||||||
int cbOffset = 0;
|
int cbOffset = 0;
|
||||||
|
|
||||||
// Top half contains block info, bottom half contains references to cbf array
|
// Top half contains block info, bottom half contains references to cbf array
|
||||||
byte[] framedata;
|
byte[] origData;
|
||||||
|
|
||||||
|
// Final frame output
|
||||||
|
int[,] frameData;
|
||||||
|
|
||||||
public VqaReader( Stream stream )
|
public VqaReader( Stream stream )
|
||||||
{
|
{
|
||||||
@@ -81,12 +84,12 @@ namespace OpenRA.FileFormats
|
|||||||
/*var bits = */reader.ReadByte();
|
/*var bits = */reader.ReadByte();
|
||||||
/*var unknown3 = */reader.ReadChars(14);
|
/*var unknown3 = */reader.ReadChars(14);
|
||||||
|
|
||||||
|
var frameSize = NextPowerOf2(Math.Max(Width,Height));
|
||||||
cbf = new byte[Width*Height];
|
cbf = new byte[Width*Height];
|
||||||
cbp = new byte[Width*Height];
|
cbp = new byte[Width*Height];
|
||||||
palette = new Color[numColors];
|
palette = new int[numColors];
|
||||||
framedata = new byte[2*blocks.X*blocks.Y];
|
origData = new byte[2*blocks.X*blocks.Y];
|
||||||
|
frameData = new int[frameSize,frameSize];
|
||||||
|
|
||||||
// Decode FINF chunk
|
// Decode FINF chunk
|
||||||
if (new String(reader.ReadChars(4)) != "FINF")
|
if (new String(reader.ReadChars(4)) != "FINF")
|
||||||
@@ -187,13 +190,13 @@ namespace OpenRA.FileFormats
|
|||||||
byte r = reader.ReadByte();
|
byte r = reader.ReadByte();
|
||||||
byte g = reader.ReadByte();
|
byte g = reader.ReadByte();
|
||||||
byte b = reader.ReadByte();
|
byte b = reader.ReadByte();
|
||||||
palette[i] = Color.FromArgb(255,ToColorByte(r),ToColorByte(g),ToColorByte(b));
|
palette[i] = Color.FromArgb(255,ToColorByte(r),ToColorByte(g),ToColorByte(b)).ToArgb();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Frame data
|
// Frame data
|
||||||
case "VPTZ":
|
case "VPTZ":
|
||||||
Format80.DecodeInto( reader.ReadBytes(subchunkLength), framedata );
|
Format80.DecodeInto( reader.ReadBytes(subchunkLength), origData );
|
||||||
// This is the last subchunk
|
// This is the last subchunk
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
@@ -202,29 +205,33 @@ namespace OpenRA.FileFormats
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FrameData(ref Bitmap frame)
|
public int[,] FrameData()
|
||||||
{
|
{
|
||||||
var bitmapData = frame.LockBits(new Rectangle(0, 0, Width, Height),
|
|
||||||
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
|
|
||||||
unsafe
|
|
||||||
{
|
|
||||||
int* c = (int*)bitmapData.Scan0;
|
|
||||||
|
|
||||||
for (var y = 0; y < blocks.Y; y++)
|
for (var y = 0; y < blocks.Y; y++)
|
||||||
for (var x = 0; x < blocks.X; x++)
|
for (var x = 0; x < blocks.X; x++)
|
||||||
{
|
{
|
||||||
var px = framedata[x + y*blocks.X];
|
var px = origData[x + y*blocks.X];
|
||||||
var mod = framedata[x + (y + blocks.Y)*blocks.X];
|
var mod = origData[x + (y + blocks.Y)*blocks.X];
|
||||||
for (var j = 0; j < blockHeight; j++)
|
for (var j = 0; j < blockHeight; j++)
|
||||||
for (var i = 0; i < blockWidth; i++)
|
for (var i = 0; i < blockWidth; i++)
|
||||||
{
|
{
|
||||||
var cbfi = (mod*256 + px)*8 + j*blockWidth + i;
|
var cbfi = (mod*256 + px)*8 + j*blockWidth + i;
|
||||||
byte color = (mod == 0x0f) ? px : cbf[cbfi];
|
byte color = (mod == 0x0f) ? px : cbf[cbfi];
|
||||||
*(c + ((y*blockHeight + j) * bitmapData.Stride >> 2) + x*blockWidth + i) = palette[color].ToArgb();
|
frameData[y*blockHeight + j, x*blockWidth + i] = palette[color];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return frameData;
|
||||||
}
|
}
|
||||||
frame.UnlockBits(bitmapData);
|
|
||||||
|
int NextPowerOf2(int v)
|
||||||
|
{
|
||||||
|
--v;
|
||||||
|
v |= v >> 1;
|
||||||
|
v |= v >> 2;
|
||||||
|
v |= v >> 4;
|
||||||
|
v |= v >> 8;
|
||||||
|
++v;
|
||||||
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte ToColorByte(byte b)
|
public byte ToColorByte(byte b)
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
float timestep;
|
float timestep;
|
||||||
Sprite videoSprite;
|
Sprite videoSprite;
|
||||||
Bitmap videoFrame;
|
|
||||||
VqaReader video = null;
|
VqaReader video = null;
|
||||||
|
|
||||||
public void LoadVideo(string filename)
|
public void LoadVideo(string filename)
|
||||||
@@ -32,11 +31,7 @@ namespace OpenRA.Widgets
|
|||||||
timestep = 1e3f/video.Framerate;
|
timestep = 1e3f/video.Framerate;
|
||||||
|
|
||||||
var size = OpenRA.Graphics.Util.NextPowerOf2(Math.Max(video.Width, video.Height));
|
var size = OpenRA.Graphics.Util.NextPowerOf2(Math.Max(video.Width, video.Height));
|
||||||
videoFrame = new Bitmap(size,size);
|
|
||||||
video.FrameData(ref videoFrame);
|
|
||||||
|
|
||||||
videoSprite = new Sprite(new Sheet(new Size(size,size)), new Rectangle( 0, 0, video.Width, video.Height ), TextureChannel.Alpha);
|
videoSprite = new Sprite(new Sheet(new Size(size,size)), new Rectangle( 0, 0, video.Width, video.Height ), TextureChannel.Alpha);
|
||||||
videoSprite.sheet.Texture.SetData(videoFrame);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int lastTime;
|
int lastTime;
|
||||||
@@ -59,8 +54,7 @@ namespace OpenRA.Widgets
|
|||||||
{
|
{
|
||||||
lastTime = t;
|
lastTime = t;
|
||||||
advanceNext = true;
|
advanceNext = true;
|
||||||
video.FrameData(ref videoFrame);
|
videoSprite.sheet.Texture.SetData(video.FrameData());
|
||||||
videoSprite.sheet.Texture.SetData(videoFrame);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Game.Renderer.RgbaSpriteRenderer.DrawSprite(videoSprite, new int2(RenderBounds.X,RenderBounds.Y), "chrome");
|
Game.Renderer.RgbaSpriteRenderer.DrawSprite(videoSprite, new int2(RenderBounds.X,RenderBounds.Y), "chrome");
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
@@ -29,6 +30,7 @@
|
|||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ using System.Drawing;
|
|||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using OpenRA.FileFormats.Graphics;
|
using OpenRA.FileFormats.Graphics;
|
||||||
using Tao.OpenGl;
|
using Tao.OpenGl;
|
||||||
|
using System.IO;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace OpenRA.GlRenderer
|
namespace OpenRA.GlRenderer
|
||||||
{
|
{
|
||||||
@@ -26,6 +28,33 @@ namespace OpenRA.GlRenderer
|
|||||||
SetData(bitmap);
|
SetData(bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// An array of Color.ToARGB()'s
|
||||||
|
public void SetData(int[,] colors)
|
||||||
|
{
|
||||||
|
int width = colors.GetUpperBound(0) + 1;
|
||||||
|
int height = colors.GetUpperBound(1) + 1;
|
||||||
|
|
||||||
|
if (!IsPowerOf2(width) || !IsPowerOf2(height))
|
||||||
|
throw new InvalidDataException("Non-power-of-two array {0}x{1}".F(width,height));
|
||||||
|
|
||||||
|
IntPtr intPtr;
|
||||||
|
unsafe
|
||||||
|
{
|
||||||
|
fixed (int* ptr = colors)
|
||||||
|
intPtr = new IntPtr((void *) ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture);
|
||||||
|
GraphicsDevice.CheckGlError();
|
||||||
|
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_BASE_LEVEL, 0);
|
||||||
|
GraphicsDevice.CheckGlError();
|
||||||
|
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAX_LEVEL, 0);
|
||||||
|
GraphicsDevice.CheckGlError();
|
||||||
|
Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA8, width, height,
|
||||||
|
0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, intPtr);
|
||||||
|
GraphicsDevice.CheckGlError();
|
||||||
|
}
|
||||||
|
|
||||||
public void SetData(Bitmap bitmap)
|
public void SetData(Bitmap bitmap)
|
||||||
{
|
{
|
||||||
if (!IsPowerOf2(bitmap.Width) || !IsPowerOf2(bitmap.Height))
|
if (!IsPowerOf2(bitmap.Width) || !IsPowerOf2(bitmap.Height))
|
||||||
|
|||||||
Reference in New Issue
Block a user