Files
Pal3.Unity/Assets/Scripts/Engine/DataLoader/DxtTextureDataSource.cs
T
Jiaqi (0x7c13) Liu 9cda701b13 Optimize DDS texture creation and static POL meshes
Separate file decoding from Unity upload through format-neutral texture data
and explicit world, sprite and skybox policies. Validate DDS layouts, preserve
alpha coverage and use native BC uploads with software RGBA fallback.

Compact referenced POL vertices and batch nearby static opaque groups sharing
materials. Keep water and dynamic geometry separate, with source ranges retained
only in the Editor. Add DDS layout and POL index regression tests.

Validation: PAL3 and PAL3A each passed 24 Editor tests, eight combined Game and
ResourceViewer style regressions, 936 paired skybox comparisons, and both macOS
Player builds on Metal. Editor provenance and Core tests are excluded from Players.
2026-11-12 11:35:23 +08:00

41 lines
1.6 KiB
C#

// See LICENSE in the project root.
namespace Engine.DataLoader
{
using System;
using Core.Abstraction;
using Pal3.Core.DataReader.Dxt;
/// <summary>Adapts validated DDS data to format-neutral texture blocks and pixel reads.</summary>
internal sealed class DxtTextureDataSource : ITextureDataSource, ITexturePixelReader
{
private readonly DxtImage _image;
public DxtTextureDataSource(DxtImage image) => _image = image;
public int Width => _image.Width;
public int Height => _image.Height;
public int MipCount => _image.MipCount;
public TextureDataFormat Format => _image.HasAlphaChannel ? TextureDataFormat.Bc2 : TextureDataFormat.Bc1;
public bool HasTransparency => _image.HasTransparency;
public ArraySegment<byte> GetMipData(int mip)
{
int offset = _image.GetOffset(mip);
int length = ((_image.GetWidth(mip) + 3) / 4) * ((_image.GetHeight(mip) + 3) / 4) *
(Format == TextureDataFormat.Bc2 ? 16 : 8);
return new ArraySegment<byte>(_image.Data, offset, length);
}
public void CopyMipToRgba32(int mip, byte[] destination) => _image.Decode(mip, destination);
// DDS bytes are owned managed data, never a pooled upload buffer. Sharing this reader
// keeps compressed blocks alive without allocating an uncompressed CPU copy.
public ITexturePixelReader CreatePixelReader() => this;
public (byte r, byte g, byte b, byte a) GetPixel(int x, int y) => _image.GetPixel(x, y);
public void Dispose() { }
}
}