libgui 2.01
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
GuiMeshCache.h
1/****************************************************************************
2 * libgui
3 * Daryl Borth 2026
4 * GuiMeshCache.h
5 *
6 * Platform-agnostic cache of shape meshes. Shapes that look the same (the
7 * keys of an on-screen keyboard, the rows of a list) share one mesh instead
8 * of tessellating and holding a copy each, and a mesh that keeps being drawn
9 * is handed to the video backend (ImageRenderer::createMesh()) to keep in its
10 * own ready-to-draw form, so drawing it again costs almost nothing on the CPU.
11 ***************************************************************************/
12#pragma once
13
17struct GuiMeshKey {
19 int width;
20 int height;
22 GuiPaint paint;
23 float feather;
24 float tolerance;
25
26 bool operator==(const GuiMeshKey& o) const;
27};
28
32class GuiSharedMesh
33{
34 public:
36 const std::vector<MeshVertex>& vertices() const { return mesh.vertices(); }
37 private:
38 friend class GuiMeshCache;
39 explicit GuiSharedMesh(const GuiMeshKey& k);
40
41 GuiMeshKey key;
42 GuiMesh mesh;
43 void * handle;
44 bool noHandle;
45 uint32_t uses;
46 int refs;
47 uint32_t idleStamp;
48};
49
54{
55 public:
57 static GuiSharedMesh * acquire(const GuiMeshKey& key);
60 static void release(GuiSharedMesh * mesh);
65 static void draw(GuiSharedMesh * mesh, float x, float y, float scaleX, float scaleY, uint8_t alpha, std::vector<MeshVertex>& scratch);
68 static void flush();
69};
Static, since there is one video backend.
static void draw(GuiSharedMesh *mesh, float x, float y, float scaleX, float scaleY, uint8_t alpha, std::vector< MeshVertex > &scratch)
Draws a mesh with its (0,0) at (x, y), stretched by scaleX/scaleY about that point.
static GuiSharedMesh * acquire(const GuiMeshKey &key)
Finds or builds the mesh for a key and takes a reference to it. Pair with release().
static void flush()
Frees every mesh nothing is holding, including the backend's copies (call when leaving the menu to gi...
static void release(GuiSharedMesh *mesh)
Gives back a reference from acquire().
Accumulates shapes as a triangle list of MeshVertex.
One cached mesh.
const std::vector< MeshVertex > & vertices() const
Gets the triangle list, in the shape's own coordinates (0,0 is its top-left)
SHAPE
Basic shape kinds a paint can be applied to.
Definition GuiPaint.h:17
Per-corner radii, in the order top-left, top-right, bottom-right, bottom-left.
Definition GuiGeometry.h:40
Everything that decides what a shape's triangles are.
float tolerance
Curve tolerance, see GuiMesh.
int width
Width in design-canvas pixels.
GuiCorners corners
Corner radii of a rectangle.
GuiPaint paint
Fill, outline and shadow.
SHAPE kind
Rectangle or ellipse.
float feather
Anti-aliasing fringe width, see GuiMesh.
int height
Height in design-canvas pixels.