Upgrade Raylib_cs to latest version, use safe version of LoadFontFromMemory in Raylib.

This commit is contained in:
2024-10-21 18:08:04 +02:00
parent 20036be50f
commit 503473c6b3
2 changed files with 21 additions and 31 deletions

View File

@@ -39,10 +39,10 @@ namespace Voile.Rendering
ConfigFlags flags = 0; ConfigFlags flags = 0;
// MSAA // MSAA
flags |= settings.Msaa == Msaa.Msaa4x ? ConfigFlags.FLAG_MSAA_4X_HINT : 0; flags |= settings.Msaa == Msaa.Msaa4x ? ConfigFlags.Msaa4xHint : 0;
// VSync // VSync
flags |= settings.UseVSync ? ConfigFlags.FLAG_VSYNC_HINT : 0; flags |= settings.UseVSync ? ConfigFlags.VSyncHint : 0;
_fullscreen = settings.Fullscreen; _fullscreen = settings.Fullscreen;
@@ -59,13 +59,13 @@ namespace Voile.Rendering
public override void CreateWindow(WindowSettings windowSettings) public override void CreateWindow(WindowSettings windowSettings)
{ {
Raylib.SetTraceLogLevel(TraceLogLevel.LOG_NONE); Raylib.SetTraceLogLevel(TraceLogLevel.None);
_defaultWindowSettings = windowSettings; _defaultWindowSettings = windowSettings;
_windowSize = windowSettings.Size; _windowSize = windowSettings.Size;
ConfigFlags windowFlags = 0; ConfigFlags windowFlags = 0;
windowFlags |= windowSettings.Resizable ? ConfigFlags.FLAG_WINDOW_RESIZABLE : 0; windowFlags |= windowSettings.Resizable ? ConfigFlags.ResizableWindow : 0;
_windowTitle = windowSettings.Title; _windowTitle = windowSettings.Title;
@@ -180,10 +180,10 @@ namespace Voile.Rendering
{ {
Raylib.DrawRectanglePro(new Rectangle() Raylib.DrawRectanglePro(new Rectangle()
{ {
x = transformPosition.X, X = transformPosition.X,
y = transformPosition.Y, Y = transformPosition.Y,
width = size.X, Width = size.X,
height = size.Y Height = size.Y
}, transformPivot, transformRotation, VoileColorToRaylibColor(color)); }, transformPivot, transformRotation, VoileColorToRaylibColor(color));
} }
@@ -252,28 +252,17 @@ namespace Voile.Rendering
return Raylib.GetCurrentMonitor(); return Raylib.GetCurrentMonitor();
} }
private unsafe void LoadFont(Font font) private void LoadFont(Font font)
{ {
Raylib_cs.Font fontRay; Raylib_cs.Font fontRay;
ReadOnlySpan<char> ext = ".ttf"; // TODO: don't use a hardcoded extension. string ext = ".ttf"; // TODO: don't use a hardcoded extension.
Span<byte> extBytes = new byte[Encoding.Default.GetByteCount(ext) + 1]; int fontChars = 250; // TODO: control this dynamically to not load the entire font.
Encoding.Default.GetBytes(ext, extBytes);
int fontChars = 2048; // TODO: control this dynamically to not load the entire font.
unsafe fontRay = Raylib.LoadFontFromMemory(ext, font.Buffer, font.Size, null, fontChars);
{
fixed (byte* extP = extBytes)
{
fixed (byte* bufferP = font.Buffer)
{
fontRay = Raylib.LoadFontFromMemory((sbyte*)extP, bufferP, (int)font.BufferSize, font.Size, null, fontChars);
}
}
}
Raylib.GenTextureMipmaps(ref fontRay.texture); Raylib.GenTextureMipmaps(ref fontRay.Texture);
Raylib.SetTextureFilter(fontRay.texture, TextureFilter.TEXTURE_FILTER_BILINEAR); Raylib.SetTextureFilter(fontRay.Texture, TextureFilter.Bilinear);
_fontPool.Add(fontRay); _fontPool.Add(fontRay);
@@ -288,14 +277,15 @@ namespace Voile.Rendering
{ {
fixed (void* dataPtr = texture.Buffer) fixed (void* dataPtr = texture.Buffer)
{ {
image.data = dataPtr; image.Data = dataPtr;
} }
} }
image.width = texture.Width;
image.height = texture.Height; image.Width = texture.Width;
image.mipmaps = texture.Mipmaps; image.Height = texture.Height;
image.format = (PixelFormat)texture.Format; image.Mipmaps = texture.Mipmaps;
image.Format = (PixelFormat)texture.Format;
Texture2D rayTexture; Texture2D rayTexture;

View File

@@ -15,7 +15,7 @@
<PackageReference Include="Tommy" Version="3.1.2" /> <PackageReference Include="Tommy" Version="3.1.2" />
<PackageReference Include="Voile.Fmod" Version="0.2.2.8" /> <PackageReference Include="Voile.Fmod" Version="0.2.2.8" />
<PackageReference Include="ImGui.NET" Version="1.89.4" /> <PackageReference Include="ImGui.NET" Version="1.89.4" />
<PackageReference Include="Raylib-cs" Version="4.2.0.1" /> <PackageReference Include="Raylib-cs" Version="6.1.1" />
<PackageReference Include="SharpFont" Version="4.0.1" /> <PackageReference Include="SharpFont" Version="4.0.1" />
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta19" /> <PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta19" />
<PackageReference Include="StbImageSharp" Version="2.27.13" /> <PackageReference Include="StbImageSharp" Version="2.27.13" />