Skip to content

Commit d236a6c

Browse files
committed
little bit of optimization and cleanup
1 parent 4d308d1 commit d236a6c

7 files changed

Lines changed: 13 additions & 22 deletions

File tree

ActiveTextureManagement/TextureConverter.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,9 @@ internal static bool WriteTo(Texture2D cacheTexture, string cacheFile)
549549
compression = SquishFlags.kDxt1;
550550
}
551551

552-
for (int i = 0; i < 32; i++)
552+
for (int i = 0; i < cacheTexture.mipmapCount; i++)
553553
{
554-
int width = Math.Max(1, cacheTexture.width>>i);
554+
int width = Math.Max(1, cacheTexture.width >> i);
555555
int height = Math.Max(1, cacheTexture.height >> i);
556556
if(i != 0)
557557
{
@@ -560,19 +560,15 @@ internal static bool WriteTo(Texture2D cacheTexture, string cacheFile)
560560
int size = squish.GetStorageRequirements(width, height, compression);
561561
squish.CompressImage(img, width, height, imageBuffer, compression | SquishFlags.kColourIterativeClusterFit | SquishFlags.kWeightColourByAlpha);
562562
imgStream.Write(imageBuffer, 0, size);
563-
if(width == 1 || height == 1 || cacheTexture.mipmapCount == 1)
563+
if(width == 1 || height == 1)
564564
{
565565
break;
566566
}
567567
}
568568
imgStream.Close();
569569
return hasAlpha;
570570
}
571-
572-
static int index1(int v)
573-
{
574-
return (int)(sizeof(int)) * 8 - 1 - (32 - (Convert.ToString(v, 2).Length));
575-
}
571+
576572

577573
private static bool texHasAlpha(byte[] colors)
578574
{

LibSquishPort/clusterfit.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class ClusterFit : ColourFit
4343
Vector4 m_xsum_wsum;
4444
Vector4 m_metric;
4545
Vector4 m_besterror;
46+
static Vector4 grid = new Vector4(31.0f, 63.0f, 31.0f, 0);
47+
static Vector4 gridrcp = new Vector4(1.0f / 31.0f, 1.0f / 63.0f, 1.0f / 31.0f, 0.0f);
4648

4749
private static void swap<T>(ref T a, ref T b)
4850
{
@@ -144,12 +146,8 @@ public unsafe override void Compress3( byte* block )
144146
// declare variables
145147
int count = m_colours.GetCount();
146148
Vector4 two = Vector4.one*( 2.0f );
147-
Vector4 one = Vector4.one*( 1.0f );
148149
Vector4 half_half2 = new Vector4( 0.5f, 0.5f, 0.5f, 0.25f );
149-
Vector4 zero = Vector4.zero;
150150
Vector4 half = Vector4.one*( 0.5f );
151-
Vector4 grid = new Vector4( 31.0f, 63.0f, 31.0f, 0.0f );
152-
Vector4 gridrcp = new Vector4( 1.0f/31.0f, 1.0f/63.0f, 1.0f/31.0f, 0.0f );
153151

154152
// prepare an ordering using the principle axis
155153
ructOrdering( m_principle, 0 );
@@ -192,8 +190,8 @@ public unsafe override void Compress3( byte* block )
192190
Vector4 b = Vector4.Scale( alphax_sum.NegativeMultiplySubtract( alphabeta_sum, Vector4.Scale(betax_sum,alpha2_sum) ), factor);
193191

194192
// clamp to the grid
195-
a = Vector4.Min( one, Vector4.Max( zero, a ) );
196-
b = Vector4.Min( one, Vector4.Max( zero, b ) );
193+
a = Vector4.Min(Vector4.one, Vector4.Max(Vector4.zero, a));
194+
b = Vector4.Min(Vector4.one, Vector4.Max(Vector4.zero, b));
197195
a = Vector4.Scale(( grid.MultiplyAdd( a, half ) ).Truncate(),gridrcp);
198196
b = Vector4.Scale(( grid.MultiplyAdd( b, half ) ).Truncate(),gridrcp);
199197

@@ -275,14 +273,10 @@ public unsafe override void Compress4( byte* block )
275273
// declare variables
276274
int count = m_colours.GetCount();
277275
Vector4 two = Vector4.one*( 2.0f );
278-
Vector4 one = Vector4.one;
279276
Vector4 onethird_onethird2 = new Vector4( 1.0f/3.0f, 1.0f/3.0f, 1.0f/3.0f, 1.0f/9.0f );
280277
Vector4 twothirds_twothirds2 = new Vector4( 2.0f/3.0f, 2.0f/3.0f, 2.0f/3.0f, 4.0f/9.0f );
281278
Vector4 twonineths = Vector4.one*( 2.0f/9.0f );
282-
Vector4 zero = Vector4.zero;
283279
Vector4 half = Vector4.one*( 0.5f );
284-
Vector4 grid = new Vector4( 31.0f, 63.0f, 31.0f, 0.0f );
285-
Vector4 gridrcp = new Vector4( 1.0f/31.0f, 1.0f/63.0f, 1.0f/31.0f, 0.0f );
286280

287281
// prepare an ordering using the principle axis
288282
ructOrdering( m_principle, 0 );
@@ -329,8 +323,8 @@ public unsafe override void Compress4( byte* block )
329323
Vector4 b = Vector4.Scale(alphax_sum.NegativeMultiplySubtract( alphabeta_sum, Vector4.Scale(betax_sum,alpha2_sum )),factor);
330324

331325
// clamp to the grid
332-
a = Vector4.Min( one, Vector4.Max( zero, a ) );
333-
b = Vector4.Min( one, Vector4.Max( zero, b ) );
326+
a = Vector4.Min(Vector4.one, Vector4.Max(Vector4.zero, a));
327+
b = Vector4.Min(Vector4.one, Vector4.Max(Vector4.zero, b));
334328
a = Vector4.Scale(( grid.MultiplyAdd( a, half ) ).Truncate(),gridrcp);
335329
b = Vector4.Scale(( grid.MultiplyAdd( b, half ) ).Truncate(),gridrcp);
336330

LibSquishPort/rangefit.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class RangeFit : ColourFit
3636
Vector3 m_start;
3737
Vector3 m_end;
3838
float m_besterror;
39+
static Vector3 grid = new Vector3(31.0f, 63.0f, 31.0f);
40+
static Vector3 gridrcp = new Vector3(1.0f / 31.0f, 1.0f / 63.0f, 1.0f / 31.0f);
3941

4042
public RangeFit( ColourSet colours, SquishFlags flags )
4143
: base( colours, flags )
@@ -92,8 +94,7 @@ public RangeFit( ColourSet colours, SquishFlags flags )
9294
end = Vector3.Min( Vector3.one, Vector3.Max( Vector3.zero, end ) );
9395

9496
// clamp to the grid and save
95-
Vector3 grid = new Vector3( 31.0f, 63.0f, 31.0f );
96-
Vector3 gridrcp = new Vector3( 1.0f/31.0f, 1.0f/63.0f, 1.0f/31.0f );
97+
9798
Vector3 half = Vector3.one*( 0.5f );
9899
m_start = Vector3.Scale(math.Truncate( Vector3.Scale(grid,start) + half ),gridrcp);
99100
m_end = Vector3.Scale(math.Truncate( Vector3.Scale(grid,end) + half ),gridrcp);

x64-Aggressive-Release.zip

-75 Bytes
Binary file not shown.

x64-Basic-Release.zip

-75 Bytes
Binary file not shown.

x86-Aggressive-Release.zip

-74 Bytes
Binary file not shown.

x86-Basic-Release.zip

-74 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)