mirror of
https://github.com/0x7c13/Pal3.Unity.git
synced 2026-11-26 17:38:10 +08:00
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.
47 lines
2.0 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|