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

#include <DrawList.hpp>

Classes

struct  GroupIdentity
 The sorting identity a SortingGroup imposes on one of its members. More...
struct  SortIdentity
 Where a draw sits in the frame's order, once any group has had its say. More...

Public Types

enum class  Phase : u8 {
  All , WithoutSceneColor , SceneColorOnly , OpaqueOnly ,
  BlendedOnly , ScreenColorOnly
}
enum class  DrawPass : u8 { Color , DepthPrepass , ColorAfterPrepass }
enum class  LayerOrder : u8 { Painter , YSort , Depth , Tree }
 How one sorting layer resolves the draws inside it. More...

Public Member Functions

void clear ()
void push (const DrawCommand &cmd)
void finalize (TransientBufferPool &pool)
template<typename Remap>
void remapPrograms (Remap &&remap)
void reserveMask2DSlots (u32 count)
bool sortKeyRange (u64 &lo, u64 &hi) const
void copySettingsFrom (const DrawList &other)
void setGBufferPass (bool on)
void setMask2DTexture (u32 unit, u32 textureId)
void execute (GfxDevice &device, TransientBufferPool &buffers, MaterialStore &materials, u32 white_texture_id=0, FrameCapture *capture=nullptr, const PerDrawBlockSet &blocks={}, Phase phase=Phase::All, DrawPass pass=DrawPass::Color)
void setShaderRunSink (std::function< void(const char *)> sink)
u32 skippedForProgram () const
 How many merged draws the last execute left out because their program was not ready (GfxDevice::setSkipPendingPrograms).
u32 depthPrepassDraws () const
 How many of the merged draws take part in a depth prepass; 0 means a prepass has nothing to draw.
bool anyUsesSceneColor (const MaterialStore &materials) const
 Whether any merged draw reads the picture behind it.
bool anyUsesScreenColor (const MaterialStore &materials) const
void setDeferScreenColor (bool defer)
void setLayerAlpha (bool layer)
void setLayerlessVisible (bool visible)
bool anyNeedsScenePicture (const MaterialStore &materials) const
 Whether a draw is of a material that does not work without a picture of the scene (MaterialStore::needsScenePicture).
bool anyBlendedWithoutSceneColor (const MaterialStore &materials) const
 Whether the list holds a blended draw that does not refract: what has to be ordered against a refracting surface by where it is, not by when it was drawn.
bool anyUsesSceneDepth (const MaterialStore &materials) const
 Whether any merged draw reads the distance to the opaque scene behind it.
u32 addSkinMatrices (const glm::mat4 *matrices, u32 count)
const glm::mat4 * skinMatrices () const
u32 addMorphShapes (const MorphConstants &shapes)
u32 addProbe (const ProbeConstants &probe)
u32 addPlanar (const PlanarConstants &value)
u32 commandCount () const
u32 sourceEntityCount (RenderType type) const
u32 mergedDrawCallCount () const
u32 breakCount (BatchBreak reason) const
u32 mergedAwayCount () const
std::span< const Entity > runEntities (u32 index) const
const DrawCommand * commands () const
u64 contentHash (u64 seed) const
 A hash of what the list draws: each command's program, geometry, state and ranges, and the bone matrices and shapes it carries. Folded into seed.
u64 contentHashOfRecords (u64 seed, TransientBufferPool &pool, bool &trusted) const
 contentHash with the instance records each command reads from pool in place of where they lie in it: two lists that draw the same records hash the same wherever another list's records pushed them. For one list among several filling a pool.
const DrawCommand & command (u32 index) const
void setYSortMask (u32 mask)
u32 ySortMask () const
void setTreeMask (u32 mask)
u32 treeMask () const
std::vector< u32 > & treeSequence ()
u32 treeSequenceOf (Entity entity) const
void setDepthMask (u32 mask)
u32 depthMask () const
bool needsDepth () const
 Whether a frame holding these draws has to be handed a depth buffer.
void setCullingMask (u32 mask)
u32 cullingMask () const
bool layerVisible (u32 layerBit) const
 Whether a draw belonging to layerBit survives this camera's mask. Bit 0 means "no layer" (outside 0..31) and is visible to every camera.
