libgui 2.01
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
ColorShader Class Reference

Flat-color quad shader (rectangles, keyboard/dialog chrome), used via WutGlyphRenderer's drawFeature(). More...

#include <ColorShader.h>

Inheritance diagram for ColorShader:
[legend]

Public Member Functions

void setShaders () const
 Binds the fetch, vertex and pixel shaders for subsequent draws.
 
void resetFrame ()
 Call once per frame, before any draws - rewinds the per-draw color slot counter so this frame starts writing from slot 0 again.
 
void setAttributeBuffer (const uint8_t *colorAttr)
 
void bindMesh (const float *positions, const uint8_t *colors, uint32_t vertexCapacity, const float *offset=nullptr, const float *scale=nullptr)
 Binds caller-owned vertex streams for mesh draws and sets the uniforms so vertices pass through unchanged: positions are already NDC (3 floats each, z = 0), colors are RGBA8 per vertex and are multiplied by 1.
 
void setAngle (float angleRadians)
 Sets the quad rotation in radians.
 
void setOffset (const float offset[3])
 Sets the NDC position of the quad's center.
 
void setScale (const float scale[3])
 Sets the NDC half-extents of the quad.
 
void setColorIntensity (const float colorIntensity[4])
 Sets the RGBA color the quad is filled with.
 

Static Public Member Functions

static ColorShader * instance ()
 
static void destroyInstance ()
 Destroys the shared instance; the next instance() call creates a new one.
 
static void drawMesh (uint32_t firstVertex, uint32_t vertexCount)
 Draws triangles from the streams bound with bindMesh().
 
- Static Public Member Functions inherited from Shader
static void draw (int32_t primitive=GX2_PRIMITIVE_MODE_QUADS, uint32_t vtxCount=4)
 Issues the draw call for the currently bound shaders and attribute buffers.
 

Static Public Attributes

static const uint32_t cuColorVtxsSize = 4 * cuColorAttrSize
 Size in bytes of the four per-vertex colors of one quad.
 
- Static Public Attributes inherited from Shader
static const uint16_t cuVertexAttrSize = sizeof(float) * 3
 Size in bytes of one position vertex (3 floats)
 
static const uint16_t cuTexCoordAttrSize = sizeof(float) * 2
 Size in bytes of one texture coordinate (2 floats)
 
static const uint16_t cuColorAttrSize = sizeof(uint8_t) * 4
 Size in bytes of one vertex color (4 bytes, RGBA)
 

Detailed Description

Flat-color quad shader (rectangles, keyboard/dialog chrome), used via WutGlyphRenderer's drawFeature().

Singleton, accessed through instance().

Definition at line 19 of file ColorShader.h.

Member Function Documentation

◆ bindMesh()

void ColorShader::bindMesh ( const float * positions,
const uint8_t * colors,
uint32_t vertexCapacity,
const float * offset = nullptr,
const float * scale = nullptr )
inline

Binds caller-owned vertex streams for mesh draws and sets the uniforms so vertices pass through unchanged: positions are already NDC (3 floats each, z = 0), colors are RGBA8 per vertex and are multiplied by 1.

The streams must stay valid and unmodified until the GPU has finished the draws.

Parameters
positionsVertex positions, GX2_VERTEX_BUFFER_ALIGNMENT aligned
colorsVertex colors, GX2_VERTEX_BUFFER_ALIGNMENT aligned
vertexCapacityNumber of vertices both streams hold
offsetNDC offset added to every vertex after scaling (nullptr = none). For a mesh kept across frames, whose positions are NDC for an instance at the canvas origin
scaleNDC scale applied to every vertex (nullptr = 1)

Definition at line 133 of file ColorShader.h.

◆ destroyInstance()

static void ColorShader::destroyInstance ( )
inlinestatic

Destroys the shared instance; the next instance() call creates a new one.

Definition at line 65 of file ColorShader.h.

◆ drawMesh()

static void ColorShader::drawMesh ( uint32_t firstVertex,
uint32_t vertexCount )
inlinestatic

Draws triangles from the streams bound with bindMesh().

Parameters
firstVertexIndex of the first vertex
vertexCountNumber of vertices (a multiple of 3)

Definition at line 149 of file ColorShader.h.

◆ instance()

static ColorShader * ColorShader::instance ( )
inlinestatic
Returns
the shared ColorShader, created on first use

Definition at line 57 of file ColorShader.h.

◆ resetFrame()

void ColorShader::resetFrame ( )
inline

Call once per frame, before any draws - rewinds the per-draw color slot counter so this frame starts writing from slot 0 again.

Safe to call even before the first frame's draws: slots from a completed frame are free to reuse once GX2DrawDone has run (WHBGfxFinishRender does this every frame), so by the time prepareFrame() runs for the next frame, every slot used last frame is guaranteed consumed.

Definition at line 86 of file ColorShader.h.

◆ setAngle()

void ColorShader::setAngle ( float angleRadians)
inline

Sets the quad rotation in radians.

Definition at line 155 of file ColorShader.h.

◆ setAttributeBuffer()

void ColorShader::setAttributeBuffer ( const uint8_t * colorAttr)
inline
Parameters
colorAttrPacked RGBA8 color, 4 vertices (cuColorVtxsSize bytes). Copied into this draw's own slot in a GX2R buffer this shader owns - the caller's memory (a stack array at every current call site) isn't guaranteed to still be valid, unmodified, or cache-flushed by the time the GPU actually executes this draw, and a single shared destination wouldn't survive multiple in-flight draws within the same frame (see cuMaxColorDraws above).

Definition at line 99 of file ColorShader.h.

◆ setColorIntensity()

void ColorShader::setColorIntensity ( const float colorIntensity[4])
inline

Sets the RGBA color the quad is filled with.

Definition at line 170 of file ColorShader.h.

◆ setOffset()

void ColorShader::setOffset ( const float offset[3])
inline

Sets the NDC position of the quad's center.

Definition at line 160 of file ColorShader.h.

◆ setScale()

void ColorShader::setScale ( const float scale[3])
inline

Sets the NDC half-extents of the quad.

Definition at line 165 of file ColorShader.h.

◆ setShaders()

void ColorShader::setShaders ( ) const
inline

Binds the fetch, vertex and pixel shaders for subsequent draws.

Definition at line 72 of file ColorShader.h.

Member Data Documentation

◆ cuColorVtxsSize

const uint32_t ColorShader::cuColorVtxsSize = 4 * cuColorAttrSize
static

Size in bytes of the four per-vertex colors of one quad.

Definition at line 54 of file ColorShader.h.


The documentation for this class was generated from the following files: