Optimize prepared asset package v2
This commit is contained in:
parent
d123c4b67c
commit
0dd966f3a0
28 changed files with 1277 additions and 106 deletions
|
|
@ -4,6 +4,7 @@ using System.Diagnostics.CodeAnalysis;
|
|||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using AcDream.Content;
|
||||
using Chorizite.Core.Render.Enums;
|
||||
using DatReaderWriter;
|
||||
using DatReaderWriter.DBObjs;
|
||||
using DatReaderWriter.Enums;
|
||||
|
|
@ -112,6 +113,100 @@ public sealed class MeshExtractorSolidFaceExtractionTests
|
|||
Assert.False(batch.Key.IsSolid);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(PixelFormat.PFID_DXT1, TextureFormat.DXT1, 8)]
|
||||
[InlineData(PixelFormat.PFID_DXT3, TextureFormat.DXT3, 16)]
|
||||
[InlineData(PixelFormat.PFID_DXT5, TextureFormat.DXT5, 16)]
|
||||
public void PrepareMeshData_UneditedDxtSurface_PreservesNativeBlocks(
|
||||
PixelFormat sourceFormat,
|
||||
TextureFormat expectedFormat,
|
||||
int sourceBytes)
|
||||
{
|
||||
var dats = new FakeMeshExtractorDats();
|
||||
byte[] blocks = Enumerable.Range(0, sourceBytes).Select(i => (byte)i).ToArray();
|
||||
RegisterTexturedQuad(dats, SurfaceType.Base1Image, sourceFormat, blocks);
|
||||
|
||||
var extractor = new MeshExtractor(dats, NullLogger.Instance, sideStagedSink: null);
|
||||
ObjectMeshData mesh = Assert.IsType<ObjectMeshData>(
|
||||
extractor.PrepareMeshData(GfxObjId, isSetup: false));
|
||||
|
||||
KeyValuePair<(int Width, int Height, TextureFormat Format), List<TextureBatchData>> group =
|
||||
Assert.Single(mesh.TextureBatches);
|
||||
Assert.Equal(expectedFormat, group.Key.Format);
|
||||
TextureBatchData batch = Assert.Single(group.Value);
|
||||
Assert.Same(blocks, batch.TextureData);
|
||||
Assert.Null(batch.UploadPixelFormat);
|
||||
Assert.Null(batch.UploadPixelType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PrepareMeshData_DxtClipMap_DecodesForSurfaceLocalAlphaEdit()
|
||||
{
|
||||
var dats = new FakeMeshExtractorDats();
|
||||
RegisterTexturedQuad(
|
||||
dats,
|
||||
SurfaceType.Base1Image | SurfaceType.Base1ClipMap,
|
||||
PixelFormat.PFID_DXT1,
|
||||
new byte[8]);
|
||||
|
||||
var extractor = new MeshExtractor(dats, NullLogger.Instance, sideStagedSink: null);
|
||||
ObjectMeshData mesh = Assert.IsType<ObjectMeshData>(
|
||||
extractor.PrepareMeshData(GfxObjId, isSetup: false));
|
||||
|
||||
KeyValuePair<(int Width, int Height, TextureFormat Format), List<TextureBatchData>> group =
|
||||
Assert.Single(mesh.TextureBatches);
|
||||
Assert.Equal(TextureFormat.RGBA8, group.Key.Format);
|
||||
Assert.Equal(4 * 4 * 4, Assert.Single(group.Value).TextureData.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PrepareMeshData_TranslucentDxt_DecodesForAlphaScale()
|
||||
{
|
||||
var dats = new FakeMeshExtractorDats();
|
||||
RegisterTexturedQuad(
|
||||
dats,
|
||||
SurfaceType.Base1Image,
|
||||
PixelFormat.PFID_DXT1,
|
||||
new byte[8],
|
||||
translucency: 0.25f);
|
||||
|
||||
var extractor = new MeshExtractor(dats, NullLogger.Instance, sideStagedSink: null);
|
||||
ObjectMeshData mesh = Assert.IsType<ObjectMeshData>(
|
||||
extractor.PrepareMeshData(GfxObjId, isSetup: false));
|
||||
|
||||
KeyValuePair<(int Width, int Height, TextureFormat Format), List<TextureBatchData>> group =
|
||||
Assert.Single(mesh.TextureBatches);
|
||||
Assert.Equal(TextureFormat.RGBA8, group.Key.Format);
|
||||
Assert.Equal(4 * 4 * 4, Assert.Single(group.Value).TextureData.Length);
|
||||
}
|
||||
|
||||
private static void RegisterTexturedQuad(
|
||||
FakeMeshExtractorDats dats,
|
||||
SurfaceType surfaceType,
|
||||
PixelFormat pixelFormat,
|
||||
byte[] sourceData,
|
||||
float translucency = 0.0f)
|
||||
{
|
||||
dats.RegisterRootGfxObj(GfxObjId, BuildQuadGfxObj(TexturedSurfaceId, noPos: false));
|
||||
dats.Register(TexturedSurfaceId, new Surface
|
||||
{
|
||||
Type = surfaceType,
|
||||
OrigTextureId = SurfaceTextureId,
|
||||
Translucency = translucency,
|
||||
});
|
||||
dats.Register(SurfaceTextureId, new SurfaceTexture
|
||||
{
|
||||
Textures = new List<QualifiedDataId<RenderSurface>> { RenderSurfaceId },
|
||||
});
|
||||
dats.Register(RenderSurfaceId, new RenderSurface
|
||||
{
|
||||
Width = 4,
|
||||
Height = 4,
|
||||
Format = pixelFormat,
|
||||
SourceData = sourceData,
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>One quad (4 verts), single polygon, PosSurface referencing <paramref name="surfaceId"/>.</summary>
|
||||
private static GfxObj BuildQuadGfxObj(uint surfaceId, bool noPos)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue