Skip to content

Commit 7cd86cf

Browse files
committed
fix saving dds mips once again
1 parent e08e858 commit 7cd86cf

File tree

1 file changed

+8
-25
lines changed

1 file changed

+8
-25
lines changed

TankLib/teTexture.cs

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -206,34 +206,17 @@ public void SaveToDDS(Stream stream, bool keepOpen, int? mips, uint? width = nul
206206
// Console.Out.WriteLine($"{mips ?? Header.MipCount} {width ?? Header.Width} {height ?? Header.Height} {surfaces ?? Header.Surfaces}");
207207

208208
var targetMips = mips ?? Header.MipCount;
209-
uint saveMipCount = Header.MipCount;
210-
int savePayloadCount = 0;
211-
if (PayloadRequired) {
212-
/*Console.Out.Write($"-- MIP DEBUG\n {Header.MipCount} ");
213-
foreach (var payload in Payloads)
214-
{
215-
if (payload == null)
216-
{
217-
Console.Out.WriteLine("MISSING!!");
218-
continue;
219-
}
220-
Console.Out.Write($"{payload.Header.Mips} ");
221-
}*/
222-
223-
var payloadIdx = Payloads.Length-1;
224-
while (payloadIdx >= 0)
225-
{
226-
var mipLimitIncludedByThisPayload = Header.MipCount - Payloads[payloadIdx--].Header.Mips;
227-
saveMipCount = mipLimitIncludedByThisPayload;
228-
savePayloadCount++;
229-
230-
if (mipLimitIncludedByThisPayload >= targetMips) break;
231-
}
232209

233-
//Console.Out.WriteLine($"---- {targetMips} {saveMipCount} {payloadIdx} {Payloads.Length} {savePayloadCount} -----");
210+
int savePayloadCount;
211+
if (targetMips == 1) {
212+
// optimization for general case
213+
// we don't need to serialize mips if we only want highest
214+
savePayloadCount = 1;
215+
} else {
216+
savePayloadCount = Header.PayloadCount;
234217
}
235218

236-
TextureTypes.DDSHeader dds = Header.ToDDSHeader((int)saveMipCount, width ?? Header.Width, height ?? Header.Height, surfaces ?? Header.Surfaces);
219+
TextureTypes.DDSHeader dds = Header.ToDDSHeader(targetMips, width ?? Header.Width, height ?? Header.Height, surfaces ?? Header.Surfaces);
237220
ddsWriter.Write(dds);
238221
if (dds.Format.FourCC == 0x30315844) {
239222
var dimension = TextureTypes.D3D10_RESOURCE_DIMENSION.UNKNOWN;

0 commit comments

Comments
 (0)