0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-05-18 19:31:17 +03:00
ParkanPlayground/NResUI/Models/TexmExplorerViewModel.cs

69 lines
1.6 KiB
C#
Raw Permalink Normal View History

2024-11-19 03:07:58 +03:00
using System.Numerics;
using Silk.NET.OpenGL;
2024-11-19 02:13:14 +03:00
using TexmLib;
2024-11-15 19:06:44 +03:00
namespace NResUI.Models;
2024-11-18 23:48:42 +03:00
public class TexmExplorerViewModel
2024-11-15 19:06:44 +03:00
{
public bool HasFile { get; set; }
public string? Error { get; set; }
2024-11-18 23:48:42 +03:00
public TexmFile? TexmFile { get; set; }
2024-11-19 02:13:14 +03:00
2024-11-15 19:06:44 +03:00
public string? Path { get; set; }
2024-11-19 02:13:14 +03:00
public List<OpenGlTexture> GlTextures { get; set; } = [];
private bool _glTexturesDirty = false;
public bool IsWhiteBgEnabled;
public bool IsBlackBgEnabled;
2024-11-19 02:28:49 +03:00
public bool DoubleSize;
2024-11-19 03:07:58 +03:00
public bool ViewPages;
2024-11-19 02:13:14 +03:00
2024-11-18 23:48:42 +03:00
public void SetParseResult(TexmParseResult result, string path)
2024-11-15 19:06:44 +03:00
{
Error = result.Error;
2024-11-18 23:48:42 +03:00
if (result.TexmFile != null)
2024-11-15 19:06:44 +03:00
{
HasFile = true;
}
2024-11-18 23:48:42 +03:00
TexmFile = result.TexmFile;
2024-11-15 19:06:44 +03:00
Path = path;
2024-11-19 02:13:14 +03:00
_glTexturesDirty = true;
}
/// <summary>
/// Сгенерировать OpenGL текстуры из всех мипмапов Texm файла
/// </summary>
public void GenerateGlTextures(GL gl)
{
if (_glTexturesDirty && TexmFile is not null)
{
foreach (var glTexture in GlTextures)
{
glTexture.Dispose();
}
GlTextures.Clear();
for (var i = 0; i < TexmFile!.Header.MipmapCount; i++)
{
var bytes = TexmFile.GetRgba32BytesFromMipmap(i, out var width, out var height);
var glTexture = new OpenGlTexture(
gl,
width,
height,
bytes
);
GlTextures.Add(glTexture);
}
_glTexturesDirty = false;
}
2024-11-15 19:06:44 +03:00
}
}