LayerOrder layerOrder (i32 layer) const
 The one answer for layer, from two masks that are two spellings of the same question.
void setSortingGroup (u32 entity, const GroupIdentity &identity)
 Resolved once per collect, by the one walk that knows the hierarchy — the draw path only reads it, exactly as it reads ClipState.
void clearSortingGroups ()
const GroupIdentity * sortingGroupOf (u32 entity) const
 The group entity belongs to, or null when it sorts on its own.
SortIdentity sortIdentity (u32 entity, i32 ownLayer, i32 ownOrder) const
 The one answer to "where does this draw sit". Asked by the draw path when it builds a key, and by anything that must reason about that order BEFORE the keys exist — a second implementation is a second order.

Static Public Member Functions

static u32 layerBit (i32 layer)
 The mask bit of a sorting layer, or 0 when it has none (outside 0..31).

Detailed Description

Definition at line 28 of file DrawList.hpp.

Member Enumeration Documentation

◆ DrawPass

enum class esengine::DrawList::DrawPass : u8
strong

What a run of the list is for. A depth prepass draws the opaque surfaces that have a depth program, into the depth buffer alone; the colour pass that follows (ColorAfterPrepass) draws those same surfaces where their depth is equal to what is there, so a pixel is shaded once, for the surface that is in front of it.

Enumerator
Color 
DepthPrepass 
ColorAfterPrepass 

Definition at line 102 of file DrawList.hpp.

◆ LayerOrder

enum class esengine::DrawList::LayerOrder : u8
strong

How one sorting layer resolves the draws inside it.

Enumerator
Painter 
YSort 
Depth 
Tree 

Definition at line 232 of file DrawList.hpp.

◆ Phase

enum class esengine::DrawList::Phase : u8
strong

Which of the list's draws an execute makes. A draw whose material reads the picture behind it (u_sceneColor) has to be made after a copy of that picture is taken, so the frame executes the list twice: the rest, then those.

Enumerator
All 
WithoutSceneColor 
SceneColorOnly 
OpaqueOnly 
BlendedOnly 
ScreenColorOnly 

Definition at line 98 of file DrawList.hpp.

Member Function Documentation

◆ addMorphShapes()

u32 esengine::DrawList::addMorphShapes ( const MorphConstants & shapes)

Append one draw's shapes; returns 1 + where they sit, so that 0 stays available for "this draw is in the shape it was authored in".

Definition at line 92 of file DrawList.cpp.

◆ addPlanar()

u32 esengine::DrawList::addPlanar ( const PlanarConstants & value)
inline

Definition at line 143 of file DrawList.hpp.

◆ addProbe()

u32 esengine::DrawList::addProbe ( const ProbeConstants & probe)

Append one draw's indirect light; returns 1 + where it sits, so that 0 stays available for "no volume holds this draw".

Definition at line 97 of file DrawList.cpp.

◆ addSkinMatrices()

u32 esengine::DrawList::addSkinMatrices ( const glm::mat4 * matrices,
u32 count )

Append one draw's bone matrices; returns where they start. Frame-scoped, like the vertex pool: a command references an offset, not a copy.

Definition at line 86 of file DrawList.cpp.

◆ anyBlendedWithoutSceneColor()

bool esengine::DrawList::anyBlendedWithoutSceneColor ( const MaterialStore & materials) const

Whether the list holds a blended draw that does not refract: what has to be ordered against a refracting surface by where it is, not by when it was drawn.

Definition at line 531 of file DrawList.cpp.

References esengine::isBlendedStage(), and esengine::MaterialStore::usesSceneColor().

◆ anyNeedsScenePicture()

bool esengine::DrawList::anyNeedsScenePicture ( const MaterialStore & materials) const

Whether a draw is of a material that does not work without a picture of the scene (MaterialStore::needsScenePicture).

Definition at line 504 of file DrawList.cpp.

References esengine::MaterialStore::needsScenePicture().

◆ anyUsesSceneColor()

