source: OniSplit/Motoko/TextureDatWriter.cs@ 1176

Last change on this file since 1176 was 1114, checked in by iritscen, 5 years ago

Adding OniSplit source code (v0.9.99.0). Many thanks to Neo for all his work over the years.

File size: 1.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using Oni.Imaging;
4
5namespace Oni.Motoko
6{
7 internal class TextureDatWriter
8 {
9 private readonly Importer importer;
10
11 public static void Write(Texture texture, string outputDirPath)
12 {
13 var writer = new DatWriter();
14 Write(texture, writer);
15 writer.Write(outputDirPath);
16 }
17
18 public static void Write(Texture texture, Importer importer)
19 {
20 var writer = new TextureDatWriter(importer);
21 writer.Write(texture);
22 }
23
24 private TextureDatWriter(Importer importer)
25 {
26 this.importer = importer;
27 }
28
29 private void Write(Texture texture)
30 {
31 var txmp = importer.CreateInstance(TemplateTag.TXMP, texture.Name);
32 int rawOffset = importer.RawWriter.Align32();
33 var flags = texture.Flags;
34 ImporterDescriptor envMapTxmp = null;
35
36 if (texture.EnvMap != null)
37 {
38 envMapTxmp = importer.CreateInstance(TemplateTag.TXMP, texture.EnvMap.Name);
39 flags |= TextureFlags.HasEnvMap;
40 }
41
42 if (texture.Surfaces.Count > 1)
43 {
44 flags |= TextureFlags.HasMipMaps;
45 }
46
47 using (var writer = txmp.OpenWrite(128))
48 {
49 writer.Write((int)flags);
50 writer.WriteInt16(texture.Width);
51 writer.WriteInt16(texture.Height);
52 writer.Write((int)texture.Format);
53 writer.Write(0);
54 writer.Write(envMapTxmp);
55 writer.Write(rawOffset);
56 writer.Skip(12);
57 }
58
59 foreach (var surface in texture.Surfaces)
60 importer.RawWriter.Write(surface.Data);
61 }
62 }
63}
Note: See TracBrowser for help on using the repository browser.