mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-07-18 20:16:44 -04:00
Added FSO.Files for use with the API server
Don't ask me. FreeSO is the prime example of dependency hell.
This commit is contained in:
parent
4b5e584eeb
commit
8fec258215
104 changed files with 14653 additions and 163 deletions
59
server/tso.files/Formats/IFF/Chunks/MTEX.cs
Executable file
59
server/tso.files/Formats/IFF/Chunks/MTEX.cs
Executable file
|
@ -0,0 +1,59 @@
|
|||
using FSO.Common;
|
||||
using FSO.Common.Utils;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System.IO;
|
||||
|
||||
namespace FSO.Files.Formats.IFF.Chunks
|
||||
{
|
||||
/// <summary>
|
||||
/// Texture for a 3D Mesh. Can be jpg, png or bmp.
|
||||
/// </summary>
|
||||
public class MTEX : IffChunk
|
||||
{
|
||||
private byte[] data;
|
||||
private Texture2D Cached;
|
||||
|
||||
/// <summary>
|
||||
/// Reads a BMP chunk from a stream.
|
||||
/// </summary>
|
||||
/// <param name="iff">An Iff instance.</param>
|
||||
/// <param name="stream">A Stream object holding a BMP chunk.</param>
|
||||
public override void Read(IffFile iff, Stream stream)
|
||||
{
|
||||
data = new byte[stream.Length];
|
||||
stream.Read(data, 0, (int)stream.Length);
|
||||
}
|
||||
|
||||
public override bool Write(IffFile iff, Stream stream)
|
||||
{
|
||||
stream.Write(data, 0, data.Length);
|
||||
return true;
|
||||
}
|
||||
|
||||
public Texture2D GetTexture(GraphicsDevice device)
|
||||
{
|
||||
if (Cached == null)
|
||||
{
|
||||
Cached = ImageLoader.FromStream(device, new MemoryStream(data));
|
||||
if (FSOEnvironment.EnableNPOTMip)
|
||||
{
|
||||
var data = new Color[Cached.Width * Cached.Height];
|
||||
Cached.GetData(data);
|
||||
var n = new Texture2D(device, Cached.Width, Cached.Height, true, SurfaceFormat.Color);
|
||||
TextureUtils.UploadWithMips(n, device, data);
|
||||
Cached.Dispose();
|
||||
Cached = n;
|
||||
}
|
||||
}
|
||||
if (!IffFile.RETAIN_CHUNK_DATA) data = null;
|
||||
return Cached;
|
||||
}
|
||||
|
||||
public void SetData(byte[] data)
|
||||
{
|
||||
this.data = data;
|
||||
Cached = null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue