Added screen space cache

This commit is contained in:
Yousef Khadadeh 2026-01-21 13:11:01 +03:00
parent 5143557e78
commit fe4716765c
3 changed files with 99 additions and 3 deletions

View file

@ -31,10 +31,12 @@ class DrawingProgramCache {
void node_loop_erase_if_components(const std::shared_ptr<DrawingProgramCacheBVHNode>& bvhNode, std::function<bool(CanvasComponentContainer::ObjInfo* comp)> f);
void node_loop_components(const std::shared_ptr<DrawingProgramCacheBVHNode>& bvhNode, std::function<void(CanvasComponentContainer::ObjInfo* comp)> f);
bool should_rebuild() const;
void update_and_draw_cached_canvas(SkCanvas* canvas, const DrawData& drawData);
void draw_components_to_canvas(SkCanvas* canvas, const DrawData& drawData, const std::optional<SCollision::AABB<WorldScalar>>& drawBounds);
bool unsorted_components_exist() const;
void invalidate_cache_at_aabb(const SCollision::AABB<WorldScalar>& aabb);
void refresh_all_draw_cache(const DrawData& drawData);
void set_clear_window_cache();
CanvasComponentContainer::ObjInfo* get_front_object_colliding_with_in_editing_layer(const SCollision::ColliderCollection<float>& cC);
~DrawingProgramCache();
private:
@ -46,6 +48,19 @@ class DrawingProgramCache {
};
static std::unordered_map<std::shared_ptr<DrawingProgramCacheBVHNode>, NodeCache> nodeCacheMap;
struct WindowCache {
sk_sp<SkSurface> surface;
DrawingProgramCache* attachedDrawingProgramCache = nullptr;
std::optional<SCollision::AABB<WorldScalar>> invalidBounds;
Vector2i size = {0, 0};
CoordSpaceHelper coords;
};
static WindowCache windowCache;
void refresh_all_draw_cache(const DrawData& drawData);
void update_window_cache_invalid_bounds(const DrawData& drawData);
void window_cache_complete_refresh(const DrawData& drawData);
void allocate_window_cache_area();
void internal_build(std::vector<CanvasComponentContainer::ObjInfo*> componentsToBuild, const std::unordered_set<CanvasComponentContainer::ObjInfo*>& objsToNotInclude);
void build_bvh_node(const std::shared_ptr<DrawingProgramCacheBVHNode>& bvhNode, const std::vector<CanvasComponentContainer::ObjInfo*>& components);
void build_bvh_node_coords_and_resolution(DrawingProgramCacheBVHNode& node);