mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-06-18 23:59:46 +03:00
texture viewer
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user