streamline Font loading

what_if_no_video_threads
cosmonaut 2024-03-05 22:50:45 -08:00
parent 3c832550d0
commit 33ed8b2364
1 changed files with 4 additions and 17 deletions

View File

@ -49,25 +49,12 @@ namespace MoonWorks.Graphics.Font
var imagePath = Path.ChangeExtension(fontPath, ".png");
ImageUtils.ImageInfoFromFile(imagePath, out var width, out var height, out var sizeInBytes);
var texture = Texture.CreateTexture2D(graphicsDevice, width, height, TextureFormat.R8G8B8A8, TextureUsageFlags.Sampler);
var transferBuffer = new TransferBuffer(graphicsDevice, sizeInBytes);
ImageUtils.DecodeIntoTransferBuffer(
imagePath,
transferBuffer,
0,
TransferOptions.Overwrite
);
var uploader = new ResourceUploader(graphicsDevice);
var texture = uploader.CreateTexture2DFromCompressed(imagePath);
uploader.Upload();
uploader.Dispose();
commandBuffer.BeginCopyPass();
commandBuffer.UploadToTexture(
transferBuffer,
texture,
WriteOptions.SafeOverwrite
);
commandBuffer.EndCopyPass();
transferBuffer.Dispose();
NativeMemory.Free(fontFileByteBuffer);
NativeMemory.Free(atlasFileByteBuffer);