libgui 2.01
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
VideoDriver.h
1/****************************************************************************
2 * Platform Abstraction Layer
3 * Daryl Borth 2026
4 * VideoDriver.h
5 *
6 * Platform video backend GuiImage and GuiText delegates to. Exactly one driver
7 * implements this and assigns the single global instance below
8 ***************************************************************************/
9#pragma once
10
11#include <stdint.h>
12#include <stddef.h>
13#include <ft2build.h>
14#include FT_FREETYPE_H
15#include "Mesh.h"
16
17// PixelColor and MeshVertex live in Mesh.h so host builds can use them without FreeType
18
19class ImageRenderer;
20class GlyphRenderer;
21
28{
29 public:
30 virtual ~VideoDriver() = default;
31
34 virtual void init(int width, int height) = 0;
36 virtual void shutdown() = 0;
37
39 virtual void render() = 0;
40
42 virtual void clearScreen(const PixelColor& color) = 0;
43
45 virtual int getScreenWidth() const = 0;
47 virtual int getScreenHeight() const = 0;
49 virtual uint32_t getFrameTimer() = 0;
51 virtual int getRefreshRate() const = 0;
53 virtual float getDeltaTime() const = 0;
54
58 virtual float getUIScale() const { return 1.0f; }
59
64};
65
72{
73 public:
74 virtual ~ImageRenderer() = default;
76 virtual void * createTexture(int width, int height) = 0;
78 virtual void loadTextureData(void * texture, const uint8_t * rgba, int width, int height) = 0;
80 virtual bool canReuseTexture(int allocWidth, int allocHeight, int width, int height) const
81 {
82 return width <= allocWidth && height <= allocHeight;
83 }
84
85 virtual void destroyTexture(void * texture) = 0;
87 virtual void drawTexture(void * texture, float xpos, float ypos, uint16_t width, uint16_t height, float degrees, float scaleX, float scaleY, uint8_t alpha) = 0;
89 virtual void drawRectangle(float x, float y, float width, float height, PixelColor color) = 0;
99 virtual void drawMesh(const MeshVertex* vertices, size_t count) = 0;
100
108 virtual void* createMesh(const MeshVertex* vertices, size_t count) { (void)vertices; (void)count; return nullptr; }
111 virtual void destroyMesh(void* mesh) { (void)mesh; }
119 virtual void drawMeshInstance(void* mesh, float x, float y, float scaleX, float scaleY) { (void)mesh; (void)x; (void)y; (void)scaleX; (void)scaleY; }
120};
121
125 public:
126 virtual ~GlyphRenderer() = default;
127
129 virtual void* createTexture(uint16_t width, uint16_t height) = 0;
131 virtual void loadTextureData(void* texture, FT_Bitmap* bitmap) = 0;
133 virtual void destroyTexture(void* texture) = 0;
134
136 virtual void drawQuad(void* texture, int16_t screenX, int16_t screenY, uint16_t width, uint16_t height, const PixelColor& color) = 0;
138 virtual void drawFeature(int16_t screenX, int16_t screenY, uint16_t width, uint16_t height, const PixelColor& color) = 0;
139};
Draws glyph textures and solid rectangles on behalf of GuiTextRenderer.
virtual void destroyTexture(void *texture)=0
Destroys a texture created by createTexture().
virtual void drawQuad(void *texture, int16_t screenX, int16_t screenY, uint16_t width, uint16_t height, const PixelColor &color)=0
Draws a glyph texture as a quad tinted with color.
virtual void * createTexture(uint16_t width, uint16_t height)=0
Allocates an empty single-channel glyph texture. Returns an opaque handle.
virtual void drawFeature(int16_t screenX, int16_t screenY, uint16_t width, uint16_t height, const PixelColor &color)=0
Draws a solid-color rectangle used for text decoration (underline/strike-through).
virtual void loadTextureData(void *texture, FT_Bitmap *bitmap)=0
Uploads a rasterized FreeType glyph bitmap into a texture from createTexture().
Platform image/texture backend GuiImageData and GuiImage delegate to.
Definition VideoDriver.h:72
virtual void * createTexture(int width, int height)=0
Allocates an empty hardware-aligned texture buffer.
virtual void destroyMesh(void *mesh)
Releases a mesh from createMesh().
virtual void drawMeshInstance(void *mesh, float x, float y, float scaleX, float scaleY)
Draws a mesh from createMesh() fully opaque, as its vertex colors say.
virtual void drawTexture(void *texture, float xpos, float ypos, uint16_t width, uint16_t height, float degrees, float scaleX, float scaleY, uint8_t alpha)=0
Draws a texture created by createTexture.
virtual void loadTextureData(void *texture, const uint8_t *rgba, int width, int height)=0
Loads raw RGBA8 pixels into the pre-allocated texture.
virtual void * createMesh(const MeshVertex *vertices, size_t count)
Hands a triangle list to the backend to keep in its own ready-to-draw form (a GX display list,...
virtual void drawMesh(const MeshVertex *vertices, size_t count)=0
Draws a triangle list: three vertices per triangle, each with its own color.
virtual void destroyTexture(void *texture)=0
Destroys a texture created by createTexture.
virtual void drawRectangle(float x, float y, float width, float height, PixelColor color)=0
Draws a solid-color rectangle (alpha-blended using color.a).
virtual bool canReuseTexture(int allocWidth, int allocHeight, int width, int height) const
Whether a texture allocated for allocWidth x allocHeight can be reloaded in place.
Definition VideoDriver.h:80
Platform video backend owning the frame lifecycle (init/render/clear, screen size,...
Definition VideoDriver.h:28
virtual int getScreenWidth() const =0
virtual int getScreenHeight() const =0
virtual void init(int width, int height)=0
virtual GlyphRenderer * getGlyphRenderer()=0
virtual void clearScreen(const PixelColor &color)=0
Clears the current frame buffer.
virtual void render()=0
Flushes the current frame to the screen and swaps buffers.
virtual int getRefreshRate() const =0
virtual ImageRenderer * getImageRenderer()=0
virtual uint32_t getFrameTimer()=0
virtual float getUIScale() const
Ratio of physical render-target pixels to design-canvas pixels (the width/height passed to init()).
Definition VideoDriver.h:58
virtual float getDeltaTime() const =0
virtual void shutdown()=0
Releases the video backend. Call after every other user of the renderers has finished.
A single 2D vertex with its own color, in design-canvas coordinates.
Definition Mesh.h:27
8-bit-per-channel RGBA color used by the video interfaces.
Definition Mesh.h:16