BVH draw cache working
This commit is contained in:
parent
1e51bf660f
commit
caea747f1e
12 changed files with 223 additions and 39 deletions
|
|
@ -3,26 +3,37 @@
|
|||
#include "../CollabList.hpp"
|
||||
#include "../DrawComponents/DrawComponent.hpp"
|
||||
#include <include/core/SkSurface.h>
|
||||
#include <unordered_set>
|
||||
|
||||
class DrawingProgram;
|
||||
|
||||
class DrawingProgramCache {
|
||||
public:
|
||||
typedef CollabList<std::shared_ptr<DrawComponent>, ServerClientID> CollabListType;
|
||||
void update(const std::vector<CollabListType::ObjectInfoPtr>& components);
|
||||
DrawingProgramCache(DrawingProgram& initDrawP);
|
||||
|
||||
void update();
|
||||
void erase_component(const CollabListType::ObjectInfoPtr& c);
|
||||
void add_component(const CollabListType::ObjectInfoPtr& c);
|
||||
void refresh_all_draw_cache(SkCanvas* canvas, const DrawData& drawData);
|
||||
|
||||
struct BVHNode {
|
||||
SCollision::AABB<WorldScalar> bounds;
|
||||
std::vector<CollabListType::ObjectInfoPtr> components;
|
||||
std::vector<BVHNode> children;
|
||||
|
||||
CoordSpaceHelper coords;
|
||||
Vector2i resolution;
|
||||
struct DrawCacheData {
|
||||
uint64_t lastDrawnComponentPlacement;
|
||||
sk_sp<SkSurface> surface;
|
||||
std::chrono::steady_clock::time_point lastRenderTime;
|
||||
};
|
||||
|
||||
std::optional<DrawCacheData> drawCache;
|
||||
};
|
||||
|
||||
std::vector<BVHNode*> nodesWithCachedSurfaces;
|
||||
std::unordered_set<BVHNode*> nodesWithCachedSurfaces;
|
||||
|
||||
void traverse_bvh_run_function(const SCollision::AABB<WorldScalar>& aabb, std::function<bool(BVHNode* node, const std::vector<CollabListType::ObjectInfoPtr>& components)> f);
|
||||
|
||||
|
|
@ -31,6 +42,8 @@ class DrawingProgramCache {
|
|||
|
||||
void invalidate_cache_before_pos(uint64_t placementToInvalidateAt);
|
||||
private:
|
||||
void build_bvh_node_coords_and_resolution(BVHNode& node);
|
||||
void refresh_draw_cache(BVHNode& bvhNode, const DrawData& drawData);
|
||||
|
||||
void build(std::vector<CollabListType::ObjectInfoPtr> components);
|
||||
|
||||
|
|
@ -40,4 +53,5 @@ class DrawingProgramCache {
|
|||
void build_bvh_node(BVHNode& node, std::vector<CollabListType::ObjectInfoPtr> components);
|
||||
BVHNode bvhRoot;
|
||||
std::vector<CollabListType::ObjectInfoPtr> unsortedComponents;
|
||||
DrawingProgram& drawP;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue