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

#include <DrawCommand.hpp>

Public Member Functions

bool hasPersistentGeometry () const
u8 textureSlotBudget (u8 reservedSlots) const
 Finds texId in this command's texture set, adds it (returns its slot), or -1 if the set is full. Used by the merge to assign per-vertex sampler slots. limit is how many slots the merge may spend: a frame with a 2D shadow mask keeps the top one for it, and a merge that took it would bind a sprite where every Lit fragment reads its shadow.
i32 addTextureSlot (u32 texId, u8 limit=MAX_CMD_TEXTURE_SLOTS)
bool orderIndependent () const
bool sameInstancedGeometry (const DrawCommand &next) const
BatchBreak mergeBlocker (const DrawCommand &next) const
bool canMergeWith (const DrawCommand &next) const

Static Public Member Functions

static u64 buildSortKey (RenderStage stage, i32 layer, u32 shaderId, BlendMode blend, u16 stateFlags, f32 depth, u32 materialId=0, i32 order=0, u32 geometry=0)
static u64 blendBits (BlendMode blend)
 The blend field, 3 bits wide wherever it appears.
static u64 orderBits (i32 order)
 The order field at [47:40], biased so a negative order sorts below zero.
static u64 withGroupOrder (u64 key, i32 memberOrder)
 Re-stamps a member's own order into a key whose top fields a SortingGroup has taken over.
static u32 orderedFloatBits (f32 v)
static u64 buildSortKeyYSorted (RenderStage stage, i32 layer, f32 worldY, u32 shaderId, BlendMode blend, u16 stateFlags, i32 order=0)
static u64 buildSortKeyTree (RenderStage stage, i32 layer, u32 sequence, u32 shaderId, BlendMode blend, u16 stateFlags, i32 order=0)

Public Attributes

u64 sort_key = 0
u32 index_offset = 0
u32 index_count = 0
u32 vertex_byte_offset = 0
u32 shader_id = 0
u32 depth_shader_id = 0
BlendMode blend_mode = BlendMode::Normal
LayoutId layout_id = LayoutId::Batch
u32 material_id = 0
bool depth_test = false
bool depth_write = true
u8 cull = 0
 CullMode: 0 = none, 1 = back, 2 = front.
i16 depth_bias = 0
 Depth-buffer units toward the eye.
GfxTopology topology = GfxTopology::Triangles
 Triangles or lines.
BatchBreak break_reason = BatchBreak::RunStart
 Why this draw call started.
u8 texture_count = 0
u32 texture_ids [MAX_CMD_TEXTURE_SLOTS] = {}
u16 state_flags = 0
ScissorRect scissor
i32 stencil_ref = 0
u16 stencil_depth = 0
Entity entity = INVALID_ENTITY
RenderType type = RenderType::Sprite
RenderStage stage = RenderStage::Transparent
i32 layer = 0
u32 entity_count = 1
bool instances_relocated = false
u32 instance_count = 0
u32 instance_stride = 0
BufferHandle instance_buffer = BufferHandle::Invalid
BufferHandle vertex_buffer = BufferHandle::Invalid
BufferHandle index_buffer = BufferHandle::Invalid
VertexLayoutHandle vertex_layout = VertexLayoutHandle::Invalid
u32 skin_offset = 0
u32 skin_count = 0
u32 morph_index = 0
u32 probe_index = 0
u32 planar_index = 0
u32 probe_base = 0
u32 vertex_count = 0

Detailed Description

Definition at line 99 of file DrawCommand.hpp.

Member Function Documentation

◆ addTextureSlot()

i32 esengine::DrawCommand::addTextureSlot ( u32 texId,
u8 limit = MAX_CMD_TEXTURE_SLOTS )
inline

◆ blendBits()

u64 esengine::DrawCommand::blendBits ( BlendMode blend)
inlinestatic

The blend field, 3 bits wide wherever it appears.

Masked, because the enum outgrew the field: BlendMode::None is 9, and unmasked it set a bit in the SHADER field above it. Aliasing None onto Additive costs a merge; the spill cost a wrong order.

Definition at line 258 of file DrawCommand.hpp.

Referenced by buildSortKey(), buildSortKeyTree(), and buildSortKeyYSorted().

◆ buildSortKey()

u64 esengine::DrawCommand::buildSortKey ( RenderStage stage,
i32 layer,
u32 shaderId,
BlendMode blend,
u16 stateFlags,
f32 depth,
u32 materialId = 0,
i32 order = 0,
u32 geometry = 0 )
inlinestatic

◆ buildSortKeyTree()

u64 esengine::DrawCommand::buildSortKeyTree ( RenderStage stage,
i32 layer,
u32 sequence,
u32 shaderId,
BlendMode blend,
u16 stateFlags,
i32 order = 0 )
inlinestatic

Definition at line 323 of file DrawCommand.hpp.

References blendBits(), layer, orderBits(), and stage.

Referenced by esengine::pushBatchDraw().

◆ buildSortKeyYSorted()

