-
Notifications
You must be signed in to change notification settings - Fork 3
How to use
I advice you reference my Veldrid.Maui.Controls latest in your project, it contain librarys that you must reference, see PackageReferences. If you want use Vulkan in iOS and Maccatalyst, you must install Veldrid.VK.MauiNativeAsset, it contain static library from MoltenVK.
These packages at my Github Packages, so you need add source for install they in Command Line:
dotnet nuget add source --username USERNAME --password GITHUB_TOKEN --store-password-in-clear-text --name github "https://nuget.pkg.github.com/xtuzy/index.json"
The detail of installing packages in Github Packages see working-with-the-nuget-registry.
Or, you can download all nuget packages to your local folder, add this folder as your nuget source.
Note: These packages have little change to fix bug for run Veldrid in Maui compare with Official Veldrid, but use same packages name as Official Veldrid packages, for cover Official Veldrid packages, my packages latest version number is bigger than Official Veldrid packages. So, you must use latest Veldrid.Maui.Controls to make sure you are using the correct package.
-
For convert shader, you can use Veldrid.SPIRV 1.0.16(Official is 1.0.15), but it is big (20m), maybe you need convert shader when build, not at runtime.
-
For use models, you can use AssimpNet for desktop, AssimpNet.Mobile.Native.Android for android, AssimpNet.Mobile.Native.iOS for ios, but AssimpNet is big, maybe you need another library.
-
Add
.UseVeldridView()
to your MauiProgram.cs -
Create a Drawable
-
Create VeldridView and set VeldridView.Drawable property.
Notice: i advice use a Grid as a container of VeldridView, set size of this Grid, not set size of VeldridView directly.
How to use Veldrid in Drawable
VeldridView.Drawable like GraphicsView.Drawable, but type is BaseGpuDrawable, it provide GraphicsDevice, ResourceFactory, MainSwapchain.
- If you have GPU programming experience, you can learn what are they and how to use they from veldrid doc.
- If you haven't GPU programming experience, first see learnopengl, then see how to realize in veldrid:
- Preprocess
Considering the low performance when run process raw image, Veldrid supply AssetProcessor to preprocess image. It use ImageSharp to preprocess image to mipmap.
- Store
I advice you create net6.0 project to store assets(have preprocessed) in a folder, you can set these assets as EmbeddedResource:
<ItemGroup>
<EmbeddedResource Include="TexturedCube\Assets\**">
</EmbeddedResource>
</ItemGroup>
you can use BaseGpuDrawableExtension to read them as byte[] or stream.
- Read
We need deserialize assets(have preprocessed) to get texture data, veldrid supply AssetPrimitives. you can see sample how to read they.