Files
Pal3.Unity/Assets/Scripts/Pal3.Game/Data/TextureCreationPolicy.cs
Jiaqi (0x7c13) Liu e870cf487a Add core protocol regression tests and copyright checks
Cover SCE command contracts, binary readers, resource layouts and full local CPK decompression for PAL3 and PAL3A. Fix CVD time rebasing, binary read bounds and short reads, and CPK/NAV validation.

Standardize first-party copyright headers, preserve correct creation years, and update console source generation. Validate both variants in Unity and verify all live CPK entries.
2026-11-12 13:37:27 +08:00

47 lines
2.0 KiB
C#

// ------------------------------------------------------------------------
// Copyright (c) 2026, Jiaqi (0x7c13) Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ------------------------------------------------------------------------
namespace Pal3.Game.Data
{
using System;
using Engine.Core.Abstraction;
public enum TextureUsage
{
World,
Sprite,
Skybox,
}
internal static class TextureCreationPolicy
{
private const int MinimumGeneratedMipSize = 64;
public static TextureCreateOptions Resolve(ITextureDataSource source, TextureUsage usage)
{
if (usage == TextureUsage.Sprite) return TextureCreateOptions.Readable;
// Six independently authored sky faces retain their original base-level sampling.
if (usage == TextureUsage.Skybox)
return new TextureCreateOptions(TextureMipMode.BaseOnly,
preferNativeCompression: true, keepCpuReadable: false);
// BMP/TGA world textures retain their original readable, base-only sampling for now.
if (source.Format == TextureDataFormat.Rgba32) return TextureCreateOptions.Readable;
// Alpha textures use complementary cutout/blend passes. Preserve base coverage
// until coverage-preserving mipmaps are validated against both cutoffs.
TextureMipMode mipmaps = TextureMipMode.BaseOnly;
if (!source.HasTransparency)
{
if (source.MipCount > 1) mipmaps = TextureMipMode.Preserve;
// Small baked-light tiles gain little from generated chains; authored mips stay.
else if (Math.Max(source.Width, source.Height) >= MinimumGeneratedMipSize)
mipmaps = TextureMipMode.GenerateIfMissing;
}
return new TextureCreateOptions(mipmaps, preferNativeCompression: true, keepCpuReadable: false);
}
}
}