refactor(pipeline): MP1a - lift TextureKey out of the GL atlas class

This commit is contained in:
Erik 2026-07-05 20:01:56 +02:00
parent 651d041e5a
commit d778930853
3 changed files with 39 additions and 29 deletions

View file

@ -15,6 +15,7 @@ using System.Numerics;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using AcDream.Content;
using AcDream.Core.Rendering.Wb; using AcDream.Core.Rendering.Wb;
using PixelFormat = Silk.NET.OpenGL.PixelFormat; using PixelFormat = Silk.NET.OpenGL.PixelFormat;
using BoundingBox = Chorizite.Core.Lib.BoundingBox; using BoundingBox = Chorizite.Core.Lib.BoundingBox;
@ -114,7 +115,7 @@ namespace AcDream.App.Rendering.Wb {
public class MeshBatchData { public class MeshBatchData {
public ushort[] Indices { get; set; } = Array.Empty<ushort>(); public ushort[] Indices { get; set; } = Array.Empty<ushort>();
public (int Width, int Height, TextureFormat Format) TextureFormat { get; set; } 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 int TextureIndex { get; set; }
public byte[] TextureData { get; set; } = Array.Empty<byte>(); public byte[] TextureData { get; set; } = Array.Empty<byte>();
public PixelFormat? UploadPixelFormat { get; set; } public PixelFormat? UploadPixelFormat { get; set; }
@ -126,7 +127,7 @@ namespace AcDream.App.Rendering.Wb {
/// CPU-side texture info for deduplication during background preparation. /// CPU-side texture info for deduplication during background preparation.
/// </summary> /// </summary>
public class TextureBatchData { public class TextureBatchData {
public TextureAtlasManager.TextureKey Key { get; set; } public TextureKey Key { get; set; }
public byte[] TextureData { get; set; } = Array.Empty<byte>(); public byte[] TextureData { get; set; } = Array.Empty<byte>();
public PixelFormat? UploadPixelFormat { get; set; } public PixelFormat? UploadPixelFormat { get; set; }
public PixelType? UploadPixelType { 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 (int Width, int Height) TextureSize { get; set; }
public TextureFormat TextureFormat { get; set; } public TextureFormat TextureFormat { get; set; }
public uint SurfaceId { 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 DatReaderWriter.Enums.CullMode CullMode { get; set; }
public bool IsTransparent { get; set; } public bool IsTransparent { get; set; }
public bool IsAdditive { get; set; } public bool IsAdditive { get; set; }
@ -1283,7 +1284,7 @@ namespace AcDream.App.Rendering.Wb {
} }
var format = (texWidth, texHeight, textureFormat); var format = (texWidth, texHeight, textureFormat);
var key = new TextureAtlasManager.TextureKey { var key = new TextureKey {
SurfaceId = surfaceId, SurfaceId = surfaceId,
PaletteId = paletteId, PaletteId = paletteId,
Stippling = poly.Stippling, Stippling = poly.Stippling,
@ -1628,7 +1629,7 @@ namespace AcDream.App.Rendering.Wb {
sourceFormat == DatReaderWriter.Enums.PixelFormat.PFID_DXT5))); sourceFormat == DatReaderWriter.Enums.PixelFormat.PFID_DXT5)));
var format = (texWidth, texHeight, textureFormat); var format = (texWidth, texHeight, textureFormat);
var key = new TextureAtlasManager.TextureKey { var key = new TextureKey {
SurfaceId = surfaceId, SurfaceId = surfaceId,
PaletteId = paletteId, PaletteId = paletteId,
Stippling = poly.Stippling, Stippling = poly.Stippling,
@ -2233,7 +2234,7 @@ namespace AcDream.App.Rendering.Wb {
new MeshBatchData { new MeshBatchData {
Indices = indices.ToArray(), Indices = indices.ToArray(),
TextureFormat = (1, 1, TextureFormat.RGBA8), TextureFormat = (1, 1, TextureFormat.RGBA8),
TextureKey = new TextureAtlasManager.TextureKey { TextureKey = new TextureKey {
SurfaceId = 0xFFFFFFFF, // Dummy surface ID SurfaceId = 0xFFFFFFFF, // Dummy surface ID
PaletteId = 0, PaletteId = 0,
Stippling = StipplingType.NoPos, Stippling = StipplingType.NoPos,
@ -2251,7 +2252,7 @@ namespace AcDream.App.Rendering.Wb {
[(1, 1, TextureFormat.RGBA8)] = new List<TextureBatchData> { [(1, 1, TextureFormat.RGBA8)] = new List<TextureBatchData> {
new TextureBatchData { new TextureBatchData {
Indices = indices.ToList(), Indices = indices.ToList(),
Key = new TextureAtlasManager.TextureKey { Key = new TextureKey {
SurfaceId = 0xFFFFFFFF, // Dummy surface ID SurfaceId = 0xFFFFFFFF, // Dummy surface ID
PaletteId = 0, PaletteId = 0,
Stippling = StipplingType.NoPos, Stippling = StipplingType.NoPos,

View file

@ -1,3 +1,4 @@
using AcDream.Content;
using Chorizite.Core.Render; using Chorizite.Core.Render;
using Chorizite.Core.Render.Enums; using Chorizite.Core.Render.Enums;
using DatReaderWriter.Enums; using DatReaderWriter.Enums;
@ -94,27 +95,5 @@ namespace AcDream.App.Rendering.Wb {
_refCounts.Clear(); _refCounts.Clear();
_freeSlots.Clear(); _freeSlots.Clear();
} }
public struct TextureKey : IEquatable<TextureKey> {
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);
}
}
} }
} }

View file

@ -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<TextureKey> {
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);
}
}