From d778930853731500972126b69ac8e381d29bd563 Mon Sep 17 00:00:00 2001 From: Erik Date: Sun, 5 Jul 2026 20:01:56 +0200 Subject: [PATCH] refactor(pipeline): MP1a - lift TextureKey out of the GL atlas class --- .../Rendering/Wb/ObjectMeshManager.cs | 15 +++++----- .../Rendering/Wb/TextureAtlasManager.cs | 23 +------------- src/AcDream.Content/TextureKey.cs | 30 +++++++++++++++++++ 3 files changed, 39 insertions(+), 29 deletions(-) create mode 100644 src/AcDream.Content/TextureKey.cs diff --git a/src/AcDream.App/Rendering/Wb/ObjectMeshManager.cs b/src/AcDream.App/Rendering/Wb/ObjectMeshManager.cs index b9261ad1..7d9368ef 100644 --- a/src/AcDream.App/Rendering/Wb/ObjectMeshManager.cs +++ b/src/AcDream.App/Rendering/Wb/ObjectMeshManager.cs @@ -15,6 +15,7 @@ using System.Numerics; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; +using AcDream.Content; using AcDream.Core.Rendering.Wb; using PixelFormat = Silk.NET.OpenGL.PixelFormat; using BoundingBox = Chorizite.Core.Lib.BoundingBox; @@ -114,7 +115,7 @@ namespace AcDream.App.Rendering.Wb { public class MeshBatchData { public ushort[] Indices { get; set; } = Array.Empty(); public (int Width, int Height, TextureFormat Format) TextureFormat { get; set; } - public TextureAtlasManager.TextureKey TextureKey { get; set; } + public TextureKey TextureKey { get; set; } public int TextureIndex { get; set; } public byte[] TextureData { get; set; } = Array.Empty(); public PixelFormat? UploadPixelFormat { get; set; } @@ -126,7 +127,7 @@ namespace AcDream.App.Rendering.Wb { /// CPU-side texture info for deduplication during background preparation. /// public class TextureBatchData { - public TextureAtlasManager.TextureKey Key { get; set; } + public TextureKey Key { get; set; } public byte[] TextureData { get; set; } = Array.Empty(); public PixelFormat? UploadPixelFormat { get; set; } public PixelType? UploadPixelType { get; set; } @@ -187,7 +188,7 @@ namespace AcDream.App.Rendering.Wb { public (int Width, int Height) TextureSize { get; set; } public TextureFormat TextureFormat { get; set; } public uint SurfaceId { get; set; } - public TextureAtlasManager.TextureKey Key { get; set; } + public TextureKey Key { get; set; } public DatReaderWriter.Enums.CullMode CullMode { get; set; } public bool IsTransparent { get; set; } public bool IsAdditive { get; set; } @@ -1283,7 +1284,7 @@ namespace AcDream.App.Rendering.Wb { } var format = (texWidth, texHeight, textureFormat); - var key = new TextureAtlasManager.TextureKey { + var key = new TextureKey { SurfaceId = surfaceId, PaletteId = paletteId, Stippling = poly.Stippling, @@ -1628,7 +1629,7 @@ namespace AcDream.App.Rendering.Wb { sourceFormat == DatReaderWriter.Enums.PixelFormat.PFID_DXT5))); var format = (texWidth, texHeight, textureFormat); - var key = new TextureAtlasManager.TextureKey { + var key = new TextureKey { SurfaceId = surfaceId, PaletteId = paletteId, Stippling = poly.Stippling, @@ -2233,7 +2234,7 @@ namespace AcDream.App.Rendering.Wb { new MeshBatchData { Indices = indices.ToArray(), TextureFormat = (1, 1, TextureFormat.RGBA8), - TextureKey = new TextureAtlasManager.TextureKey { + TextureKey = new TextureKey { SurfaceId = 0xFFFFFFFF, // Dummy surface ID PaletteId = 0, Stippling = StipplingType.NoPos, @@ -2251,7 +2252,7 @@ namespace AcDream.App.Rendering.Wb { [(1, 1, TextureFormat.RGBA8)] = new List { new TextureBatchData { Indices = indices.ToList(), - Key = new TextureAtlasManager.TextureKey { + Key = new TextureKey { SurfaceId = 0xFFFFFFFF, // Dummy surface ID PaletteId = 0, Stippling = StipplingType.NoPos, diff --git a/src/AcDream.App/Rendering/Wb/TextureAtlasManager.cs b/src/AcDream.App/Rendering/Wb/TextureAtlasManager.cs index 8ce969d1..8751c689 100644 --- a/src/AcDream.App/Rendering/Wb/TextureAtlasManager.cs +++ b/src/AcDream.App/Rendering/Wb/TextureAtlasManager.cs @@ -1,3 +1,4 @@ +using AcDream.Content; using Chorizite.Core.Render; using Chorizite.Core.Render.Enums; using DatReaderWriter.Enums; @@ -94,27 +95,5 @@ namespace AcDream.App.Rendering.Wb { _refCounts.Clear(); _freeSlots.Clear(); } - - public struct TextureKey : IEquatable { - public uint SurfaceId; - public uint PaletteId; - public StipplingType Stippling; - public bool IsSolid; - - public bool Equals(TextureKey other) { - return SurfaceId == other.SurfaceId && - PaletteId == other.PaletteId && - Stippling == other.Stippling && - IsSolid == other.IsSolid; - } - - public override bool Equals(object? obj) { - return obj is TextureKey other && Equals(other); - } - - public override int GetHashCode() { - return HashCode.Combine(SurfaceId, PaletteId, Stippling, IsSolid); - } - } } } diff --git a/src/AcDream.Content/TextureKey.cs b/src/AcDream.Content/TextureKey.cs new file mode 100644 index 00000000..3fe41827 --- /dev/null +++ b/src/AcDream.Content/TextureKey.cs @@ -0,0 +1,30 @@ +using DatReaderWriter.Enums; +using System; + +namespace AcDream.Content; + +// MP1a (2026-07-05): lifted verbatim out of TextureAtlasManager (GL class) +// so the GL-free mesh-extraction path (MeshExtractor / ObjectMeshData) can +// reference the atlas dedup key without a Silk.NET dependency. Field set, +// equality semantics, and hash behavior are UNCHANGED. +public struct TextureKey : IEquatable { + public uint SurfaceId; + public uint PaletteId; + public StipplingType Stippling; + public bool IsSolid; + + public bool Equals(TextureKey other) { + return SurfaceId == other.SurfaceId && + PaletteId == other.PaletteId && + Stippling == other.Stippling && + IsSolid == other.IsSolid; + } + + public override bool Equals(object? obj) { + return obj is TextureKey other && Equals(other); + } + + public override int GetHashCode() { + return HashCode.Combine(SurfaceId, PaletteId, Stippling, IsSolid); + } +}