bool esengine::DrawList::anyUsesSceneColor ( const MaterialStore & materials) const

Whether any merged draw reads the picture behind it.

Definition at line 511 of file DrawList.cpp.

References esengine::MaterialStore::usesSceneColor().

◆ anyUsesSceneDepth()

bool esengine::DrawList::anyUsesSceneDepth ( const MaterialStore & materials) const

Whether any merged draw reads the distance to the opaque scene behind it.

Definition at line 552 of file DrawList.cpp.

References esengine::MaterialStore::usesSceneDepth().

◆ anyUsesScreenColor()

bool esengine::DrawList::anyUsesScreenColor ( const MaterialStore & materials) const

Definition at line 518 of file DrawList.cpp.

References esengine::MaterialStore::usesScreenColor().

◆ breakCount()

u32 esengine::DrawList::breakCount ( BatchBreak reason) const
inline

How many of the last finalize's draws started for reason.

Definition at line 153 of file DrawList.hpp.

◆ clear()

void esengine::DrawList::clear ( )

Definition at line 70 of file DrawList.cpp.

◆ clearSortingGroups()

void esengine::DrawList::clearSortingGroups ( )
inline

Definition at line 272 of file DrawList.hpp.

◆ command()

const DrawCommand & esengine::DrawList::command ( u32 index) const
inline

Definition at line 179 of file DrawList.hpp.

Referenced by finalize(), remapPrograms(), and sortKeyRange().

◆ commandCount()

u32 esengine::DrawList::commandCount ( ) const
inline

Definition at line 145 of file DrawList.hpp.

◆ commands()

const DrawCommand * esengine::DrawList::commands ( ) const
inline

Definition at line 160 of file DrawList.hpp.

◆ contentHash()

u64 esengine::DrawList::contentHash ( u64 seed) const

A hash of what the list draws: each command's program, geometry, state and ranges, and the bone matrices and shapes it carries. Folded into seed.

Not the bytes of the instance records, which live in the pool (hash those beside it), and not what a material or a texture holds. Two lists with the same hash over the same pool draw the same pixels; read after finalize().

Definition at line 824 of file DrawList.cpp.

References esengine::hash::combine(), esengine::hash::combineWords(), and esengine::MAX_CMD_TEXTURE_SLOTS.

◆ contentHashOfRecords()

u64 esengine::DrawList::contentHashOfRecords ( u64 seed,
TransientBufferPool & pool,
bool & trusted ) const

contentHash with the instance records each command reads from pool in place of where they lie in it: two lists that draw the same records hash the same wherever another list's records pushed them. For one list among several filling a pool.

Parameters
trustedCleared when a command reads what this cannot hash: records a compute pass wrote, or vertices with no stride to measure them by.

Definition at line 785 of file DrawList.cpp.

References esengine::hash::combine(), esengine::hash::combineWords(), esengine::Invalid, esengine::MAX_CMD_TEXTURE_SLOTS, esengine::TransientBufferPool::vertexBytesUsed(), and esengine::TransientBufferPool::vertexData().

◆ copySettingsFrom()

void esengine::DrawList::copySettingsFrom ( const DrawList & other)
inline

What the frame has set on other for how it sorts and draws - the sort masks, the 2D masks and their slots, the second output, the screen colour and layer modes, the shader-run sink - set here too: a second list the frame draws with.

Definition at line 63 of file DrawList.hpp.

◆ cullingMask()

u32 esengine::DrawList::cullingMask ( ) const
inline

Definition at line 218 of file DrawList.hpp.

◆ depthMask()

u32 esengine::DrawList::depthMask ( ) const
inline

Definition at line 203 of file DrawList.hpp.

◆ depthPrepassDraws()

u32 esengine::DrawList::depthPrepassDraws ( ) const

How many of the merged draws take part in a depth prepass; 0 means a prepass has nothing to draw.

Definition at line 544 of file DrawList.cpp.

References esengine::takesPartInPrepass().

◆ execute()

