Skip to content

Commit 66e21d4

Browse files
committed
Allowing for uncompressed textures.
1 parent fd96a24 commit 66e21d4

9 files changed

Lines changed: 55 additions & 28 deletions

File tree

ActiveTextureManagement/CacheController.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ public static TextureInfoWrapper FetchCacheTexture(TexInfo Texture, bool compres
6767
bool.TryParse(hasAlphaString, out hasAlpha);
6868
bool.TryParse(hasMipmapsString, out hasMipmaps);
6969

70-
//Need to add comparison here... || compress != isCompressed
71-
if (cacheHash != hashString || mipmaps != hasMipmaps || cacheIsNorm != Texture.isNormalMap || Texture.resizeWidth != cacheWidth || Texture.resizeHeight != cacheHeight)
70+
if (cacheHash != hashString || compress != isCompressed || mipmaps != hasMipmaps || cacheIsNorm != Texture.isNormalMap || Texture.resizeWidth != cacheWidth || Texture.resizeHeight != cacheHeight)
7271
{
7372
if (cacheHash != hashString)
7473
{
@@ -129,8 +128,7 @@ private static TextureInfoWrapper RebuildCache(TexInfo Texture, bool compress, b
129128
ActiveTextureManagement.DBGLog("Saving cache file " + cacheFile + ".imgcache");
130129
tex.Apply(mipmaps);
131130
Color32[] colors = tex.GetPixels32();
132-
bool hasAlpha =TextureConverter.WriteTo(tex, cacheFile + ".imgcache");
133-
compress = true;
131+
bool hasAlpha =TextureConverter.WriteTo(tex, cacheFile + ".imgcache", compress);
134132

135133
String originalTextureFile = Texture.filename;
136134
String cacheConfigFile = cacheFile + ".tcache";

ActiveTextureManagement/ColorExtensions.cs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,30 @@ public static byte[] component(this Color32 color)
1919
return new byte[4] { color.b, color.g, color.r, color.a };
2020
}
2121

22-
public static byte[] bytes(this Texture2D texture, int mipmapLevel)
22+
public static byte[] bytes(this Texture2D texture, int mipmapLevel, bool hasAlpha = true)
2323
{
2424
Color32[] colors = texture.GetPixels32(mipmapLevel);
25-
byte[] array = new byte[colors.Length * 4];
26-
27-
for (int i = 0; i < colors.Length; i++ )
25+
byte[] array;
26+
if (hasAlpha)
2827
{
29-
array[(i*4)] = colors[i].r;
30-
array[(i*4)+1] = colors[i].g;
31-
array[(i*4)+2] = colors[i].b;
32-
array[(i*4)+3] = colors[i].a;
28+
array = new byte[colors.Length * 4];
29+
for (int i = 0; i < colors.Length; i++)
30+
{
31+
array[(i * 4)] = colors[i].r;
32+
array[(i * 4) + 1] = colors[i].g;
33+
array[(i * 4) + 2] = colors[i].b;
34+
array[(i * 4) + 3] = colors[i].a;
35+
}
36+
}
37+
else
38+
{
39+
array = new byte[colors.Length * 3];
40+
for (int i = 0; i < colors.Length; i++)
41+
{
42+
array[(i * 3)] = colors[i].r;
43+
array[(i * 3) + 1] = colors[i].g;
44+
array[(i * 3) + 2] = colors[i].b;
45+
}
3346
}
3447
return array;
3548
}

ActiveTextureManagement/TextureConverter.cs

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace ActiveTextureManagement
1212
class TextureConverter
1313
{
1414

15-
const int MAX_IMAGE_SIZE = 4048 * 4048 * 5;
15+
const int MAX_IMAGE_SIZE = 8096 * 8096 * 3;
1616
static byte[] imageBuffer = null;
1717

1818
public static void InitImageBuffer()
@@ -463,18 +463,26 @@ public static TextureInfoWrapper DDSToTexture(TexInfo Texture, bool mipmaps, boo
463463
imgStream.Close();
464464

465465
TextureFormat format = TextureFormat.DXT1;
466-
if(hasAlpha)
466+
if(hasAlpha && isCompressed)
467467
{
468468
format = TextureFormat.DXT5;
469469
}
470+
else if(hasAlpha)
471+
{
472+
format = TextureFormat.RGBA32;
473+
}
474+
else if(!isCompressed)
475+
{
476+
format = TextureFormat.RGB24;
477+
}
470478

471479
Texture2D newTex = new Texture2D(Texture.width, Texture.height, format, mipmaps);
472480

473481
newTex.LoadRawTextureData(imageBuffer);
474482
newTex.Apply(false, Texture.makeNotReadable);
475483
newTex.name = Texture.name;
476484

477-
TextureInfoWrapper newTexInfo = new TextureInfoWrapper(newTex, Texture.isNormalMap, !Texture.makeNotReadable, true);
485+
TextureInfoWrapper newTexInfo = new TextureInfoWrapper(newTex, Texture.isNormalMap, !Texture.makeNotReadable, isCompressed);
478486
newTexInfo.name = Texture.name;
479487
return newTexInfo;
480488
}
@@ -532,7 +540,7 @@ public static void GetReadable(TexInfo Texture, bool mipmaps)
532540
}
533541
}
534542

535-
internal static bool WriteTo(Texture2D cacheTexture, string cacheFile)
543+
internal static bool WriteTo(Texture2D cacheTexture, string cacheFile, bool compress)
536544
{
537545
String directory = Path.GetDirectoryName(cacheFile + ".none");
538546
if (File.Exists(directory))
@@ -558,20 +566,28 @@ internal static bool WriteTo(Texture2D cacheTexture, string cacheFile)
558566
{
559567
int width = Math.Max(1, cacheTexture.width >> i);
560568
int height = Math.Max(1, cacheTexture.height >> i);
561-
if(i != 0)
569+
if (compress)
562570
{
563-
img = cacheTexture.bytes(i);
571+
if (i != 0)
572+
{
573+
img = cacheTexture.bytes(i);
574+
}
575+
int size = squish.GetStorageRequirements(width, height, compression);
576+
if (DatabaseLoaderTexture_ATM.UseSquish)
577+
{
578+
squish.CompressImage(img, width, height, imageBuffer, compression | SquishFlags.kColourIterativeClusterFit | SquishFlags.kWeightColourByAlpha);
579+
}
580+
else
581+
{
582+
TextureToolsDXT.GetDXT(cacheTexture, i, imageBuffer, format);
583+
}
584+
imgStream.Write(imageBuffer, 0, size);
564585
}
565-
int size = squish.GetStorageRequirements(width, height, compression);
566-
if (DatabaseLoaderTexture_ATM.UseSquish)
586+
else
567587
{
568-
squish.CompressImage(img, width, height, imageBuffer, compression | SquishFlags.kColourIterativeClusterFit | SquishFlags.kWeightColourByAlpha);
569-
}
570-
else
571-
{
572-
TextureToolsDXT.GetDXT(cacheTexture, i, imageBuffer, format);
588+
img = cacheTexture.bytes(i, hasAlpha);
589+
imgStream.Write(img, 0, img.Length);
573590
}
574-
imgStream.Write(imageBuffer, 0, size);
575591
if(width == 1 || height == 1)
576592
{
577593
break;

Content/aggressive/GameData/BoulderCo/ActiveTextureManagerConfig.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ DBG = TRUE
6060

6161
### Section for normalmapped textures. Same as above, but
6262
### apply only to normal maps.
63-
compress_normals = false
63+
compress_normals = true
6464
mipmaps_normals = true
6565
scale_normals = 2
6666
max_size_normals = 256

Content/basic/GameData/BoulderCo/ActiveTextureManagerConfig.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ ACTIVE_TEXTURE_MANAGER
6060

6161
### Section for normalmapped textures. Same as above, but
6262
### apply only to normal maps.
63-
compress_normals = false
63+
compress_normals = true
6464
mipmaps_normals = true
6565
scale_normals = 2
6666
max_size_normals = 512

x64-Aggressive-Release.zip

81 Bytes
Binary file not shown.

x64-Basic-Release.zip

82 Bytes
Binary file not shown.

x86-Aggressive-Release.zip

80 Bytes
Binary file not shown.

x86-Basic-Release.zip

81 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)