9#include <coreinit/time.h>
10#include <gx2/sampler.h>
11#include <gx2/texture.h>
12#include "../VideoDriver.h"
19enum class OutputTarget
25static const int OUTPUT_TARGET_COUNT = 2;
61 float colorIntensity[4];
77 ~WutVideoDriver()
override;
79 void init(
int width,
int height)
override;
96 int getTargetWidth(OutputTarget target)
const {
return targetWidth[(int)target]; }
97 int getTargetHeight(OutputTarget target)
const {
return targetHeight[(int)target]; }
114 void presentBuffer();
154 void setUiTargets(
unsigned mask) { uiTargets = mask; }
177 static const size_t cuMaxQueuedDraws = 4096;
178 std::vector<WutDrawCmd> drawQueue;
184 static const uint32_t cuMeshArenaVertices = 1u << 18;
185 float * meshPositions =
nullptr;
186 uint8_t * meshColors =
nullptr;
187 uint32_t meshUsed = 0;
188 uint32_t meshFlushed = 0;
191 Mutex * retireLock =
nullptr;
192 WutMesh * retiredMeshes =
nullptr;
193 void freeRetiredMeshes();
194 void replayDrawQueue()
const;
197 bool gpuFramesInFlight =
false;
198 OSTime lastSubmitTimeStamp = 0;
202 void computeUIScale();
206 float uiScale = 1.0f;
207 int targetWidth[OUTPUT_TARGET_COUNT] = { 0, 0 };
208 int targetHeight[OUTPUT_TARGET_COUNT] = { 0, 0 };
209 PixelColor clearColor;
211 ImageRenderer * imageRenderer;
212 GlyphRenderer * glyphRenderer;
224 void loadTextureData(
void * texture,
const uint8_t * rgba,
int width,
int height)
override;
225 bool canReuseTexture(
int allocWidth,
int allocHeight,
int width,
int height)
const override;
227 void drawTexture(
void * texture,
float xpos,
float ypos, uint16_t width, uint16_t height,
float degrees,
float scaleX,
float scaleY, uint8_t alpha)
override;
232 void drawMeshInstance(
void* mesh,
float x,
float y,
float scaleX,
float scaleY)
override;
248 void*
createTexture(uint16_t width, uint16_t height)
override;
252 void drawQuad(
void* texture, int16_t screenX, int16_t screenY, uint16_t width, uint16_t height,
const PixelColor& color)
override;
253 void drawFeature(int16_t screenX, int16_t screenY, uint16_t width, uint16_t height,
const PixelColor& color)
override;
Draws glyph textures and solid rectangles on behalf of GuiTextRenderer.
Platform image/texture backend GuiImageData and GuiImage delegate to.
A simple mutual-exclusion lock.
Platform video backend owning the frame lifecycle (init/render/clear, screen size,...
void drawQuad(void *texture, int16_t screenX, int16_t screenY, uint16_t width, uint16_t height, const PixelColor &color) override
Draws a glyph texture as a quad tinted with color.
void drawFeature(int16_t screenX, int16_t screenY, uint16_t width, uint16_t height, const PixelColor &color) override
Draws a solid-color rectangle used for text decoration (underline/strike-through).
void destroyTexture(void *texture) override
Destroys a texture created by createTexture().
WutGlyphRenderer(WutVideoDriver *driver)
void * createTexture(uint16_t width, uint16_t height) override
Allocates an empty single-channel glyph texture. Returns an opaque handle.
void loadTextureData(void *texture, FT_Bitmap *bitmap) override
Uploads a rasterized FreeType glyph bitmap into a texture from createTexture().
void drawMeshInstance(void *mesh, float x, float y, float scaleX, float scaleY) override
Draws a mesh from createMesh() fully opaque, as its vertex colors say.
void destroyTexture(void *texture) override
Destroys a texture created by createTexture.
void destroyMesh(void *mesh) override
Releases a mesh from createMesh().
void loadTextureData(void *texture, const uint8_t *rgba, int width, int height) override
Loads raw RGBA8 pixels into the pre-allocated texture.
void * createTexture(int width, int height) override
Allocates an empty hardware-aligned texture buffer.
void drawRectangle(float x, float y, float width, float height, PixelColor color) override
Draws a solid-color rectangle (alpha-blended using color.a).
void drawMesh(const MeshVertex *vertices, size_t count) override
Draws a triangle list: three vertices per triangle, each with its own color.
void * createMesh(const MeshVertex *vertices, size_t count) override
Hands a triangle list to the backend to keep in its own ready-to-draw form (a GX display list,...
void drawTexture(void *texture, float xpos, float ypos, uint16_t width, uint16_t height, float degrees, float scaleX, float scaleY, uint8_t alpha) override
Draws a texture created by createTexture.
bool canReuseTexture(int allocWidth, int allocHeight, int width, int height) const override
Whether a texture allocated for allocWidth x allocHeight can be reloaded in place.
WutImageRenderer(WutVideoDriver *driver)
Wii U VideoDriver: GX2 + libwhb's WHBGfx* helpers.
uint32_t getFrameTimer() override
void clearScreen(const PixelColor &color) override
Clears the current frame buffer.
static const unsigned kAllTargets
Which outputs flushDrawQueue() replays into (bit per OutputTarget: 1 << TV, 1 << DRC).
void queueDraw(const WutDrawCmd &cmd)
Records a UI draw for the next flushDrawQueue().
int getScreenHeight() const override
float getUIScale() const override
Ratio of physical render-target pixels to design-canvas pixels (the width/height passed to init()).
GlyphRenderer * getGlyphRenderer() override
bool isPresentPending() const
True while the last presented frame has not finished: not yet on screen (the swap is waiting for the ...
void retireMesh(WutMesh *mesh)
Sets a mesh aside to be freed once the GPU is done with every frame that might draw it.
ImageRenderer * getImageRenderer() override
void queueMesh(const MeshVertex *vertices, size_t count)
Copies a triangle list into this frame's vertex arena (converting positions to NDC) and records a Mes...
float getDeltaTime() const override
void render() override
Flushes the current frame to the screen and swaps buffers.
int getRefreshRate() const override
void init(int width, int height) override
void queueMeshInstance(const WutMesh *mesh, float x, float y, float scaleX, float scaleY)
Records a draw of a mesh made by WutImageRenderer::createMesh().
void shutdown() override
Releases the video backend. Call after every other user of the renderers has finished.
int getTargetWidth(OutputTarget target) const
Physical pixel size of a render target (the TV follows the console's output setting,...
int getScreenWidth() const override
void flushDrawQueue()
Replays every recorded UI draw into the TV context, then the same list into the GamePad context,...
void waitForIdle()
Waits until the GPU has retired the last submitted frame.
bool isForeground() const
False once the OS has taken away the foreground (HOME menu overlay, forced exit, etc....
A single 2D vertex with its own color, in design-canvas coordinates.
8-bit-per-channel RGBA color used by the video interfaces.
One recorded UI draw (image, glyph quad or flat rectangle).
Kind
Which shader a queued draw goes through.
@ Mesh
triangle list from the mesh arena through ColorShader (see WutVideoDriver::queueMesh())
@ TextureRotated
textured quad whose corners were pre-rotated into a Texture2DShader rotated slot
@ Texture
textured quad through Texture2DShader, shader-side angle/offset/scale
@ Color
flat-color quad through ColorShader
@ MeshInstance
a WutMesh through ColorShader, placed by the shader-side offset/scale (see WutVideoDriver::queueMeshI...
float offset[3]
NDC position (unused by TextureRotated)
const GX2Sampler * sampler
Texture/TextureRotated only.
float angle
Texture only, radians.
float scale[3]
NDC half-extents (unused by TextureRotated)
uint32_t slot
TextureRotated only: slot from Texture2DShader::uploadRotatedQuad()
uint32_t first
Mesh only: index of the first vertex in the arena.
uint32_t count
Mesh only: number of vertices.
const GX2Texture * texture
Texture/TextureRotated only.
const WutMesh * mesh
MeshInstance only.
A mesh kept in GPU-readable vertex buffers across frames (ImageRenderer::createMesh()).
WutMesh * next
Link in the retired list.
uint32_t count
Number of vertices.
uint8_t * colors
RGBA8 per vertex.
float * positions
3 floats per vertex (x, y, 0)