0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-06-18 23:59:46 +03:00

texture viewer

This commit is contained in:
bird_egop
2024-11-19 02:13:14 +03:00
parent 08c8d07d91
commit 5f84617567
5 changed files with 285 additions and 28 deletions

View File

@ -1,4 +1,5 @@
using TexmLib;
using Silk.NET.OpenGL;
using TexmLib;
namespace NResUI.Models;
@ -8,9 +9,15 @@ public class TexmExplorerViewModel
public string? Error { get; set; }
public TexmFile? TexmFile { get; set; }
public string? Path { get; set; }
public List<OpenGlTexture> GlTextures { get; set; } = [];
private bool _glTexturesDirty = false;
public bool IsWhiteBgEnabled;
public bool IsBlackBgEnabled;
public void SetParseResult(TexmParseResult result, string path)
{
Error = result.Error;
@ -22,6 +29,38 @@ public class TexmExplorerViewModel
TexmFile = result.TexmFile;
Path = path;
_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;
}
}
}