void esengine::DrawList::execute ( GfxDevice & device,
TransientBufferPool & buffers,
MaterialStore & materials,
u32 white_texture_id = 0,
FrameCapture * capture = nullptr,
const PerDrawBlockSet & blocks = {},
Phase phase = Phase::All,
DrawPass pass = DrawPass::Color )

Definition at line 559 of file DrawList.cpp.

References esengine::PipelineDesc::albedo, All, esengine::MaterialStore::alphaIsCoverage(), esengine::PipelineDesc::alphaToCoverage, esengine::PerDrawBlocks::bind(), esengine::MaterialStore::bindForDraw(), esengine::TransientBufferPool::bindInstanceBuffer(), esengine::TransientBufferPool::bindInstanceLayout(), esengine::TransientBufferPool::bindLayout(), esengine::GfxDevice::bindTexture(), esengine::PipelineDesc::blend, BlendedOnly, esengine::PipelineDesc::blendEnabled, esengine::GfxDevice::boundSamplerUnits(), esengine::CMD_STATE_SCISSOR, ColorAfterPrepass, esengine::PipelineDesc::colorWrite, esengine::FrameProfiler::counter(), esengine::GfxDevice::createPipeline(), esengine::PipelineDesc::cullEnabled, esengine::PipelineDesc::cullFront, esengine::PipelineDesc::depthBias, esengine::PipelineDesc::depthEqual, DepthPrepass, esengine::PipelineDesc::depthTest, esengine::PipelineDesc::depthWrite, esengine::GfxDevice::drawElements(), esengine::GfxDevice::drawElementsInstanced(), esengine::GfxDevice::drawElementsInstancedMulti(), esengine::PipelineDesc::gbuffer, esengine::FrameProfiler::get(), esengine::DrawCommand::index_count, esengine::DrawCommand::index_offset, esengine::PerDrawBlockSet::instance, esengine::INSTANCE_CONSTANTS_BINDING, esengine::DrawCommand::instance_count, esengine::TransientBufferPool::instanceTexture(), esengine::Invalid, esengine::isBlendedStage(), esengine::FrameCapture::isCapturing(), esengine::FrameCapture::isReplaying(), esengine::PipelineDesc::layerAlpha, esengine::TransientBufferPool::layoutHandle(), esengine::MAX_CMD_TEXTURE_SLOTS, esengine::MESH_INSTANCE_TEXTURE_UNIT, esengine::None, esengine::Off, OpaqueOnly, esengine::PerDrawBlockSet::planar, esengine::PLANAR_CONSTANTS_BINDING, esengine::PerDrawBlockSet::probe, esengine::PROBE_CONSTANTS_BINDING, esengine::PipelineDesc::program, esengine::GfxDevice::programReady(), esengine::MaterialStore::programWritesAlbedo(), esengine::MaterialStore::programWritesGBuffer(), esengine::FrameCapture::record(), runEntities(), SceneColorOnly, ScreenColorOnly, esengine::GfxDevice::setIndexBuffer(), esengine::GfxDevice::setPipeline(), esengine::GfxDevice::setScissor(), esengine::GfxDevice::setScissorTest(), esengine::GfxDevice::setStencilReference(), esengine::GfxDevice::setVertexBuffer(), esengine::MaterialStore::shaderLabel(), esengine::PerDrawBlockSet::skin, esengine::SKIN_CONSTANTS_BINDING, esengine::GfxDevice::skipPendingPrograms(), esengine::PipelineDesc::stencil, esengine::stencilModeOf(), esengine::FrameCapture::stepReplay(), esengine::GfxDevice::supportsMultiDraw(), esengine::GfxDevice::supportsUnblendedSurfaceTarget(), esengine::takesPartInPrepass(), esengine::PipelineDesc::topology, esengine::UnsignedInt, esengine::MaterialStore::usesSceneColor(), esengine::MaterialStore::usesScreenColor(), esengine::PipelineDesc::vertexLayout, and WithoutSceneColor.

◆ finalize()

◆ layerBit()

u32 esengine::DrawList::layerBit ( i32 layer)
inlinestatic

The mask bit of a sorting layer, or 0 when it has none (outside 0..31).

