Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
esengine::RenderContext Class Reference

#include <RenderContext.hpp>

Public Member Functions

 RenderContext (GfxDevice &device)
 RenderContext ()=delete
 ~RenderContext ()
 RenderContext (const RenderContext &)=delete
RenderContext & operator= (const RenderContext &)=delete
void init ()
 Initializes rendering resources.
void shutdown ()
 Releases all rendering resources.
void restoreBuiltinContent ()
 Builds again what this context made from code alone and the device lost: call once the device is back.
bool isInitialized () const
 Checks if the context is initialized.
u64 programEpoch () const
 Which generation of renderer PROGRAM readiness is current.
void advanceProgramEpoch ()
 Declares that programs which WERE ready have gone cold.
glm::mat4 & viewProjection ()
 Gets the current view-projection matrix.
const glm::mat4 & viewProjection () const
 Gets the current view-projection matrix (const).
u32 getWhiteTextureId () const
 Gets the white texture handle's raw value (for untextured quads).
TextureHandle getWhiteTexture () const
void updateCameraConstants (const glm::mat4 &viewProjection)
 Point the frame at what a CAMERA sees.
void updateCameraConstants (const glm::mat4 &viewProjection, const glm::vec2 &jitterNdc)
 The same, with the picture shifted by jitterNdc (a fraction of the clip square) — what temporal anti-aliasing samples a different sub-pixel position with each frame.
void updateFrameConstants (const glm::mat4 &viewProjection)
 Point the frame at a pass whose projection already suits the device.
void useFrameConstants (BufferHandle ubo, const glm::mat4 &viewProjection)
 Frame constants for viewProjection in a buffer the CALLER owns, bound.
void prepareFrameConstants (BufferHandle ubo, const glm::mat4 &viewProjection)
 Stage a light view before the render passes and switch to it without a mid-pass upload.
void bindFrameConstants (BufferHandle ubo)
BufferHandle frameUbo () const
 The buffer the camera's FrameConstants live in, for a compute pass that reads them (it is bound at group 0).
void setFrameTime (f32 elapsedSec, u32 viewportW, u32 viewportH)
 Uploads the frame clock + canvas size into the injected TimeConstants UBO.
void setViewExposure (f32 ev)
 The editor view's exposure, in stops, carried to the output blit in u_time.z. VIEW state: zero (the default, and every packaged build) is exp2(0) = 1, an exact no-op.
void setQualityConstants (const glm::vec4 &values)
f32 viewExposure () const
QualityValues & qualityValues ()
const QualityValues & qualityValues () const
MaterialStore & materials ()
 The engine-side material registry (handle -> resolved render state).
const MaterialStore & materials () const
LightStore & lights ()
 The engine-side per-frame 2D light registry (binding 2 LightConstants UBO).
const LightStore & lights () const
ProbeStore & probes ()
 The frame's probe volumes. Gathered beside the lights, because it answers the same question at the points a light cannot be asked.
const ProbeStore & probes () const
ReflectionStore & reflections ()
 The frame's reflection probes — the same question about the half of the environment a surface MIRRORS rather than scatters.
const ReflectionStore & reflections () const
PerDrawBlockSet perDrawBlocks ()
 The blocks the draw loop rewrites before each draw.
void beginPerDrawBlocks ()
 Hand every one of them back at the top of a frame.

Static Public Member Functions

static u32 frameConstantsSize ()
 Bytes a buffer passed to useFrameConstants must hold.

Detailed Description

Definition at line 63 of file RenderContext.hpp.

Constructor & Destructor Documentation

◆ RenderContext() [1/3]

esengine::RenderContext::RenderContext ( GfxDevice & device)
explicit

Definition at line 33 of file RenderContext.cpp.

Referenced by RenderContext(), and operator=().

◆ RenderContext() [2/3]

esengine::RenderContext::RenderContext ( )
delete

◆ ~RenderContext()

esengine::RenderContext::~RenderContext ( )

Definition at line 37 of file RenderContext.cpp.

References shutdown().

◆ RenderContext() [3/3]

esengine::RenderContext::RenderContext ( const RenderContext & )
delete

References RenderContext().

Member Function Documentation

◆ advanceProgramEpoch()

void esengine::RenderContext::advanceProgramEpoch ( )
inline

Declares that programs which WERE ready have gone cold.

Renderer-wide, not stock-only: ANY operation that can make a previously-ready program requirement cold owes this call — a cache emptied after a device rebuild, a pipeline flush, a shader hot reload. Skipping it leaves a stamp vouching for nothing.

Definition at line 120 of file RenderContext.hpp.

