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"); var imagePath = Path.ChangeExtension(fontPath, ".png");
ImageUtils.ImageInfoFromFile(imagePath, out var width, out var height, out var sizeInBytes); 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); var uploader = new ResourceUploader(graphicsDevice);
ImageUtils.DecodeIntoTransferBuffer( var texture = uploader.CreateTexture2DFromCompressed(imagePath);
imagePath, uploader.Upload();
transferBuffer, uploader.Dispose();
0,
TransferOptions.Overwrite
);
commandBuffer.BeginCopyPass();
commandBuffer.UploadToTexture(
transferBuffer,
texture,
WriteOptions.SafeOverwrite
);
commandBuffer.EndCopyPass();
transferBuffer.Dispose();
NativeMemory.Free(fontFileByteBuffer); NativeMemory.Free(fontFileByteBuffer);
NativeMemory.Free(atlasFileByteBuffer); NativeMemory.Free(atlasFileByteBuffer);