Definition at line 227 of file DrawList.hpp.

Referenced by esengine::batchEntityVisible(), layerVisible(), esengine::pushBatchDraw(), and esengine::RenderFrame::visibleToCamera().

◆ layerOrder()

LayerOrder esengine::DrawList::layerOrder ( i32 layer) const
inline

The one answer for layer, from two masks that are two spellings of the same question.

Y-sort is a depth PROJECTED from world Y and depth is the real thing; a layer declaring both has said two contradictory things, and there is no order that satisfies them. Y-sort wins so that a project which had it before renders exactly as it did — the resolution belongs here, in one pure function, rather than in each caller's idea of precedence. Layers outside 0..31 have no bit and are therefore painter-ordered.

Definition at line 245 of file DrawList.hpp.

References Depth, Painter, Tree, and YSort.

Referenced by esengine::pushBatchDraw().

◆ layerVisible()

bool esengine::DrawList::layerVisible ( u32 layerBit) const
inline

Whether a draw belonging to layerBit survives this camera's mask. Bit 0 means "no layer" (outside 0..31) and is visible to every camera.

Definition at line 222 of file DrawList.hpp.

References layerBit().

Referenced by esengine::batchEntityVisible(), and esengine::pushBatchDraw().

◆ mergedAwayCount()

u32 esengine::DrawList::mergedAwayCount ( ) const
inline

How many submitted commands the last finalize folded into another.

Definition at line 155 of file DrawList.hpp.

◆ mergedDrawCallCount()

u32 esengine::DrawList::mergedDrawCallCount ( ) const
inline

Definition at line 151 of file DrawList.hpp.

◆ needsDepth()

bool esengine::DrawList::needsDepth ( ) const
inline

Whether a frame holding these draws has to be handed a depth buffer.

Two things resolve by depth and they are ONE question: a layer the project declared depth-resolved, and a draw that declared it for ITSELF (an opaque mesh). A depth test with no attachment behind it PASSES, and opaque sorts front-to-back — the furthest paints last.

Definition at line 213 of file DrawList.hpp.

◆ push()

◆ remapPrograms()

template<typename Remap>
void esengine::DrawList::remapPrograms ( Remap && remap)
inline

Definition at line 39 of file DrawList.hpp.

References command().

◆ reserveMask2DSlots()

void esengine::DrawList::reserveMask2DSlots ( u32 count)
inline

How many of the frame's TOP texture units are screen-space light masks: one for the shadow mask, two when a light also carries a shape. Set BEFORE finalize (the merge spends slots) and reserved top-down, so a sampler's unit never moves.

Definition at line 46 of file DrawList.hpp.

References esengine::MAX_CMD_TEXTURE_SLOTS.

◆ runEntities()

std::span< const Entity > esengine::DrawList::runEntities ( u32 index) const

The entities merged draw index was made from, in draw order.

Definition at line 307 of file DrawList.cpp.

Referenced by execute().

◆ setCullingMask()

void esengine::DrawList::setCullingMask ( u32 mask)
inline

Definition at line 217 of file DrawList.hpp.

◆ setDeferScreenColor()

void esengine::DrawList::setDeferScreenColor ( bool defer)
inline

Definition at line 121 of file DrawList.hpp.

◆ setDepthMask()

void esengine::DrawList::setDepthMask ( u32 mask)
inline

Definition at line 202 of file DrawList.hpp.

◆ setGBufferPass()

void esengine::DrawList::setGBufferPass ( bool on)
inline

The pass this list is about to execute into carries a second colour attachment, so the draws whose shaders write it say so in their pipelines. Set for the scene pass and cleared after: the same list is executed into other targets, which have no second output to take.

Definition at line 80 of file DrawList.hpp.

◆ setLayerAlpha()

void esengine::DrawList::setLayerAlpha ( bool layer)
inline

Definition at line 122 of file DrawList.hpp.

◆ setLayerlessVisible()

void esengine::DrawList::setLayerlessVisible ( bool visible)
inline

Definition at line 123 of file DrawList.hpp.

