group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
HudContext Class Reference

Accumulates HUD geometry during a frame for batch rendering. More...

#include <HudContext.hpp>

Collaboration diagram for HudContext:
[legend]

Public Member Functions

void init (const SdfAtlas *atlas)
 Bind the SDF atlas for text layout (glyph metrics).
void beginFrame ()
 Clear all geometry for a new frame.
void rect (float x, float y, float w, float h, HudColor color)
void rectOutline (float x, float y, float w, float h, float thickness, HudColor color)
void roundedRect (float x, float y, float w, float h, float radius, HudColor color)
void rotatedRect (float cx, float cy, float w, float h, float angleDeg, HudColor color)
void bar (float x, float y, float w, float h, float fill01, HudColor fg, HudColor bg)
void text (const char *str, float x, float y, float size, HudColor color, HudAlign align=HudAlign::Left)
float measureText (const char *str, float size) const
void icon (HudIcon id, float x, float y, float size, HudColor tint=HudColor::white())
void crosshair (const CrosshairStyle &style, float screenW, float screenH)
void vignette (float screenW, float screenH, HudColor color)
 Draw a full-screen radial vignette overlay.
void pushClipRect (float x, float y, float w, float h)
void popClipRect ()
void endFrame ()
 Flush any remaining unflushed vertices into a final clip span.
const std::vector< HudVertex > & vertices () const
const std::vector< std::array< float, 6 > > & clipSpans () const
 Clip rect spans: {startVertex, vertexCount, x, y, w, h}.

Private Member Functions

void emitQuad (float x, float y, float w, float h, float u0, float v0, float u1, float v1, HudColor color, float texMode, float sd0=0.f, float sd1=0.f, float sd2=0.f)
 Emit 6 vertices for a textured quad.
void flushClipSpan ()
 Flush the current clip span before changing scissor state.

Private Attributes

const SdfAtlassdfAtlas_ = nullptr
std::vector< HudVertexvertices_
std::vector< std::array< float, 6 > > clipSpans_
std::vector< std::array< float, 4 > > clipStack_
uint32_t spanStartVertex_ = 0
 Vertex index where current clip span started.
bool spanDirty_ = false

Detailed Description

Accumulates HUD geometry during a frame for batch rendering.

Widgets call rect(), text(), bar(), etc. to emit quads. At the end of the frame, HudRenderer consumes the vertex buffer and clip rect list.

Member Function Documentation

◆ bar()

void HudContext::bar ( float x,
float y,
float w,
float h,
float fill01,
HudColor fg,
HudColor bg )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ beginFrame()

void HudContext::beginFrame ( )

Clear all geometry for a new frame.

◆ clipSpans()

const std::vector< std::array< float, 6 > > & HudContext::clipSpans ( ) const
inlinenodiscard

Clip rect spans: {startVertex, vertexCount, x, y, w, h}.

Negative w means "full viewport" (no scissor).

◆ crosshair()

void HudContext::crosshair ( const CrosshairStyle & style,
float screenW,
float screenH )
Here is the call graph for this function:

◆ emitQuad()

void HudContext::emitQuad ( float x,
float y,
float w,
float h,
float u0,
float v0,
float u1,
float v1,
HudColor color,
float texMode,
float sd0 = 0.f,
float sd1 = 0.f,
float sd2 = 0.f )
private

Emit 6 vertices for a textured quad.

Here is the caller graph for this function:

◆ endFrame()

void HudContext::endFrame ( )

Flush any remaining unflushed vertices into a final clip span.

Must be called after all draw() calls, before accessing vertices/clipSpans.

Here is the call graph for this function:

◆ flushClipSpan()

void HudContext::flushClipSpan ( )
private

Flush the current clip span before changing scissor state.

Here is the caller graph for this function:

◆ icon()

void HudContext::icon ( HudIcon id,
float x,
float y,
float size,
HudColor tint = HudColor::white() )
Here is the call graph for this function:

◆ init()

void HudContext::init ( const SdfAtlas * atlas)

Bind the SDF atlas for text layout (glyph metrics).

◆ measureText()

float HudContext::measureText ( const char * str,
float size ) const
Here is the caller graph for this function:

◆ popClipRect()

void HudContext::popClipRect ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pushClipRect()

void HudContext::pushClipRect ( float x,
float y,
float w,
float h )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rect()

void HudContext::rect ( float x,
float y,
float w,
float h,
HudColor color )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rectOutline()

void HudContext::rectOutline ( float x,
float y,
float w,
float h,
float thickness,
HudColor color )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rotatedRect()

void HudContext::rotatedRect ( float cx,
float cy,
float w,
float h,
float angleDeg,
HudColor color )
Here is the caller graph for this function:

◆ roundedRect()

void HudContext::roundedRect ( float x,
float y,
float w,
float h,
float radius,
HudColor color )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ text()

void HudContext::text ( const char * str,
float x,
float y,
float size,
HudColor color,
HudAlign align = HudAlign::Left )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vertices()

const std::vector< HudVertex > & HudContext::vertices ( ) const
inlinenodiscard

◆ vignette()

void HudContext::vignette ( float screenW,
float screenH,
HudColor color )

Draw a full-screen radial vignette overlay.

Parameters
screenWViewport width in pixels.
screenHViewport height in pixels.
colorTint color with alpha controlling intensity.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ clipSpans_

std::vector<std::array<float, 6> > HudContext::clipSpans_
private

◆ clipStack_

std::vector<std::array<float, 4> > HudContext::clipStack_
private

◆ sdfAtlas_

const SdfAtlas* HudContext::sdfAtlas_ = nullptr
private

◆ spanDirty_

bool HudContext::spanDirty_ = false
private

◆ spanStartVertex_

uint32_t HudContext::spanStartVertex_ = 0
private

Vertex index where current clip span started.

◆ vertices_

std::vector<HudVertex> HudContext::vertices_
private

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