Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
RenderFrame.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
7#pragma once
8
9#include "SkinCache.hpp"
10#include "../../core/Types.hpp"
13#include "./RenderContext.hpp"
23#ifdef ES_ENABLE_POSTPROCESS
25#endif
26#include "./FrameCapture.hpp"
27#include "../rhi/GfxDevice.hpp"
28#include "../rhi/Texture.hpp"
30#include "../draw/DrawList.hpp"
32#include "../draw/ClipState.hpp"
36
37#include <glm/glm.hpp>
38#include <array>
39#include <span>
40#include <unordered_map>
41#include <vector>
42#include <string>
43#include <memory>
44#include <unordered_map>
45#include <unordered_set>
46
47namespace esengine {
48
49class GpuParticles;
50
51namespace ecs { struct Light; }
52class ImmediateDraw;
53
57inline constexpr u32 kShadowAtlasSize = 2048;
61inline constexpr u32 kShadowCellSize = 512;
62inline constexpr u32 kShadowCascadeCells = 2;
63
71enum class ShadowShape : u8 { Box, Cone, Cube };
72
73// GPU frame timer: a small ring of device timer queries so a frame's result is
74// read a few frames later without stalling the CPU on the GPU.
75class GpuTimer {
76public:
77 void begin(GfxDevice& device);
78 void end(GfxDevice& device);
79 void poll(GfxDevice& device);
80 f32 lastMs() const { return last_ms_; }
81
82private:
83 static constexpr int kRing = 3;
84 u32 queries_[kRing] = {0, 0, 0};
85 bool inflight_[kRing] = {false, false, false};
86 int write_ = 0;
87 int read_ = 0;
88 int state_ = 0; // 0 = uninit, 1 = available, 2 = unavailable
89 bool active_ = false;
90 f32 last_ms_ = -1.0f;
91};
92
94
96public:
97 struct Stats {
115 f32 gpu_time_ms = -1.0f; // -1 when the timer is unavailable
116 };
117
118 RenderFrame(GfxDevice& device, RenderContext& context,
119 resource::ResourceManager& resource_manager);
120 ~RenderFrame();
121
122 RenderFrame(const RenderFrame&) = delete;
124
125 void init(u32 width, u32 height);
126 void shutdown();
127 void resize(u32 width, u32 height);
128 void setShadowBudget(u32 atlasSize, u32 cellSize, u32 cascades);
129 void setShadowDistance(f32 distance);
131 void setShadow2DSoftSamples(u32 samples);
132 bool setQualityValue(const std::string& name, f32 value);
135 void setDepthPrepass(bool on) { depth_prepass_ = on; }
138 void setProbesPerPixel(bool on) { probes_per_pixel_ = on; }
139 bool probesPerPixel() const { return probes_per_pixel_; }
140 void setLodDistanceScale(f32 scale) { lod_distance_scale_ = scale > 0.0f ? scale : 1.0f; }
141 f32 lodDistanceScale() const { return lod_distance_scale_; }
142 void setOcclusionGridSize(u32 size) { occlusion_.setSize(size); }
143 void setTargetPoolIdleBudget(u64 bytes) { target_pool_.setIdleByteBudget(bytes); }
148 void setSkyEnvironment(resource::EnvironmentHandle environment) { sky_environment_ = environment; }
149 void setLightingDirect(bool on);
150 bool lightingDirect() const { return lighting_direct_; }
151 void setPlanarQuality(f32 scale, u32 maxSize, f32 updatesPerSecond, bool capAuthored);
156 void wantTextureSide(u32 texture, f32 side) {
157 if (texture == 0 || !(side > 0.0f)) return;
158 f32& held = texture_wants_[texture];
159 if (side > held) held = side;
160 }
161
162 std::string takeTextureWants();
164 f32 viewHeightPx() const { return static_cast<f32>(scene_viewport_.h > 0 ? scene_viewport_.h : height_); }
165
170 };
171
172 void setImpostorAtlas(Entity entity, u32 texture, u32 frames) {
173 if (texture == 0 || frames < 2) { impostor_atlases_.erase(entity.raw); return; }
174 impostor_atlases_[entity.raw] = {texture, frames};
175 }
176 const ImpostorAtlas* impostorAtlas(Entity entity) const {
177 const auto it = impostor_atlases_.find(entity.raw);
178 return it == impostor_atlases_.end() ? nullptr : &it->second;
179 }
181 return entity == planar_receiver_ ? planar_texture_ : 0;
182 }
183 const PlanarConstants& planarConstants() const { return planar_constants_; }
184 std::string planarStatus(u32 view, u32 entity) const;
185
187 void setPresentedOverlayDraw(ImmediateDraw* draw) { presented_overlay_draw_ = draw; }
188
192 struct PassClear {
193 bool color = false;
194 bool depth = false;
195 glm::vec4 colorValue{0.0f, 0.0f, 0.0f, 1.0f};
196 i32 x = 0, y = 0;
197 u32 w = 0, h = 0;
198 };
199
208 void beginFrame();
209 void setPlanarTime(f32 seconds) { planar_elapsed_ = seconds; }
210
219 void endFrame();
220
221 void begin(const glm::mat4& view_projection, RenderTargetManager::Handle target = 0);
222 void begin(const glm::mat4& view_projection, RenderTargetManager::Handle target,
223 const PassClear& clear);
224 void flush();
225 void end();
226
227 void processMasks(ecs::Registry& registry, i32 vpX, i32 vpY, i32 vpW, i32 vpH);
231 void processMasks(ecs::Registry& registry, const glm::mat4& projection,
232 i32 vpX, i32 vpY, i32 vpW, i32 vpH);
233
234 // ---- The screen-space overlay -------------------------------------------
235 //
236 // One pass a frame, after every camera and after post. The frame's, not a
237 // camera's: the projection comes from the layout domain.
238
241 void setScreenDomain(const std::unordered_set<u32>* domain) { screen_domain_ = domain; }
243 void setUITreeLayers(const std::unordered_map<u32, i32>* layers) { ui_tree_layers_ = layers; }
246 void setScreenRoots(const std::vector<u32>* roots, const std::vector<u32>* rootByIndex) {
247 screen_roots_ = roots;
248 screen_root_by_index_ = rootByIndex;
249 }
250
253 void beginScreenOverlay(const glm::mat4& projection, i32 vpX, i32 vpY, u32 vpW, u32 vpH);
254
258 void submitScreenOverlay(ecs::Registry& registry);
259
262 void setRetainedTextCollected(bool collected) { retained_text_collected_ = collected; }
263 bool retainedTextCollected() const { return retained_text_collected_; }
265 void submitRetainedText(ecs::Registry& registry, bool screen, const f32* projection, u32 onlyRoot = 0);
266
272 bool keepScreenOverlay(ecs::Registry& registry, bool hostStill);
273
274 void setScreenOverlayEffect(u32 material);
276
282 void drawOverScreen(i32 vpX, i32 vpY, u32 vpW, u32 vpH, RenderTargetManager::Handle target);
283
285 bool screenOverlayOpen() const { return overlay_active_; }
286
287 void setEntityClipRect(u32 entity, i32 x, i32 y, i32 w, i32 h);
288 void clearAllClipRects();
289
290 void setEntityStencilMask(u32 entity, i32 refValue, bool hierarchical = false);
291 void setEntityStencilTest(u32 entity, i32 refValue, bool hierarchical = false);
293
294 void submitTileQuad(
295 const glm::vec2& position, const glm::vec2& size,
296 const glm::vec2& uvOffset, const glm::vec2& uvScale,
297 const glm::vec4& color, u32 textureId,
298 Entity entity, i32 layer, f32 depth
299 );
300
306 void submitTextBatch(
307 const f32* vertices, i32 vertexCount,
308 const u16* indices, i32 indexCount,
309 u32 textureId, const f32* transform16,
310 Entity entity, i32 layer, f32 depth, TextGlyphMode mode, u32 cullBit = 0
311 );
312
314 RetainedTextStore& retainedText() { return retained_text_; }
315
330
340 std::vector<f32> vertices;
341 std::vector<u16> indices;
344 bool premultipliedColor = false;
345 glm::mat4 transform{1.0f};
348 f32 depth = 0.0f;
350 };
351
365 const f32* vertices, i32 vertexCount,
366 const u16* indices, i32 indexCount,
367 u32 textureId, i32 blendMode,
368 const f32* transform16,
369 Entity entity, i32 layer, f32 depth, u32 materialId = 0, bool premultipliedColor = false,
370 f32 treeAlpha = 1.0f, u32 cullBit = 0
371 );
372
374 bool uiTreeHolds(Entity entity) const {
375 return ui_tree_layers_ && ui_tree_layers_->count(entity.id()) != 0;
376 }
377
378 void setStage(RenderStage stage) { current_stage_ = stage; }
379 RenderStage getStage() const { return current_stage_; }
380
381#ifdef ES_ENABLE_POSTPROCESS
382 PostProcessPipeline* postProcess() { return post_process_.get(); }
383#endif
384 RenderTargetManager& targetManager() { return target_manager_; }
385
393 u32 queueMaterialBake(u32 material, u32 shader, u32 target, u32 x, u32 y, u32 w, u32 h, const glm::vec4& a, const glm::vec4& b);
396 i32 materialBakeState(u32 ticket);
397 void cancelMaterialBakesFor(u32 target);
398 bool projectMaterialBake(u32 ticket, u32 material, u32 target, u32 instances);
399
400 const Stats& stats() const { return stats_; }
401 FrameCapture& frameCapture() { return frame_capture_; }
402
404 void setYSortLayers(u32 mask) { draw_list_.setYSortMask(mask); }
406 void setTreeSortLayers(u32 mask) { draw_list_.setTreeMask(mask); }
407 void setDepthLayers(u32 mask) {
408 draw_list_.setDepthMask(mask);
409 // Through the one applier: the mask is no longer the whole answer, only
410 // half of it. Before init there is no pipeline yet, and init asks again.
411 applySceneDepthNeed();
412 }
413 u32 depthLayers() const { return draw_list_.depthMask(); }
414
416 void setCullingMask(u32 mask) { draw_list_.setCullingMask(mask); }
417
425 void setViewId(u32 view) { view_id_ = view; }
426
436 bool clusterInspect(Entity entity, u32& outTriangles, u32& outClusters) const {
437 for (const auto& plugin : plugins_) {
438 if (plugin->clusterInspect(entity.id(), outTriangles, outClusters)) return true;
439 }
440 return false;
441 }
442
443 bool lodInspect(u32 view, Entity entity, u8& outLevel, u8& outUnbiased,
444 u8& outLevels, f32& outSize) const {
445 return lod_view_state_.inspect(view, entity, outLevel, outUnbiased, outLevels, outSize);
446 }
447
456 void setLodPreview(u32 view, Entity entity, u8 level) {
457 lod_view_state_.preview(view, entity, level);
458 }
459
461 usize lodPreviewCount() const { return lod_view_state_.previewCount(); }
462
470 void setViewShading(u32 view, ShadingMode mode) { view_shading_.set(view, mode); }
477 void setViewSelection(u32 view, const u32* ids, u32 count) {
478 if (count == 0) { view_selection_.erase(view); return; }
479 view_selection_[view] = std::unordered_set<u32>(ids, ids + count);
480 }
481
485 void requestProbeCapture(const glm::vec3& position, u32 face);
489 const std::vector<u8>& probeCapturePixels() const { return probe_capture_.pixels; }
494 void setProbeVolumeReflection(u32 entity, u32 environment, u32 slot) {
495 if (environment != 0 && slot != 0) probe_reflections_[entity] = {environment, slot};
496 else probe_reflections_.erase(entity);
497 }
498
501 world_units_per_meter_ = units > 0.0f ? units : 100.0f;
502 // The same answer for every default that is a length: a material's unset params follow it (MaterialParamSlot::worldUnits).
503 context_.materials().setWorldUnitsPerMeter(world_units_per_meter_);
504 }
505
510 void setViewSkinWeights(u32 view, Entity entity, u32 joint) { view_shading_.setWeights(view, entity, joint); }
511
513 ShadingMode viewShading(u32 view) const { return view_shading_.get(view); }
514
521 const ShadowPlanReport& shadowPlan() const { return shadow_plan_; }
522
534 return {shadow_held_builds_, shadow_mover_collects_, shadow_lists_kept_, shadow_held_stale_,
535 cover_builds_, cover_mover_collects_, cover_draws_total_, cover_kept_total_};
536 }
537
545 const LightCapReport& lightCap() const { return light_cap_; }
546
559 bool studio = false;
561 f32 rotation = 0.0f;
567 bool showSky = false;
568 };
569 void setViewLighting(const ViewLighting& lighting) { view_lighting_ = lighting; }
570 const ViewLighting& viewLighting() const { return view_lighting_; }
572 bool sceneSkyAvailable() const { return scene_sky_available_; }
573
581 void setColorSpace(bool linear);
582 bool linearColor() const { return linear_color_; }
583
589 void replayToDrawCall(i32 drawIndex);
592 bool snapshotMatchesCapture() const { return snapshot_matches_; }
593 const u8* getSnapshotPixels() const { return snapshot_pixels_.data(); }
594 u32 getSnapshotSize() const { return static_cast<u32>(snapshot_pixels_.size()); }
595 u32 getSnapshotWidth() const { return snapshot_w_; }
596 u32 getSnapshotHeight() const { return snapshot_h_; }
597
606
613 void renderToTarget(ecs::Registry& registry, const glm::mat4& viewProjection, u32 w, u32 h);
614 const u8* getPreviewPixels() const { return preview_.pixels.data(); }
615 u32 getPreviewSize() const { return static_cast<u32>(preview_.pixels.size()); }
616 u32 getPreviewWidth() const { return preview_.width; }
617 u32 getPreviewHeight() const { return preview_.height; }
618
621
622 // — Skeletal previews —————————————————————————————————————————————————————
623 // Every call names its handle: no current preview, no mode, no begin/end
624 // pair, so two in flight cannot reach each other whatever the call order.
625
629
632
638 const f32* vertices, i32 vertexCount,
639 const u16* indices, i32 indexCount,
640 u32 textureId, i32 blendMode, const f32* transform16,
641 i32 layer, f32 depth, u32 materialId, bool premultipliedColor = false);
642
650 bool renderSkeletalPreview(SkeletalPreviewId id, const glm::mat4& viewProjection);
651
658
665
666 void addPlugin(std::unique_ptr<RenderTypePlugin> plugin);
667
676 RenderPrewarmResult prewarmPrograms(ecs::Registry& registry, const Entity* entities, u32 count);
677
681 void collectAll(ecs::Registry& registry, bool sceneGBuffer = true);
683 bool inFrame() const { return in_frame_; }
685 u32 stagedVertexBytes(LayoutId layout) const { return pool_.vertexBytesUsed(layout); }
686
695 bool visibleToCamera(i32 layer, const glm::vec3& center, const glm::vec3& halfExtents) const;
696
698 u32 batchProgram(const std::vector<std::string>& features);
699 u32 displayProgram(u32 program);
700
701 static constexpr u32 STAGE_COUNT = 4;
702
703#ifdef ES_ENABLE_GPU_PARTICLES
705 GpuParticles* gpuParticles() { return gpu_particles_.get(); }
706#endif
708 SkinCache* skinCache() { return skin_cache_.get(); }
709
710private:
711 GfxDevice& device_;
712 RenderContext& context_;
713 resource::ResourceManager& resource_manager_;
714 ImmediateDraw* presented_overlay_draw_ = nullptr;
715
716#ifdef ES_ENABLE_POSTPROCESS
717 Unique<PostProcessPipeline> post_process_;
718#endif
719#ifdef ES_ENABLE_GPU_PARTICLES
721 Unique<GpuParticles> gpu_particles_;
722#endif
723 Unique<SkinCache> skin_cache_;
725 u64 skin_cache_frame_ = ~0ull;
726 void declareSkinCache(ecs::Registry& registry);
727 RenderTargetManager target_manager_;
728 struct MaterialBake { u32 ticket; u32 material; u32 shader; u32 target; u32 x, y, w, h; glm::vec4 a, b; u32 projection = 0, receiver = 0, instances = 0; };
730 std::vector<MaterialBake> material_bakes_;
731 std::vector<rg::ResourceId> projected_bake_resources_;
732 std::unordered_map<u32, i32> material_bake_states_;
733 u32 next_material_bake_ = 1;
734 u32 material_bakes_drawn_ = 0;
735 struct WaterSunField {
737 u32 target = 0;
738 glm::vec4 rect{}, depth{}, sun{};
739 glm::vec3 sunDirection{};
740 };
741 WaterSunField water_sun_;
743 u64 material_bakes_frame_ = ~0ull;
744
745 glm::mat4 view_projection_{1.0f};
746 Frustum frustum_;
748 OcclusionView occlusion_;
749 RenderTargetManager::Handle current_target_ = 0;
750 RenderStage current_stage_ = RenderStage::Transparent;
751
752 // Polls + lands one async readback: takes into @p pixels when Ready and
753 // resets @p handle. Returns the 0/1/2 contract of the public poll methods.
754 i32 pollReadback(ReadbackHandle& handle, std::vector<u8>& pixels, u32 w, u32 h);
755
763 void renderSurface(ecs::Registry& registry, const glm::mat4& viewProjection,
764 PreviewSurface& surface, u32 w, u32 h,
765 std::span<const PendingSkeletalBatch> extraSkeletalBatches);
766
767 Stats stats_;
773 GpuTimer gpu_timer_;
775 Unique<rg::PassTimer> pass_timer_;
777 std::unordered_map<const char*, std::string> pass_scope_names_;
778 f32 pass_graph_ms_ = -1.0f;
780 bool gpu_frame_open_ = false;
781 bool gpu_frame_passes_ = false;
783 rg::PassTimer* running_pass_timer_ = nullptr;
784 bool gpuDetailWanted() const;
785 FrameCapture frame_capture_;
786 std::vector<u8> snapshot_pixels_;
787 RenderTargetManager::Handle replay_rt_ = 0;
788 ReadbackHandle snapshot_readback_ = ReadbackHandle::Invalid;
789 i32 replay_pass_ = -1;
790 i32 replay_draw_ = -1;
791 bool snapshot_matches_ = false;
792 void runPendingReplay(const glm::mat4& projection, u32 w, u32 h);
793 void tallyPass(const DrawList& list);
794 void publishFrameCounters();
795 u32 frame_merged_ = 0;
796 u32 frame_breaks_[static_cast<u32>(BatchBreak::Count)] = {};
797 u32 snapshot_w_ = 0;
798 u32 snapshot_h_ = 0;
799 PreviewSurface preview_;
800
802 struct SkeletalPreview {
803 ecs::Registry registry;
804 Entity entity{};
805 std::vector<PendingSkeletalBatch> pending;
806 PreviewSurface surface;
807 };
810 static constexpr u32 kPreviewViewId = 0xFFFFFFFEu;
811
812 u32 view_id_ = 0;
813 lod::LodViewState lod_view_state_;
814 ViewShading view_shading_;
815 lod::SelectionCounts lod_counts_;
816
817 std::unordered_map<SkeletalPreviewId, Unique<SkeletalPreview>> skeletal_previews_;
819 SkeletalPreviewId next_skeletal_preview_ = 1;
820
821 SkeletalPreview* skeletalPreview(SkeletalPreviewId id);
822 const SkeletalPreview* skeletalPreview(SkeletalPreviewId id) const;
823 bool in_frame_ = false;
824 bool flushed_ = false;
827 bool depth_seen_ = false;
829 bool frame_depth_seen_ = false;
831 bool scene_picture_seen_ = false;
832 bool frame_scene_picture_seen_ = false;
835 bool frame_collected_ = false;
837 bool depth_answered_ = false;
838 u32 width_ = 0;
839 u32 height_ = 0;
840
841 std::unordered_map<u32, ScissorRect> clip_rects_;
842
843 struct EntityStencilInfo {
844 i32 ref_value = 0;
845 bool is_mask = false;
846 bool hierarchical = false;
847 };
848 std::unordered_map<u32, EntityStencilInfo> stencil_masks_;
849
850 u32 batch_shader_id_ = 0;
851 std::unordered_map<std::string, resource::ShaderHandle> batch_variants_;
852 std::array<const resource::ShaderHandle*, static_cast<usize>(BatchVariant::Count)> batch_variant_handles_{};
853 TransientBufferPool pool_;
854 DrawList draw_list_;
855 bool linear_color_ = false;
856 ClipState clip_state_;
857 std::vector<std::unique_ptr<RenderTypePlugin>> plugins_;
858
859 RenderFrameContext makeContext();
860 void buildClipState();
862 void buildSpriteMasks(ecs::Registry& registry);
864 void buildSortingGroups(ecs::Registry& registry);
866 void buildTreeSequence(ecs::Registry& registry);
867 std::vector<Entity> tree_pending_;
869 void accumulateStats(const DrawList& list);
872 void drawScreenOverlay();
873
882 void applySceneDepthNeed();
886 void collectLights(ecs::Registry& registry);
888 void collectStudioLights(ecs::Registry& registry);
889
891 void collectProbes(ecs::Registry& registry);
892
897 void collectOccluders(ecs::Registry& registry);
898
900 void collectReflections(ecs::Registry& registry);
901 void declarePlanarReflection(ecs::Registry& registry);
902 void declareProbeCapture(ecs::Registry& registry);
903 void collectProbeFace(ecs::Registry& registry);
904 void executeProbeFace();
905 struct ProbeCapture {
906 enum class State : u8 { Idle, Capturing, Drawn, Reading };
907 State state = State::Idle;
908 glm::vec3 position{0.0f};
909 u32 face = 32;
910 u32 next = 0;
911 u64 frame = ~0ull;
912 glm::mat4 viewProjection{1.0f};
913 Unique<Framebuffer> faces[6];
917 std::vector<u8> pixels;
918 };
919 ProbeCapture probe_capture_;
920 std::unordered_map<u32, resource::ProbeVolumeHandle> probe_overrides_;
921 struct CapturedReflection { u32 environment = 0; u32 slot = 0; };
922 std::unordered_map<u32, CapturedReflection> probe_reflections_;
923 void collectPlanarReflection(ecs::Registry& registry, u32 view);
924 void executePlanarReflection(u32 view);
925 struct PlanarCapture {
926 Unique<Framebuffer> target;
928 Entity receiver = INVALID_ENTITY;
929 PlanarReflectionCamera camera;
930 u64 lastSeen = 0;
931 u64 generation = 0;
932 u32 revision = 0;
933 u32 mask = 0xFFFFFFFFu;
934 f32 lastTime = -1.0f;
935 u32 draws = 0;
936 u32 rejected = 0;
937 bool valid = false;
938 };
939 std::unordered_map<u32, PlanarCapture> planar_captures_;
940 TransientBufferPool planar_pool_{device_};
941 TransientBufferPool probe_pool_{device_};
942 DrawList probe_list_;
943 f32 world_units_per_meter_ = 100.0f;
946 Unique<Texture> probe_atlas_;
947 std::vector<u16> probe_atlas_texels_;
948 DrawList planar_list_;
949 u64 planar_frame_ = 0;
950 f32 planar_elapsed_ = 0;
951 f32 planar_scale_ = 0.5f;
952 bool planar_float_refused_ = false;
953 u32 planar_max_size_ = 1024;
954 f32 planar_rate_ = 0;
955 bool planar_capped_ = false;
956 Entity planar_receiver_ = INVALID_ENTITY;
957 u32 planar_texture_ = 0;
959 std::unordered_map<u32, ImpostorAtlas> impostor_atlases_;
961 std::unordered_map<u32, f32> texture_wants_;
962 PlanarConstants planar_constants_;
963 glm::vec4 scene_clear_{0.0f, 0.0f, 0.0f, 1.0f};
964 rg::ResourceId planar_resource_ = rg::kNoResource;
965 void releasePlanarCaptures();
966
971 bool collectEnvironment(const ecs::Light& light, const glm::vec3& scale, bool withoutSun);
973 resource::EnvironmentHandle environmentOf(const ecs::Light& light) const;
974 resource::EnvironmentHandle sky_environment_{};
983 void buildShadowPlan(ecs::Registry& registry);
992 void declareShadowPass(ecs::Registry& registry);
994 void declareMaterialBakes(ecs::Registry& registry);
995#ifdef ES_ENABLE_POSTPROCESS
996 struct ReceiverCapture {
997 explicit ReceiverCapture(GfxDevice& device) : pool(device) {}
998 ~ReceiverCapture() {
999 pool.shutdown();
1000 if (constants != BufferHandle::Invalid) pool.device().deleteBuffer(constants);
1001 }
1002 u32 bakeTarget = 0;
1003 TransientBufferPool pool;
1004 DrawList draws;
1005 BufferHandle constants = BufferHandle::Invalid;
1006 Unique<Framebuffer> target;
1007 u64 key = 0;
1008 bool valid = false;
1009 };
1010 struct ReceiverMaps {
1011 rg::ResourceId fixed = rg::kNoResource, moving = rg::kNoResource;
1012 glm::vec4 window{0, 0, 1, 0};
1013 };
1014 std::vector<Unique<ReceiverCapture>> receiver_captures_;
1015 ReceiverMaps declareCausticReceivers(ecs::Registry& registry, const MaterialBake& bake, const glm::vec4& sun, usize index);
1016#endif
1021 bool collectShadowViews(ecs::Registry& registry, u64 inputs, bool vouched, u64 heldInputs, bool heldVouched, u64& key);
1022 void collectShadowLists(ecs::Registry& registry, CasterSplit split, TransientBufferPool& pool, std::vector<DrawList>& lists,
1023 u32& culled);
1024 u32 shadowViewDraws(usize vi) const;
1026 void executeShadowPass();
1027
1036 void collectShadow2D(ecs::Registry& registry);
1037
1039 bool hasShape2DLight(ecs::Registry& registry);
1040
1042 void declareShadow2DPass();
1043
1046 void executeShadow2DPass(u32 mask);
1047
1049 void buildShadow2DGeometry(u32 mask);
1050
1052 void releaseShadow2DResources();
1053
1055 bool ensureShadow2DShader();
1056
1059 bool shadow2DActive() const { return shadow_2d_masks_[0].textureId != 0; }
1060
1067 void collectShape2D(ecs::Registry& registry);
1068
1070 void declareShape2DPass();
1071
1073 void executeShape2DPass();
1074
1076 void releaseShape2DResources();
1077
1079 bool ensureShape2DShader();
1080
1082 bool shape2DActive() const { return shape_2d_texture_id_ != 0; }
1083
1085 void ensureShadowFrameUbos(u32 count);
1086
1088 void releaseShadowFrameUbos();
1090 void drawScene(DrawList::Phase phase = DrawList::Phase::All);
1092 void submitColorList(DrawList& list, TransientBufferPool& buffers, FrameCapture* capture,
1093 DrawList::Phase phase, const char* prepassCounter);
1096 void releaseFrameTargets();
1097
1098 struct MeshBounds {
1099 glm::vec3 min{0.0f}, max{0.0f};
1100 bool valid = false;
1101 void include(const glm::vec3& centre, const glm::vec3& half) {
1102 min = valid ? glm::min(min, centre - half) : centre - half;
1103 max = valid ? glm::max(max, centre + half) : centre + half;
1104 valid = true;
1105 }
1106 };
1107 struct ShadowBounds { MeshBounds all, casters, hair; };
1109 ShadowBounds gatherShadowBounds(ecs::Registry& registry, bool includeHair);
1112 void openPass(const PassClear& clear, RenderTargetManager::Handle target);
1113 u32 initBatchShader();
1114 const resource::ShaderHandle& batchVariantHandle(const std::vector<std::string>& features);
1115 resource::ShaderHandle compileBatchVariant(const std::vector<std::string>& features);
1116
1125 struct ShadowCaster {
1126 u32 slot = 0;
1129 Entity light{};
1133 glm::vec3 dir{0.0f, 0.0f, -1.0f};
1135 glm::vec3 pos{0.0f};
1137 f32 extent = 0.0f;
1140 f32 range = 0.0f;
1141 f32 outerAngle = 0.0f;
1142 f32 split = 0.75f;
1143 f32 bias = 1.5f;
1144 f32 slopeFloor = 0.15f;
1145 };
1149 struct CollectedLight {
1150 GpuLight gpu;
1151 bool castsMeshShadow;
1152 ShadowCaster caster;
1153 };
1154 std::vector<CollectedLight> light_scratch_; // reused across frames; collectLights only
1157 std::vector<ShadowCaster> shadow_casters_;
1160 i32 cloud_sun_slot_ = -1;
1161 glm::vec3 cloud_sun_aim_{0.0f, -1.0f, 0.0f};
1164 i32 cloud_tile_ = -1;
1165 glm::mat4 cloud_matrix_{1.0f};
1169 rg::TargetPool target_pool_;
1173 rg::RenderGraph graph_;
1176 rg::ResourceId scene_resource_ = rg::kNoResource;
1181 GfxDevice::Viewport scene_viewport_{};
1190 struct ShadowRing2D {
1191 u32 first = 0;
1192 u32 count = 0;
1194 glm::vec2 centre{0.0f};
1195 f32 radius = 0.0f;
1196 };
1197
1199 struct Shadow2DLight {
1201 glm::vec2 pos{0.0f};
1203 glm::vec2 dir{0.0f};
1206 f32 reach = 0.0f;
1208 f32 softness = 0.0f;
1210 u32 slot = 0;
1212 u32 channel = 0;
1214 bool tiled = false;
1215 bool directional = false;
1216 };
1217
1218 std::vector<glm::vec2> shadow_points_2d_;
1219 std::vector<ShadowRing2D> shadow_rings_2d_;
1220 std::vector<Shadow2DLight> shadow_2d_lights_;
1222 u32 shadow_2d_unplaced_ = 0;
1226 struct Shadow2DMask {
1228 u32 textureId = 0;
1231 std::vector<f32> vertices;
1233 u32 vboBytes = 0;
1234 };
1235 Shadow2DMask shadow_2d_masks_[2];
1236 RetainedTextStore retained_text_;
1238 resource::ShaderHandle shadow_2d_shader_{};
1239 bool shadow_2d_shader_tried_ = false;
1240
1242 struct Shape2DLight {
1244 glm::vec2 corners[4]{};
1246 u32 texture = 0;
1248 u32 slot = 0;
1249 };
1250
1251 std::vector<Shape2DLight> shape_2d_lights_;
1253 rg::ResourceId shape_2d_resource_ = rg::kNoResource;
1254 u32 shape_2d_texture_id_ = 0;
1256 std::vector<f32> shape_2d_vertices_;
1257 BufferHandle shape_2d_vbo_ = BufferHandle::Invalid;
1258 u32 shape_2d_vbo_bytes_ = 0;
1260 resource::ShaderHandle shape_2d_shader_{};
1261 bool shape_2d_shader_tried_ = false;
1262
1266 rg::ResourceId shadow_resource_ = rg::kNoResource;
1273 struct ShadowView {
1274 glm::mat4 view_projection{1.0f};
1275 u32 x = 0;
1276 u32 y = 0;
1277 u32 size = 0;
1280 bool sun = false;
1281 glm::vec3 ray{0.0f, -1.0f, 0.0f};
1282 f32 floorY = 0.0f;
1283 f32 reachCap = 0.0f;
1284 };
1286 bool shadow_receiver_cull_ = true;
1289 std::vector<ShadowView> shadow_views_;
1298 TransientBufferPool shadow_pool_;
1303 TransientBufferPool velocity_pool_;
1304 DrawList velocity_list_;
1306 std::unordered_map<u32, std::unordered_set<u32>> view_selection_;
1307 TransientBufferPool selection_pool_;
1308 DrawList selection_list_;
1309 Unique<Framebuffer> selection_fbo_;
1311 void collectSelection(ecs::Registry& registry);
1312 void executeSelectionPass();
1314 rg::ResourceId declareSelectionMask();
1316 glm::vec2 velocity_jitter_{0.0f};
1318 void collectMotion(ecs::Registry& registry);
1319 void executeMotionPass();
1327 void collectCover(ecs::Registry& registry);
1328 void executeCoverPass();
1329 TransientBufferPool cover_pool_;
1330 DrawList cover_list_;
1331 TransientBufferPool cover_mover_pool_{device_};
1332 DrawList cover_mover_list_;
1333 u64 cover_held_hash_ = 0;
1334 bool cover_held_trusted_ = false;
1335 u64 cover_held_inputs_ = 0;
1336 bool cover_held_valid_ = false;
1337 bool cover_held_uploaded_ = false;
1338 bool cover_movers_uploaded_ = false;
1339 u64 cover_lists_inputs_ = 0;
1340 bool cover_lists_valid_ = false;
1341 u64 cover_key_ = 0;
1342 bool cover_trusted_ = false;
1343 u64 cover_drawn_key_ = 0;
1344 bool cover_drawn_valid_ = false;
1345 u32 cover_drawn_target_ = 0;
1346 u32 cover_builds_ = 0;
1347 u32 cover_mover_collects_ = 0;
1348 u32 cover_draws_total_ = 0;
1349 u32 cover_kept_total_ = 0;
1350 bool cover_wanted_ = false;
1351 bool coverInputs(ecs::Registry& registry, u64& key, u64& heldKey, bool& heldVouched);
1352 u32 coverCommandCount() const { return cover_list_.commandCount() + cover_mover_list_.commandCount(); }
1353 BufferHandle cover_frame_ubo_ = BufferHandle::Invalid;
1354 glm::mat4 cover_view_projection_{1.0f};
1356 glm::vec2 scene_jitter_{0.0f};
1358 bool depth_prepass_ = false;
1359 bool probes_per_pixel_ = true;
1360 bool lighting_direct_ = false;
1361 f32 lod_distance_scale_ = 1.0f;
1364 std::vector<DrawList> shadow_view_lists_;
1367 Unique<Framebuffer> shadow_target_;
1370 u64 shadow_drawn_key_ = 0;
1371 bool shadow_drawn_valid_ = false;
1373 u64 shadow_pending_key_ = 0;
1374 bool shadow_pending_trusted_ = false;
1376 bool shadow_reused_ = false;
1379 u64 shadow_drawn_inputs_ = 0;
1380 bool shadow_drawn_inputs_valid_ = false;
1381 u64 shadow_pending_inputs_ = 0;
1382 bool shadow_pending_inputs_valid_ = false;
1384 u32 shadow_inputs_stale_ = 0;
1385 bool warned_shadow_inputs_ = false;
1387 bool shadowInputs(ecs::Registry& registry, u64& key, u64& heldKey, bool& heldVouched);
1388 TransientBufferPool shadow_mover_pool_{device_};
1389 std::vector<DrawList> shadow_mover_lists_;
1390 std::vector<u64> shadow_held_hash_;
1391 std::vector<u8> shadow_held_trusted_;
1392 u32 shadow_held_culled_ = 0;
1393 u64 shadow_held_inputs_ = 0;
1394 bool shadow_held_valid_ = false;
1395 bool shadow_held_uploaded_ = false;
1396 u64 shadow_lists_inputs_ = 0;
1397 bool shadow_lists_valid_ = false;
1398 u64 shadow_lists_key_ = 0;
1399 bool shadow_lists_trusted_ = false;
1400 u32 shadow_held_builds_ = 0;
1401 u32 shadow_mover_collects_ = 0;
1402 u32 shadow_lists_kept_ = 0;
1403 u32 shadow_held_stale_ = 0;
1404 bool warned_shadow_held_ = false;
1405 u32 shadow_casters_culled_ = 0;
1407 u32 shadow_held_tiles_ = 0;
1408 u32 shadow_held_draws_ = 0;
1409
1413 std::vector<u64> shadow_tile_keys_;
1414 std::vector<u8> shadow_tile_held_;
1415 std::vector<u32> shadow_tile_draws_;
1416 u64 shadow_tile_layout_ = 0;
1417 bool shadow_tiles_known_ = false;
1419 std::vector<u64> shadow_view_keys_;
1420 std::vector<u8> shadow_view_trusted_;
1421 std::vector<u8> shadow_view_redraw_;
1422 u64 shadow_layout_ = 0;
1424 u32 shadow_tile_passes_left_ = 0;
1425 bool shadow_pool_uploaded_ = false;
1426 u32 shadow_frame_tiles_ = 0, shadow_frame_draws_ = 0;
1427 u32 shadow_squares_kept_total_ = 0, shadow_squares_drawn_total_ = 0;
1429 void drawShadowView(usize vi);
1431 void recordShadowTiles(bool all);
1433 void executeShadowTile(usize vi);
1437 std::vector<BufferHandle> shadow_frame_ubos_;
1440 ShadowAtlas shadow_atlas_{kShadowAtlasSize, kShadowCellSize};
1441 u32 shadow_atlas_size_ = kShadowAtlasSize;
1442 u32 shadow_cell_size_ = kShadowCellSize;
1443 u32 shadow_cascades_ = MAX_SHADOW_CASCADES;
1444 f32 shadow_distance_ = 0.0f;
1445 u32 shadow_2d_soft_samples_ = 16;
1446 ShadowPlanReport shadow_plan_;
1447 ShadowPlanReport previous_shadow_plan_;
1448 LightCapReport light_cap_;
1449 ViewLighting view_lighting_;
1450 bool scene_sky_available_ = false;
1452 u32 shadow_texture_id_ = 0;
1454 u32 environment_texture_id_ = 0;
1456 bool draw_sky_ = false;
1458 u32 sky_texture_id_ = 0;
1460 u32 sky_programs_[2] = {};
1461 bool sky_compiled_[2] = {};
1463 void collectSky(RenderCollectContext& ctx);
1464
1466 const std::unordered_set<u32>* screen_domain_ = nullptr;
1467 const std::unordered_map<u32, i32>* ui_tree_layers_ = nullptr;
1468 bool overlay_active_ = false;
1469 bool retained_text_collected_ = false;
1473 struct OverlayHold {
1474 explicit OverlayHold(GfxDevice& device) : pool(device) {}
1475 TransientBufferPool pool;
1476 DrawList list;
1477 };
1478 std::unique_ptr<OverlayHold> overlay_hold_;
1479 bool overlay_swapped_ = false;
1481 bool overlay_kept_ = false;
1483 bool overlay_reset_pending_ = false;
1485 bool overlay_valid_ = false;
1486 u64 overlay_key_ = 0;
1487 u32 overlay_tick_ = 0;
1488 double overlay_journal_ = -1;
1489 u64 overlay_pending_key_ = 0;
1490 u32 overlay_pending_tick_ = 0;
1491 double overlay_pending_journal_ = -1;
1493 u64 overlay_watched_ = 0;
1494 u32 overlay_reader_ = 0;
1496 u32 overlay_passes_ = 0;
1498 u64 overlay_content_ = 0;
1499 bool overlay_would_keep_ = false;
1500 u32 overlay_stale_ = 0;
1501 bool warned_overlay_stale_ = false;
1502 u32 overlay_kept_total_ = 0;
1503 u32 overlay_why_ = 0;
1504 void swapOverlayIn();
1505 void swapOverlayOut();
1506 void resetOverlayContents();
1507 u64 overlayInputs(ecs::Registry& registry, bool whole) const;
1508 bool overlayRegistryMoved(ecs::Registry& registry);
1509
1513 struct OverlaySegment {
1514 u32 root = 0;
1515 std::unique_ptr<OverlayHold> hold;
1516 bool valid = false;
1517 bool dirty = true;
1518 bool wouldKeep = false;
1519 u64 domain = 0;
1520 u64 content = 0;
1521 };
1522 const std::vector<u32>* screen_roots_ = nullptr;
1523 const std::vector<u32>* screen_root_by_index_ = nullptr;
1524 std::vector<OverlaySegment> segments_;
1526 bool overlay_segmented_ = false;
1529 bool segments_trusted_ = false;
1530 u64 segments_key_ = 0;
1531 u32 segments_tick_ = 0;
1532 double segments_journal_ = -1;
1534 bool segments_refused_ = false;
1535 u64 segments_refused_roots_ = 0;
1536 u32 overlay_segments_rebuilt_ = 0;
1538 u32 overlay_rebuilt_last_ = 0;
1539 ecs::Registry* overlay_registry_ = nullptr;
1540 u32 screenRootAt(u32 entity) const;
1541 u64 screenRootsHash() const;
1542 bool keepSegments(ecs::Registry& registry);
1543 void segmentIn(OverlaySegment& segment);
1544 void segmentOut(OverlaySegment& segment);
1545 void collectScreenOverlayInto(ecs::Registry& registry, u32 onlyRoot);
1546 void endSegmentedOverlay(RenderTargetManager::Handle target);
1547 glm::mat4 overlay_projection_{1.0f};
1548 i32 overlay_vp_x_ = 0, overlay_vp_y_ = 0;
1549 u32 overlay_vp_w_ = 0, overlay_vp_h_ = 0;
1550 u32 overlay_effect_ = 0;
1551 TextureHandle overlay_grab_ = TextureHandle::Invalid;
1552 Unique<Framebuffer> overlay_backdrop_;
1553 u32 overlay_grab_w_ = 0, overlay_grab_h_ = 0;
1554 bool grabOverlayBackdrop(FramebufferHandle source);
1555 void executeOverlayGraph();
1556 void releaseOverlayBackdrop();
1557
1559 std::vector<ResolvedMask> sprite_mask_scratch_;
1560 std::vector<Entity> mask_entities_scratch_;
1561 // processMasks scratch, reused across cameras/frames.
1562 std::vector<Entity> mask_scissor_scratch_;
1563 std::vector<Entity> mask_stencil_scratch_;
1564 std::vector<Entity> mask_root_scratch_;
1565 std::vector<std::pair<Entity, ScissorRect>> mask_scissor_walk_scratch_;
1566 std::vector<std::pair<Entity, i32>> mask_stencil_walk_scratch_;
1567 std::unordered_set<u32> mask_set_scratch_;
1568 std::unordered_set<u32> stencil_set_scratch_;
1569};
1570
1571} // namespace esengine
One frame's draw calls as the device received them, for the frame debugger.
Abstract graphics device interface.
Per-frame 2D lighting constants — the third tier of the engine's constant-buffer layering (after per-...
Which lights reached the frame, and who was turned away.
Post-processing effects pipeline.
Central ECS registry for entity and component management.
Rendering context containing all renderer state.
Full-screen passes as a declared graph: what each one reads, what it writes, and at what size — the g...
Central resource management system.
Glyph geometry the engine keeps between frames, and the clipping of it against a view.
Who owns which square of the one shadow texture.
What each caster asked the shadow atlas for, and what it got.
Skinned meshes posed once a frame by a compute shader, into vertices every pass then draws as they ar...
Which SpriteMask, if any, cuts a sprite — the rule, apart from the frame.
The render targets a frame borrows from, keyed by shape — owned by the frame, not by any one graph th...
GPU texture abstraction for 2D images.
Core type definitions and utilities for ESEngine.
Abstract graphics device interface.
Definition GfxDevice.hpp:75
void end(GfxDevice &device)
void poll(GfxDevice &device)
void begin(GfxDevice &device)
Immediate mode 2D drawing API.
Post-processing effects pipeline.
void wantTextureSide(u32 texture, f32 side)
Note that a view drew a mesh with texture texture (a resource handle) where it needs side texels acro...
void setScreenDomain(const std::unordered_set< u32 > *domain)
The screen's entities (UISystem::screenDomain), borrowed for the frame. Null partitions nothing — eve...
void setPlanarQuality(f32 scale, u32 maxSize, f32 updatesPerSecond, bool capAuthored)
void setEntityStencilMask(u32 entity, i32 refValue, bool hierarchical=false)
void renderToTarget(ecs::Registry &registry, const glm::mat4 &viewProjection, u32 w, u32 h)
void submitScreenOverlay(ecs::Registry &registry)
Collects the screen's renderables. Between this and endScreenOverlay a host may submit its own screen...
ShadingMode viewShading(u32 view) const
The mode view asked for; Shaded when it never did.
const u8 * getPreviewPixels() const
SkinCache * skinCache()
u32 skeletalPreviewWidth(SkeletalPreviewId id) const
void endFrame()
Closes the FRAME, once, after every camera and every overlay.
void setDepthLayers(u32 mask)
void setColorSpace(bool linear)
Switch the frame to linear-light rendering (project colorSpace).
void setStage(RenderStage stage)
bool probesPerPixel() const
void processMasks(ecs::Registry &registry, i32 vpX, i32 vpY, i32 vpW, i32 vpH)
void requestProbeCapture(const glm::vec3 &position, u32 face)
Capture the scene around position (world) into six face-pixel faces, one a frame, and read them back:...
void setPresentedOverlayDraw(ImmediateDraw *draw)
bool projectMaterialBake(u32 ticket, u32 material, u32 target, u32 instances)
void addPlugin(std::unique_ptr< RenderTypePlugin > plugin)
const ImpostorAtlas * impostorAtlas(Entity entity) const
void setUITreeLayers(const std::unordered_map< u32, i32 > *layers)
The layers of what a Canvas holds with no uiOrder, borrowed for the frame.
void setSkyEnvironment(resource::EnvironmentHandle environment)
The environment the sky lights the scene with (the Sky Atmosphere's, worked out by the SDK as the sky...
void submitTileQuad(const glm::vec2 &position, const glm::vec2 &size, const glm::vec2 &uvOffset, const glm::vec2 &uvScale, const glm::vec4 &color, u32 textureId, Entity entity, i32 layer, f32 depth)
SkeletalPreviewId createSkeletalPreview(u32 w, u32 h)
std::string planarStatus(u32 view, u32 entity) const
void setEntityClipRect(u32 entity, i32 x, i32 y, i32 w, i32 h)
void setShadowBudget(u32 atlasSize, u32 cellSize, u32 cascades)
u32 stagedVertexBytes(LayoutId layout) const
The vertex bytes staged for layout since the last begin().
void setPlanarTime(f32 seconds)
void setOcclusionGridSize(u32 size)
FrameCapture & frameCapture()
void setImpostorAtlas(Entity entity, u32 texture, u32 frames)
Hand entity the atlas its Impostor draws from; a zero texture takes it away.
void setViewShading(u32 view, ShadingMode mode)
Shade view's meshes as mode says instead of as authored.
void setScreenRoots(const std::vector< u32 > *roots, const std::vector< u32 > *rootByIndex)
The screen's root Canvases in drawing order and, by entity index, the root each screen entity draws u...
RenderPrewarmResult prewarmDocument(const MeshDocumentRecord *rows, u32 count)
The same readiness, from a prepared cell's own description — no entity of it need exist.
bool inFrame() const
Whether begin() opened a frame; false when it refused one for a lost device.
CasterCacheStats casterCacheStats() const
void endScreenOverlay(RenderTargetManager::Handle target)
const LightCapReport & lightCap() const
Which lights the cap turned away last frame, and why.
u32 getPreviewHeight() const
void setDepthPrepass(bool on)
void begin(const glm::mat4 &view_projection, RenderTargetManager::Handle target=0)
const ShadowPlanReport & shadowPlan() const
What each caster asked the shadow atlas for last frame, and what it got.
void setProbeVolumeOverride(u32 entity, resource::ProbeVolumeHandle grid)
The grid a volume reads instead of its own probes (a capture's), or an invalid handle to stop.
void drawOverScreen(i32 vpX, i32 vpY, u32 vpW, u32 vpH, RenderTargetManager::Handle target)
Draws the immediate geometry collected since the screen overlay over everything the frame shows,...
bool retainedTextCollected() const
bool lightingDirect() const
const std::vector< u8 > & probeCapturePixels() const
The six faces side by side, +X -X +Y -Y +Z -Z, RGBM over 8 in RGBA8 (alpha 0 = nothing drawn),...
void init(u32 width, u32 height)
void setViewSelection(u32 view, const u32 *ids, u32 count)
The editor's selection in view, outlined on screen (by Entity::id()); empty clears it.
void setTargetPoolIdleBudget(u64 bytes)
bool keepScreenOverlay(ecs::Registry &registry, bool hostStill)
Asked after beginScreenOverlay and the layers: true, and the host submits nothing and endScreenOverla...
void setCullingMask(u32 mask)
Layers the camera about to be collected renders — see DrawList::setCullingMask.
RenderFrame & operator=(const RenderFrame &)=delete
u32 skeletalPreviewHeight(SkeletalPreviewId id) const
u32 getSnapshotWidth() const
void setLodPreview(u32 view, Entity entity, u8 level)
Show level for entity in view instead of the level that view chose; lod::kNoPreview goes back to choo...
u32 displayProgram(u32 program)
u32 getPreviewWidth() const
void setTreeSortLayers(u32 mask)
Layers (bits 0..31) that paint in hierarchy order within the layer — see DrawList::setTreeMask.
void replayToDrawCall(i32 drawIndex)
void setViewSkinWeights(u32 view, Entity entity, u32 joint)
Colour entity in view by how much joint moves each of its vertices.
const u8 * skeletalPreviewPixels(SkeletalPreviewId id) const
std::string takeTextureWants()
What each texture was asked for since the last take, as handle:side pairs joined by commas; the recor...
bool sceneSkyAvailable() const
Whether the frame found a scene environment it could draw as the background.
void submitRetainedText(ecs::Registry &registry, bool screen, const f32 *projection, u32 onlyRoot=0)
Every retained label laid out for one domain into the open list, culled against projection (world,...
void setLightingDirect(bool on)
f32 lodDistanceScale() const
u32 queueMaterialBake(u32 material, u32 shader, u32 target, u32 x, u32 y, u32 w, u32 h, const glm::vec4 &a, const glm::vec4 &b)
Draws material material through shader (a PostProcess-domain shader) into the rect (x,...
u32 getSnapshotSize() const
void setProbesPerPixel(bool on)
Whether a mesh without lightmap UVs reads its probe volume per pixel (the grid through the frame's br...
void cancelMaterialBakesFor(u32 target)
void beginFrame()
Opens the FRAME, once, before any of its cameras.
bool lodInspect(u32 view, Entity entity, u8 &outLevel, u8 &outUnbiased, u8 &outLevels, f32 &outSize) const
void setRetainedTextCollected(bool collected)
The retained labels drawn by the frame's own collects (the camera's world labels, the overlay's scree...
void setYSortLayers(u32 mask)
Layers (bits 0..31) that sort by world Y within the layer — see DrawList::setYSortMask.
u32 getSnapshotHeight() const
RenderFrame(const RenderFrame &)=delete
void setLodDistanceScale(f32 scale)
bool clusterInspect(Entity entity, u32 &outTriangles, u32 &outClusters) const
The LOD decision view last made about entity: the level, what the bare thresholds asked for,...
void setViewId(u32 view)
Names the view the camera about to be collected looks from, which is what its LOD levels are remember...
bool submitSkeletalPreviewBatch(SkeletalPreviewId id, const f32 *vertices, i32 vertexCount, const u16 *indices, i32 indexCount, u32 textureId, i32 blendMode, const f32 *transform16, i32 layer, f32 depth, u32 materialId, bool premultipliedColor=false)
RenderTargetManager & targetManager()
void collectAll(ecs::Registry &registry, bool sceneGBuffer=true)
RetainedTextStore & retainedText()
The glyph quads of every label the text system laid out and handed over once, which the engine submit...
const PlanarConstants & planarConstants() const
void submitSkeletalBatch(const f32 *vertices, i32 vertexCount, const u16 *indices, i32 indexCount, u32 textureId, i32 blendMode, const f32 *transform16, Entity entity, i32 layer, f32 depth, u32 materialId=0, bool premultipliedColor=false, f32 treeAlpha=1.0f, u32 cullBit=0)
Batch vertices posed by a skeletal runtime, drawn as one entity's geometry.
u32 batchProgram(BatchVariant variant)
u32 planarTextureFor(Entity entity) const
const ViewLighting & viewLighting() const
i32 materialBakeState(u32 ticket)
A bake's state: 0 waiting, 1 drawn, -1 not drawable (no target, shader or material,...
usize lodPreviewCount() const
How many (view, entity) pairs are held up for inspection.
void resize(u32 width, u32 height)
i32 pollProbeCapture()
0 = not yet, 1 = ready (probeCapturePixels), 2 = none asked for or it failed. Between frames only.
static constexpr u32 STAGE_COUNT
f32 viewHeightPx() const
The pixel height of the view being collected: what a texel is held to.
void setShadow2DSoftSamples(u32 samples)
How many samples across a light source a soft 2D shadow is drawn with: the quality level's say on the...
bool screenOverlayOpen() const
Whether the overlay is open — what routes a host's submissions.
void submitTextBatch(const f32 *vertices, i32 vertexCount, const u16 *indices, i32 indexCount, u32 textureId, const f32 *transform16, Entity entity, i32 layer, f32 depth, TextGlyphMode mode, u32 cullBit=0)
RenderFrame(GfxDevice &device, RenderContext &context, resource::ResourceManager &resource_manager)
void beginScreenOverlay(const glm::mat4 &projection, i32 vpX, i32 vpY, u32 vpW, u32 vpH)
Opens the overlay: projection maps the layout domain onto the pixel rect vpX/vpY/vpW/vpH of the surfa...
bool renderSkeletalPreview(SkeletalPreviewId id, const glm::mat4 &viewProjection)
bool uiTreeHolds(Entity entity) const
Whether a Canvas holds entity with no uiOrder of its own (an emitter, a skeleton, a plain Sprite).
const Stats & stats() const
void destroySkeletalPreview(SkeletalPreviewId id)
bool setQualityValue(const std::string &name, f32 value)
RenderStage getStage() const
bool snapshotMatchesCapture() const
RenderPrewarmResult prewarmPrograms(ecs::Registry &registry, const Entity *entities, u32 count)
Make ready the programs entities will need, drawing nothing.
u32 skeletalPreviewSize(SkeletalPreviewId id) const
void setEntityStencilTest(u32 entity, i32 refValue, bool hierarchical=false)
void setScreenOverlayEffect(u32 material)
void setShadowDistance(f32 distance)
const u8 * getSnapshotPixels() const
void setWorldUnitsPerMeter(f32 units)
How many world units make a metre (the project's setting): what an inverse-square light measures in.
i32 pollSkeletalPreview(SkeletalPreviewId id)
bool visibleToCamera(i32 layer, const glm::vec3 &center, const glm::vec3 &halfExtents) const
Whether the camera being rendered right now would draw something of layer at these world bounds.
void setProbeVolumeReflection(u32 entity, u32 environment, u32 slot)
The volume on entity reflects column slot of environment (an atlas built from captures,...
void setViewLighting(const ViewLighting &lighting)
The retained geometry of every label, by entity. Ordered: a frame submits in entity order,...
Central container for all entities and components.
Definition Registry.hpp:73
Central manager for GPU resources.
Handle< esengine::Shader > ShaderHandle
Handle to a shader resource.
Definition Handle.hpp:214
Handle< esengine::Environment > EnvironmentHandle
Handle to a baked environment (irradiance + prefiltered reflection).
Definition Handle.hpp:229
Handle< esengine::ProbeVolume > ProbeVolumeHandle
Handle to a grid of baked irradiance.
Definition Handle.hpp:232
constexpr ResourceId kNoResource
FramebufferHandle
Handle 0 is the default framebuffer (backbuffer); it cannot be created or deleted.
Definition GfxEnums.hpp:41
std::int32_t i32
Signed 32-bit integer.
Definition Types.hpp:54
std::uint64_t u64
Unsigned 64-bit integer.
Definition Types.hpp:47
constexpr u32 kShadowCellSize
std::size_t usize
Size type for indexing and sizes.
Definition Types.hpp:64
constexpr Entity INVALID_ENTITY
Invalid entity sentinel value.
Definition Types.hpp:174
constexpr u32 kShadowAtlasSize
std::unique_ptr< T > Unique
Unique ownership smart pointer.
Definition Types.hpp:75
std::uint32_t u32
Unsigned 32-bit integer.
Definition Types.hpp:45
std::uint8_t u8
Unsigned 8-bit integer.
Definition Types.hpp:41
ShadingMode
What a mesh is drawn WITH in a view, whatever its own material says.
std::uint16_t u16
Unsigned 16-bit integer.
Definition Types.hpp:43
LayoutId
Identifies a transient vertex stream / vertex format. Each layout has its own VBO+EBO+VAO in Transien...
Definition GfxEnums.hpp:88
static EstellaContext & ctx()
constexpr u32 kShadowCascadeCells
ReadbackHandle
An in-flight framebuffer readback (GfxDevice::requestReadback).
Definition GfxEnums.hpp:43
float f32
32-bit floating point
Definition Types.hpp:59
ShadowShape
The shape a light's map has to cover — the one thing a shadow pass differs by.
constexpr u32 MAX_SHADOW_CASCADES
Slices one directional shadow map is split into, each covering a stretch of the view — so the near on...
Entity identifier with packed index + generation.
Definition Types.hpp:135
constexpr u32 id() const
Returns the raw packed value for FFI serialization.
Definition Types.hpp:159
What the frame's light cap came to.
Definition LightPlan.hpp:57
What a renderable's program key is made of, with no say in where the facts came from — a live entity'...
An impostor's pictures: the atlas texture and how many frames along its side.
The frame's main-pass load-op: which attachments to clear, the color, and an optional region (w == 0 ...
Skeletal geometry a caller holds until it renders, owning its bytes.
One offscreen render's resources, correct only together.
RenderTargetManager::Handle target
u32 gpu_draws
Every draw the GPU was asked for in the frame, every pass included; draw_calls is the scene's and the...
u32 lightsSpared
Loop lights the lit quads did not have to work out (RenderCollectContext::lightsSpared).
u32 occluded
Of culled, how many an occluder refused rather than the frustum.
u32 waiting_for_program
Scene draws left out of the frame because a program they use was still compiling in the background.
The editor view's own lighting, in place of the scene's.
bool showSky
Draw the scene's environment as the background while studio-lit.
f32 skyIntensity
Scales the neutral sky's light; the scene's own Ambient is not consulted.
f32 rotation
Degrees about +Y that the key and fill turn together.
What readying a set of renderables' programs found. Counts, not JSON: this crosses no boundary and pa...
The frame's whole shadow allocation, as numbers something outside it can check.
A 2D light contributing to Lit-shaded materials.
Definition Light.hpp:54