◆ beginPerDrawBlocks()

void esengine::RenderContext::beginPerDrawBlocks ( )
inline

Hand every one of them back at the top of a frame.

Definition at line 273 of file RenderContext.hpp.

◆ bindFrameConstants()

void esengine::RenderContext::bindFrameConstants ( BufferHandle ubo)

◆ frameConstantsSize()

u32 esengine::RenderContext::frameConstantsSize ( )
static

Bytes a buffer passed to useFrameConstants must hold.

Definition at line 225 of file RenderContext.cpp.

◆ frameUbo()

BufferHandle esengine::RenderContext::frameUbo ( ) const
inline

The buffer the camera's FrameConstants live in, for a compute pass that reads them (it is bound at group 0).

Definition at line 189 of file RenderContext.hpp.

◆ getWhiteTexture()

TextureHandle esengine::RenderContext::getWhiteTexture ( ) const
inline

The white 1x1 as a typed handle — what a lost texture is parked on until its content is re-uploaded.

Definition at line 149 of file RenderContext.hpp.

◆ getWhiteTextureId()

u32 esengine::RenderContext::getWhiteTextureId ( ) const
inline

Gets the white texture handle's raw value (for untextured quads).

Definition at line 145 of file RenderContext.hpp.

◆ init()

void esengine::RenderContext::init ( )

Initializes rendering resources.

Creates the quad VAO, shaders, and default textures.

Definition at line 43 of file RenderContext.cpp.

References ES_LOG_WARN.

◆ isInitialized()

bool esengine::RenderContext::isInitialized ( ) const
inline

Checks if the context is initialized.

Returns
True if init() has been called successfully

Definition at line 97 of file RenderContext.hpp.

◆ lights() [1/2]

LightStore & esengine::RenderContext::lights ( )
inline

The engine-side per-frame 2D light registry (binding 2 LightConstants UBO).

Filled by the render collect path from the scene's Light components and uploaded once per frame; Lit material shaders read it. Lives here next to materials() so the render path reaches one store / one UBO without a global lookup.

Definition at line 224 of file RenderContext.hpp.

◆ lights() [2/2]

const LightStore & esengine::RenderContext::lights ( ) const
inline

Definition at line 225 of file RenderContext.hpp.

◆ materials() [1/2]

MaterialStore & esengine::RenderContext::materials ( )
inline

The engine-side material registry (handle -> resolved render state).

Written by the SDK material binding (defineMaterial) and read by the render collect path to resolve a component's material handle into shader + pipeline state. Lives here so both sides reach it without a global lookup.

Definition at line 215 of file RenderContext.hpp.

◆ materials() [2/2]

const MaterialStore & esengine::RenderContext::materials ( ) const
inline

Definition at line 216 of file RenderContext.hpp.

◆ operator=()

RenderContext & esengine::RenderContext::operator= ( const RenderContext & )
delete

References RenderContext().

◆ perDrawBlocks()

PerDrawBlockSet esengine::RenderContext::perDrawBlocks ( )
inline

The blocks the draw loop rewrites before each draw.

Definition at line 269 of file RenderContext.hpp.

◆ prepareFrameConstants()

void esengine::RenderContext::prepareFrameConstants ( BufferHandle ubo,
const glm::mat4 & viewProjection )

Stage a light view before the render passes and switch to it without a mid-pass upload.

Definition at line 229 of file RenderContext.cpp.

References esengine::cameraFromViewProjection(), esengine::Invalid, esengine::renderOrigin(), and viewProjection().

Referenced by useFrameConstants().

◆ probes() [1/2]

ProbeStore & esengine::RenderContext::probes ( )
inline

The frame's probe volumes. Gathered beside the lights, because it answers the same question at the points a light cannot be asked.

Definition at line 229 of file RenderContext.hpp.

◆ probes() [2/2]

const ProbeStore & esengine::RenderContext::probes ( ) const
inline

Definition at line 230 of file RenderContext.hpp.

◆ programEpoch()

u64 esengine::RenderContext::programEpoch ( ) const
inline

Which generation of renderer PROGRAM readiness is current.

A record stamped with an older epoch names programs that may no longer exist, so it is re-derived rather than trusted. Distinct from the device generation, which says which device the GPU work happened on rather than whether readiness survived.

Definition at line 110 of file RenderContext.hpp.

◆ qualityValues() [1/2]

QualityValues & esengine::RenderContext::qualityValues ( )
inline

Definition at line 206 of file RenderContext.hpp.

◆ qualityValues() [2/2]

const QualityValues & esengine::RenderContext::qualityValues ( ) const
inline

