Skip to content

How to use

xtuzy edited this page May 3, 2023 · 33 revisions

Reference nuget

Necessary nuget

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.

Additional nuget

How to use VeldridView

  1. Add .UseVeldridView() to your MauiProgram.cs

  2. Create a Drawable

  3. 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:

How to process image/model asset in project

  • 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.