acdream/tests/AcDream.Core.Tests/Rendering/Wb/WbMeshAdapterTests.cs
Erik 01cff4144f phase(N.4) Tasks 22+23: WbDrawDispatcher + surface metadata side-table
WbDrawDispatcher draws all entities through WB's ObjectRenderData
(VAO/VBO per GfxObj, per-batch IBO) using acdream's TextureCache for
texture resolution. Two-pass rendering (opaque+ClipMap, then
translucent) matching the existing InstancedMeshRenderer pattern.
Per-entity single-instance drawing for N.4 simplicity — true
instancing grouping deferred to N.6.

Atlas-tier entities: mesh from WB, texture from TextureCache via
batch SurfaceId. Per-instance-tier entities: AnimatedEntityState
drives part overrides + hidden-parts, palette/surface overrides
resolve through TextureCache's composite-key caches.

Side-table population (Task 23 folded in): WbMeshAdapter now takes
DatCollection and populates AcSurfaceMetadataTable on first
IncrementRefCount per GfxObj. The side-table provides TranslucencyKind
(critical for ClipMap alpha-test on vegetation) plus Luminosity,
Diffuse, SurfOpacity, NeedsUvRepeat, DisableFog for sky-pass and
lighting.

GameWindow wiring: when WbFoundationFlag is enabled, WbDrawDispatcher
draws everything and InstancedMeshRenderer is skipped. Flag-off path
is unchanged.

Matrix composition: restPose * animOverride * entityWorld, matching
the spec. Three MatrixCompositionTests verify the contract.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-08 15:30:33 +02:00

65 lines
2 KiB
C#

using System;
using AcDream.App.Rendering.Wb;
using Microsoft.Extensions.Logging.Abstractions;
using Silk.NET.OpenGL;
namespace AcDream.Core.Tests.Rendering.Wb;
public sealed class WbMeshAdapterTests
{
[Fact]
public void Construct_WithNullGl_ThrowsArgumentNull()
{
// GL is the first guarded parameter; verifies the constructor validates inputs.
// We can't pass a real GL (no context in tests), so we verify only the
// null-GL guard. The real pipeline is tested via integration.
Assert.Throws<ArgumentNullException>(() =>
new WbMeshAdapter(gl: null!, datDir: "some/path", dats: null!, logger: NullLogger<WbMeshAdapter>.Instance));
}
[Fact]
public void Dispose_OnUninitializedAdapter_DoesNotThrow()
{
var adapter = WbMeshAdapter.CreateUninitialized();
adapter.Dispose(); // no-op when fields are null
adapter.Dispose(); // idempotent
}
[Fact]
public void IncrementRefCount_OnUninitializedAdapter_NoOps()
{
var adapter = WbMeshAdapter.CreateUninitialized();
// Should not throw, even though there's no underlying mesh manager.
adapter.IncrementRefCount(0x01000001ul);
}
[Fact]
public void DecrementRefCount_OnUninitializedAdapter_NoOps()
{
var adapter = WbMeshAdapter.CreateUninitialized();
adapter.DecrementRefCount(0x01000001ul);
}
[Fact]
public void GetRenderData_OnUninitializedAdapter_ReturnsNull()
{
var adapter = WbMeshAdapter.CreateUninitialized();
Assert.Null(adapter.GetRenderData(0x01000001ul));
}
[Fact]
public void Tick_OnUninitializedAdapter_DoesNotThrow()
{
var adapter = WbMeshAdapter.CreateUninitialized();
adapter.Tick(); // no-op, no throw
adapter.Tick(); // idempotent
}
[Fact]
public void Tick_AfterDispose_DoesNotThrow()
{
var adapter = WbMeshAdapter.CreateUninitialized();
adapter.Dispose();
adapter.Tick(); // no-op, no throw
}
}