u64 esengine::DrawCommand::buildSortKeyYSorted ( RenderStage stage,
i32 layer,
f32 worldY,
u32 shaderId,
BlendMode blend,
u16 stateFlags,
i32 order = 0 )
inlinestatic

Definition at line 303 of file DrawCommand.hpp.

References blendBits(), layer, orderBits(), orderedFloatBits(), and stage.

Referenced by esengine::pushBatchDraw().

◆ canMergeWith()

bool esengine::DrawCommand::canMergeWith ( const DrawCommand & next) const
inline

Definition at line 489 of file DrawCommand.hpp.

References mergeBlocker(), esengine::None, and planar_index.

◆ hasPersistentGeometry()

bool esengine::DrawCommand::hasPersistentGeometry ( ) const
inline

Definition at line 181 of file DrawCommand.hpp.

References esengine::Invalid, and vertex_buffer.

Referenced by sameInstancedGeometry().

◆ mergeBlocker()

◆ orderBits()

u64 esengine::DrawCommand::orderBits ( i32 order)
inlinestatic

The order field at [47:40], biased so a negative order sorts below zero.

CLAMPED, not wrapped: an order past the range pins to the extreme it ran past, where a wrap would land it on the far side — "very much on top" turning into "behind everything" is the one failure a clamp cannot make.

Definition at line 266 of file DrawCommand.hpp.

Referenced by buildSortKey(), buildSortKeyTree(), and buildSortKeyYSorted().

◆ orderedFloatBits()

u32 esengine::DrawCommand::orderedFloatBits ( f32 v)
inlinestatic

Definition at line 285 of file DrawCommand.hpp.

Referenced by buildSortKey(), and buildSortKeyYSorted().

◆ orderIndependent()

bool esengine::DrawCommand::orderIndependent ( ) const
inline

Why next cannot join this draw, or None if it can.

The predicate answers with the reason rather than a bare no: a frame is some number of draw calls, and the only actionable thing about that number is what kept them apart. canMergeWith is this, read as a bool. Whether this draw's result is the same wherever it happens among its peers: it replaces what it covers rather than reading it, and depth decides what covers what. Only such draws can be merged into one — a merge is exactly the loss of their relative order.

Definition at line 381 of file DrawCommand.hpp.

References blend_mode, depth_test, depth_write, and esengine::None.

Referenced by sameInstancedGeometry().

◆ sameInstancedGeometry()

bool esengine::DrawCommand::sameInstancedGeometry ( const DrawCommand & next) const
inline

Whether two instanced draws are the same geometry drawn again — what a second instance record answers, rather than a second draw. Both must be order-independent, since merging is the loss of their relative order; a skinned draw is out because one draw can only be in one pose.

Definition at line 391 of file DrawCommand.hpp.

References hasPersistentGeometry(), index_buffer, index_count, index_offset, instance_stride, morph_index, orderIndependent(), planar_index, skin_count, texture_count, texture_ids, vertex_buffer, and vertex_layout.

Referenced by mergeBlocker().

◆ textureSlotBudget()

u8 esengine::DrawCommand::textureSlotBudget ( u8 reservedSlots) const
inline

Finds texId in this command's texture set, adds it (returns its slot), or -1 if the set is full. Used by the merge to assign per-vertex sampler slots. limit is how many slots the merge may spend: a frame with a 2D shadow mask keeps the top one for it, and a merge that took it would bind a sprite where every Lit fragment reads its shadow.

How many sprite textures a merged run headed by this draw may carry.

The Batch stream merges draws of different textures by giving each its own sampler slot and stamping the slot on its vertices — which only the engine's own batch program reads. A material's shader samples the sprite at slot 0 and nothing else (u_textures[0] / t0), so a run of material draws that merged across textures drew every sprite with the first one's picture. Such a run keeps to one texture; a second one starts a new draw.

Definition at line 354 of file DrawCommand.hpp.

References material_id, and esengine::MAX_CMD_TEXTURE_SLOTS.

Referenced by esengine::DrawList::finalize().

◆ withGroupOrder()

u64 esengine::DrawCommand::withGroupOrder ( u64 key,
i32 memberOrder )
inlinestatic

Re-stamps a member's own order into a key whose top fields a SortingGroup has taken over.

[37:30] is the only field directly under stage in ALL three packings, and it must be one field or two members of a group are incomparable. Costs those bits' projection (depth, shader, worldY) inside a group only.

Definition at line 278 of file DrawCommand.hpp.

Referenced by esengine::pushBatchDraw().

Member Data Documentation

◆ blend_mode

BlendMode esengine::DrawCommand::blend_mode = BlendMode::Normal

◆ break_reason

BatchBreak esengine::DrawCommand::break_reason = BatchBreak::RunStart

Why this draw call started.

Definition at line 123 of file DrawCommand.hpp.

Referenced by esengine::FrameCapture::record().

◆ cull

u8 esengine::DrawCommand::cull = 0

CullMode: 0 = none, 1 = back, 2 = front.

Definition at line 120 of file DrawCommand.hpp.

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

◆ depth_bias

i16 esengine::DrawCommand::depth_bias = 0

Depth-buffer units toward the eye.

