Class ImGuiTexture
- Namespace
- BSGameLib.Game
- Assembly
- BSGameLib.Game.dll
Turns a ITexture into what ImGui.Image needs: a texture id, and the
UV rectangle covering it.
public static class ImGuiTexture
- Inheritance
-
ImGuiTexture
- Inherited Members
Remarks
The id is whatever the active render backend uses to find a texture again — a GL name
under OpenGL, a key the Vulkan backend resolves to a descriptor set. Both backends
already accept an arbitrary one in an ImGui draw command; what was missing was a public
way to obtain it, because BSGameLib.Game.Textures.ITexture.Handle is internal. Without this a game
has to reach for reflection, which is what BSGame/Game's Panel does today
and no longer needs to.
The UVs matter as much as the id. A SubTexture — every cell of an indexed atlas is one — shares its parent's id, so drawing it with the default 0,0–1,1 UVs paints the entire sheet rather than the one sprite that was asked for.
Methods
IdFor(ITexture)
The id ImGui.Image wants for this texture, or Zero if there
is none — an unloaded texture, or null.
public static nint IdFor(ITexture texture)
Parameters
textureITexture
Returns
Uv(ITexture, out Vector2, out Vector2)
The UV rectangle this texture occupies within the image IdFor(ITexture) names — 0,0 to 1,1 for a whole texture, the cell's own rectangle for a SubTexture.
public static void Uv(ITexture texture, out Vector2 uv0, out Vector2 uv1)