Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
SkinCache.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
18#pragma once
19
20#include "../../core/Types.hpp"
21#include "../../ecs/Entity.hpp"
22#include "../../math/Math.hpp"
23#include "../rhi/GfxEnums.hpp"
24
25#include <memory>
26#include <unordered_map>
27#include <vector>
28
29namespace esengine {
30
31class GfxDevice;
32class Mesh;
33
35enum class SkinCacheBehavior : u8 {
40};
41
43enum class SkinCacheUsage : u8 { Auto = 0, Disabled = 1, Enabled = 2 };
44
52
53class SkinCache {
54public:
55 explicit SkinCache(GfxDevice& device);
56 ~SkinCache();
57 SkinCache(const SkinCache&) = delete;
58 SkinCache& operator=(const SkinCache&) = delete;
59
60 void setSettings(const SkinCacheSettings& settings) { settings_ = settings; }
61 const SkinCacheSettings& settings() const { return settings_; }
62
64 bool active() const;
65
67 bool wants(SkinCacheUsage usage) const;
68
70 void beginFrame(u64 frame);
71
77 BufferHandle schedule(Entity entity, const Mesh& mesh, const glm::mat4* pose, u32 joints);
78
80 BufferHandle bufferFor(Entity entity) const;
81
83 bool hasWork() const { return scheduled_ > 0; }
84
86 void run();
87
88 u64 bytesUsed() const { return bytes_; }
89 u32 entryCount() const { return static_cast<u32>(entries_.size()); }
91 u32 refusedThisFrame() const { return refused_; }
93 u32 scheduledThisFrame() const { return scheduled_; }
95 void noteDraw() { ++drawn_; }
96 u32 drawsThisFrame() const { return drawn_; }
97
98private:
99 struct Entry {
100 u64 meshRevision = 0;
101 std::shared_ptr<const std::vector<u8>> source;
102 BufferHandle sourceBuffer = BufferHandle::Invalid;
108 u32 poseCapacity = 0;
109 u32 vertexCount = 0;
110 u64 bytes = 0;
111 u64 lastFrame = 0;
112 bool scheduled = false;
113 std::vector<glm::mat4> pendingPose;
114 };
115
116 bool build(Entry& entry, const Mesh& mesh);
117 void release(Entry& entry);
118
119 GfxDevice& device_;
120 SkinCacheSettings settings_;
121 std::unordered_map<u32, Entry> entries_;
123 bool kernelFailed_ = false;
124 u64 frame_ = 0;
125 u64 bytes_ = 0;
126 u32 scheduled_ = 0;
127 u32 refused_ = 0;
128 u32 drawn_ = 0;
129};
130
131} // namespace esengine
Entity utilities for the ECS system.
Backend-agnostic graphics enumerations.
Math utilities and GLM configuration for ESEngine.
Core type definitions and utilities for ESEngine.
Abstract graphics device interface.
Definition GfxDevice.hpp:75
Buffers, the layout that describes them, and the bounds culling reads.
Definition Mesh.hpp:85
u32 drawsThisFrame() const
Definition SkinCache.hpp:96
SkinCache & operator=(const SkinCache &)=delete
void setSettings(const SkinCacheSettings &settings)
Definition SkinCache.hpp:60
bool hasWork() const
Definition SkinCache.hpp:83
u32 refusedThisFrame() const
Definition SkinCache.hpp:91
SkinCache(const SkinCache &)=delete
bool active() const
bool wants(SkinCacheUsage usage) const
BufferHandle bufferFor(Entity entity) const
u32 entryCount() const
Definition SkinCache.hpp:89
u64 bytesUsed() const
Definition SkinCache.hpp:88
void beginFrame(u64 frame)
const SkinCacheSettings & settings() const
Definition SkinCache.hpp:61
SkinCache(GfxDevice &device)
Definition SkinCache.cpp:94
BufferHandle schedule(Entity entity, const Mesh &mesh, const glm::mat4 *pose, u32 joints)
Schedules entity's skin for this frame, posed by pose (one matrix a joint: joint world times inverse ...
u32 scheduledThisFrame() const
Definition SkinCache.hpp:93
std::uint64_t u64
Unsigned 64-bit integer.
Definition Types.hpp:47
ComputeHandle
A compute program (GfxDevice::createCompute); only a device that supportsCompute() issues one.
Definition GfxEnums.hpp:39
std::uint32_t u32
Unsigned 32-bit integer.
Definition Types.hpp:45
std::uint8_t u8
Unsigned 8-bit integer.
Definition Types.hpp:41
SkinCacheUsage
A mesh's own word on the cache (MeshSkin::skinCache).
Definition SkinCache.hpp:43
SkinCacheBehavior
Which skinned meshes go through the cache when their own MeshSkin says Auto.
Definition SkinCache.hpp:35
float f32
32-bit floating point
Definition Types.hpp:59
Entity identifier with packed index + generation.
Definition Types.hpp:135
The project's skin cache settings.
Definition SkinCache.hpp:46
SkinCacheBehavior behavior
Definition SkinCache.hpp:48