Definition at line 207 of file RenderContext.hpp.

◆ reflections() [1/2]

ReflectionStore & esengine::RenderContext::reflections ( )
inline

The frame's reflection probes — the same question about the half of the environment a surface MIRRORS rather than scatters.

Definition at line 234 of file RenderContext.hpp.

◆ reflections() [2/2]

const ReflectionStore & esengine::RenderContext::reflections ( ) const
inline

Definition at line 235 of file RenderContext.hpp.

◆ restoreBuiltinContent()

void esengine::RenderContext::restoreBuiltinContent ( )

Builds again what this context made from code alone and the device lost: call once the device is back.

Definition at line 130 of file RenderContext.cpp.

References esengine::buildRippleNormals(), esengine::Invalid, esengine::RIPPLE_NORMALS_SIZE, and esengine::GfxOwedContent::Texture.

◆ setFrameTime()

void esengine::RenderContext::setFrameTime ( f32 elapsedSec,
u32 viewportW,
u32 viewportH )

Uploads the frame clock + canvas size into the injected TimeConstants UBO.

Definition at line 269 of file RenderContext.cpp.

◆ setQualityConstants()

void esengine::RenderContext::setQualityConstants ( const glm::vec4 & values)
inline

Definition at line 203 of file RenderContext.hpp.

◆ setViewExposure()

void esengine::RenderContext::setViewExposure ( f32 ev)
inline

The editor view's exposure, in stops, carried to the output blit in u_time.z. VIEW state: zero (the default, and every packaged build) is exp2(0) = 1, an exact no-op.

Definition at line 202 of file RenderContext.hpp.

◆ shutdown()

void esengine::RenderContext::shutdown ( )

Releases all rendering resources.

Definition at line 60 of file RenderContext.cpp.

References ES_LOG_INFO, and esengine::Invalid.

Referenced by ~RenderContext().

◆ updateCameraConstants() [1/2]

void esengine::RenderContext::updateCameraConstants ( const glm::mat4 & viewProjection)

Point the frame at what a CAMERA sees.

Keeps the projection in the engine's convention and uploads it in the device's. This is the one place that conversion happens.

Definition at line 205 of file RenderContext.cpp.

References esengine::toClipDepthRange(), and viewProjection().

◆ updateCameraConstants() [2/2]

void esengine::RenderContext::updateCameraConstants ( const glm::mat4 & viewProjection,
const glm::vec2 & jitterNdc )

The same, with the picture shifted by jitterNdc (a fraction of the clip square) — what temporal anti-aliasing samples a different sub-pixel position with each frame.

Only the UPLOADED matrix moves. The engine's own copy, which culling and the camera position are read from, is the unshifted one.

Definition at line 210 of file RenderContext.cpp.

References esengine::toClipDepthRange(), and viewProjection().

◆ updateFrameConstants()

void esengine::RenderContext::updateFrameConstants ( const glm::mat4 & viewProjection)

Point the frame at a pass whose projection already suits the device.

The shadow cascades: theirs spans exactly the occluders it draws, so it lands inside either clip volume untouched, and converting it would move the depths it writes away from the copy of the matrix the receiving shader compares against.

Definition at line 221 of file RenderContext.cpp.

References viewProjection().

◆ useFrameConstants()

void esengine::RenderContext::useFrameConstants ( BufferHandle ubo,
const glm::mat4 & viewProjection )

Frame constants for viewProjection in a buffer the CALLER owns, bound.

For a pass that draws several views. A buffer write is a queue operation and does not land between draws already recorded into an open pass, so views sharing one UBO all read the last write. One buffer each makes the BINDING, an encoder command, what varies.

Definition at line 236 of file RenderContext.cpp.

References bindFrameConstants(), esengine::Invalid, prepareFrameConstants(), and viewProjection().

◆ viewExposure()

f32 esengine::RenderContext::viewExposure ( ) const
inline

Definition at line 204 of file RenderContext.hpp.

◆ viewProjection() [1/2]

glm::mat4 & esengine::RenderContext::viewProjection ( )
inline

Gets the current view-projection matrix.

Returns
Reference to the matrix

Definition at line 130 of file RenderContext.hpp.

Referenced by prepareFrameConstants(), updateCameraConstants(), updateCameraConstants(), updateFrameConstants(), and useFrameConstants().

◆ viewProjection() [2/2]

const glm::mat4 & esengine::RenderContext::viewProjection ( ) const
inline

Gets the current view-projection matrix (const).

Returns
Const reference to the matrix

Definition at line 136 of file RenderContext.hpp.


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