◆ setMask2DTexture()

void esengine::DrawList::setMask2DTexture ( u32 unit,
u32 textureId )
inline

A mask itself, which every draw then binds on its unit. Zero leaves the unit filled with white — "nothing shadows anything", and "the shape covers all".

Definition at line 84 of file DrawList.hpp.

References esengine::MAX_CMD_TEXTURE_SLOTS.

◆ setShaderRunSink()

void esengine::DrawList::setShaderRunSink ( std::function< void(const char *)> sink)
inline

Told, while a list executes, which shader the draws that follow use (and with nullptr that they are over): what lets a profiler time the scene a shader at a time. Empty costs nothing; a sink is installed only while someone is measuring.

Definition at line 110 of file DrawList.hpp.

References esengine::sink().

◆ setSortingGroup()

void esengine::DrawList::setSortingGroup ( u32 entity,
const GroupIdentity & identity )
inline

Resolved once per collect, by the one walk that knows the hierarchy — the draw path only reads it, exactly as it reads ClipState.

Definition at line 269 of file DrawList.hpp.

◆ setTreeMask()

void esengine::DrawList::setTreeMask ( u32 mask)
inline

Definition at line 191 of file DrawList.hpp.

◆ setYSortMask()

void esengine::DrawList::setYSortMask ( u32 mask)
inline

Definition at line 184 of file DrawList.hpp.

◆ skinMatrices()

const glm::mat4 * esengine::DrawList::skinMatrices ( ) const
inline

Definition at line 134 of file DrawList.hpp.

◆ skippedForProgram()

u32 esengine::DrawList::skippedForProgram ( ) const
inline

How many merged draws the last execute left out because their program was not ready (GfxDevice::setSkipPendingPrograms).

Definition at line 113 of file DrawList.hpp.

◆ sortIdentity()

SortIdentity esengine::DrawList::sortIdentity ( u32 entity,
i32 ownLayer,
i32 ownOrder ) const
inline

The one answer to "where does this draw sit". Asked by the draw path when it builds a key, and by anything that must reason about that order BEFORE the keys exist — a second implementation is a second order.

Definition at line 294 of file DrawList.hpp.

References sortingGroupOf().

Referenced by esengine::batchEntityVisible(), and esengine::pushBatchDraw().

◆ sortingGroupOf()

const GroupIdentity * esengine::DrawList::sortingGroupOf ( u32 entity) const
inline

The group entity belongs to, or null when it sorts on its own.

Definition at line 275 of file DrawList.hpp.

Referenced by esengine::pushBatchDraw(), and sortIdentity().

◆ sortKeyRange()

bool esengine::DrawList::sortKeyRange ( u64 & lo,
u64 & hi ) const
inline

The lowest and highest sort key of the commands it holds; false when it holds none. Two lists drawn one after the other draw as one list would only while the first's highest is below the second's lowest.

Definition at line 50 of file DrawList.hpp.

References command().

◆ sourceEntityCount()

u32 esengine::DrawList::sourceEntityCount ( RenderType type) const
inline

Entities by original submission type, independent of a merged run's head.

Definition at line 147 of file DrawList.hpp.

◆ treeMask()

u32 esengine::DrawList::treeMask ( ) const
inline

Definition at line 192 of file DrawList.hpp.

◆ treeSequence()

std::vector< u32 > & esengine::DrawList::treeSequence ( )
inline

Definition at line 193 of file DrawList.hpp.

◆ treeSequenceOf()

u32 esengine::DrawList::treeSequenceOf ( Entity entity) const
inline

Definition at line 194 of file DrawList.hpp.

References esengine::Entity::index().

Referenced by esengine::pushBatchDraw().

◆ ySortMask()

u32 esengine::DrawList::ySortMask ( ) const
inline

Definition at line 185 of file DrawList.hpp.


The documentation for this class was generated from the following files:
  • /home/runner/work/estella/estella/src/esengine/renderer/draw/DrawList.hpp
  • /home/runner/work/estella/estella/src/esengine/renderer/draw/DrawList.cpp