See also
PipelineDesc.

Definition at line 121 of file DrawCommand.hpp.

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

◆ depth_shader_id

u32 esengine::DrawCommand::depth_shader_id = 0

The program that writes only this draw's depth, for the scene's depth prepass (0 = the draw takes no part in one). Its vertex stage is the draw's own, so the depth it writes is the depth the draw's colour pass lands on.

Definition at line 109 of file DrawCommand.hpp.

Referenced by mergeBlocker(), esengine::pushBatchDraw(), and esengine::takesPartInPrepass().

◆ depth_test

bool esengine::DrawCommand::depth_test = false

◆ depth_write

bool esengine::DrawCommand::depth_write = true

◆ entity

Entity esengine::DrawCommand::entity = INVALID_ENTITY

Definition at line 133 of file DrawCommand.hpp.

Referenced by esengine::pushBatchDraw().

◆ entity_count

u32 esengine::DrawCommand::entity_count = 1

Definition at line 140 of file DrawCommand.hpp.

Referenced by esengine::DrawList::finalize(), and esengine::DrawList::push().

◆ index_buffer

BufferHandle esengine::DrawCommand::index_buffer = BufferHandle::Invalid

Definition at line 159 of file DrawCommand.hpp.

Referenced by mergeBlocker(), esengine::pushBatchDraw(), and sameInstancedGeometry().

◆ index_count

◆ index_offset

u32 esengine::DrawCommand::index_offset = 0

◆ instance_buffer

BufferHandle esengine::DrawCommand::instance_buffer = BufferHandle::Invalid

Definition at line 153 of file DrawCommand.hpp.

Referenced by esengine::pushBatchDraw().

◆ instance_count

u32 esengine::DrawCommand::instance_count = 0

◆ instance_stride

u32 esengine::DrawCommand::instance_stride = 0

◆ instances_relocated

bool esengine::DrawCommand::instances_relocated = false

This draw's instance records have been moved to the end of the stream, where the run it heads is growing. Set by the merge, read by it alone.

Definition at line 143 of file DrawCommand.hpp.

Referenced by esengine::DrawList::finalize().

◆ layer

i32 esengine::DrawCommand::layer = 0

◆ layout_id

LayoutId esengine::DrawCommand::layout_id = LayoutId::Batch

◆ material_id

u32 esengine::DrawCommand::material_id = 0

◆ morph_index

u32 esengine::DrawCommand::morph_index = 0

Definition at line 169 of file DrawCommand.hpp.

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

◆ planar_index

u32 esengine::DrawCommand::planar_index = 0

◆ probe_base

u32 esengine::DrawCommand::probe_base = 0

Definition at line 179 of file DrawCommand.hpp.

◆ probe_index

u32 esengine::DrawCommand::probe_index = 0

Definition at line 174 of file DrawCommand.hpp.

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

◆ scissor

ScissorRect esengine::DrawCommand::scissor

◆ shader_id

u32 esengine::DrawCommand::shader_id = 0

◆ skin_count

u32 esengine::DrawCommand::skin_count = 0

Definition at line 165 of file DrawCommand.hpp.

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

◆ skin_offset

u32 esengine::DrawCommand::skin_offset = 0

Definition at line 164 of file DrawCommand.hpp.

Referenced by esengine::pushBatchDraw().

◆ sort_key

u64 esengine::DrawCommand::sort_key = 0

Definition at line 100 of file DrawCommand.hpp.

Referenced by esengine::pushBatchDraw().

◆ stage

◆ state_flags

◆ stencil_depth

u16 esengine::DrawCommand::stencil_depth = 0

Definition at line 131 of file DrawCommand.hpp.

Referenced by esengine::ClipState::applyTo().

◆ stencil_ref

i32 esengine::DrawCommand::stencil_ref = 0

◆ texture_count

◆ texture_ids

◆ topology

GfxTopology esengine::DrawCommand::topology = GfxTopology::Triangles

Triangles or lines.

See also
PipelineDesc.

Definition at line 122 of file DrawCommand.hpp.

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

◆ type

RenderType esengine::DrawCommand::type = RenderType::Sprite

◆ vertex_buffer

BufferHandle esengine::DrawCommand::vertex_buffer = BufferHandle::Invalid

◆ vertex_byte_offset

u32 esengine::DrawCommand::vertex_byte_offset = 0

Definition at line 104 of file DrawCommand.hpp.

Referenced by esengine::DrawList::finalize(), and esengine::pushBatchDraw().

◆ vertex_count

u32 esengine::DrawCommand::vertex_count = 0

Definition at line 185 of file DrawCommand.hpp.

Referenced by esengine::pushBatchDraw().

◆ vertex_layout

VertexLayoutHandle esengine::DrawCommand::vertex_layout = VertexLayoutHandle::Invalid

Definition at line 160 of file DrawCommand.hpp.

Referenced by mergeBlocker(), esengine::pushBatchDraw(), and sameInstancedGeometry().


The documentation for this struct was generated from the following file:
  • /home/runner/work/estella/estella/src/esengine/renderer/draw/DrawCommand.hpp