From a7c4d3bc08cb57ebe5654d942904be7bd95382bf Mon Sep 17 00:00:00 2001 From: clayjohn Date: Fri, 19 Jan 2024 17:21:55 -0800 Subject: [PATCH] Add basic multimesh data needed for headless export to the Dummy rendering server (cherry picked from commit ed2b3d358d3883b98f741cbfc1ca3d7aa4fcbb7b) --- .../rendering/dummy/storage/mesh_storage.cpp | 30 +++++++++++++++++++ .../rendering/dummy/storage/mesh_storage.h | 16 ++++++---- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/servers/rendering/dummy/storage/mesh_storage.cpp b/servers/rendering/dummy/storage/mesh_storage.cpp index ab27711d6e1..0b7ade17628 100644 --- a/servers/rendering/dummy/storage/mesh_storage.cpp +++ b/servers/rendering/dummy/storage/mesh_storage.cpp @@ -63,3 +63,33 @@ void MeshStorage::mesh_clear(RID p_mesh) { m->surfaces.clear(); } + +RID MeshStorage::multimesh_allocate() { + return multimesh_owner.allocate_rid(); +} + +void MeshStorage::multimesh_initialize(RID p_rid) { + multimesh_owner.initialize_rid(p_rid, DummyMultiMesh()); +} + +void MeshStorage::multimesh_free(RID p_rid) { + DummyMultiMesh *multimesh = multimesh_owner.get_or_null(p_rid); + ERR_FAIL_NULL(multimesh); + + multimesh_owner.free(p_rid); +} + +void MeshStorage::multimesh_set_buffer(RID p_multimesh, const Vector &p_buffer) { + DummyMultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh); + ERR_FAIL_NULL(multimesh); + multimesh->buffer.resize(p_buffer.size()); + float *cache_data = multimesh->buffer.ptrw(); + memcpy(cache_data, p_buffer.ptr(), p_buffer.size() * sizeof(float)); +} + +Vector MeshStorage::multimesh_get_buffer(RID p_multimesh) const { + DummyMultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh); + ERR_FAIL_NULL_V(multimesh, Vector()); + + return multimesh->buffer; +} diff --git a/servers/rendering/dummy/storage/mesh_storage.h b/servers/rendering/dummy/storage/mesh_storage.h index d287a1c3874..a7351655bd7 100644 --- a/servers/rendering/dummy/storage/mesh_storage.h +++ b/servers/rendering/dummy/storage/mesh_storage.h @@ -50,6 +50,12 @@ private: mutable RID_Owner mesh_owner; + struct DummyMultiMesh { + PackedFloat32Array buffer; + }; + + mutable RID_Owner multimesh_owner; + public: static MeshStorage *get_singleton() { return singleton; } @@ -132,9 +138,9 @@ public: /* MULTIMESH API */ - virtual RID multimesh_allocate() override { return RID(); } - virtual void multimesh_initialize(RID p_rid) override {} - virtual void multimesh_free(RID p_rid) override {} + virtual RID multimesh_allocate() override; + virtual void multimesh_initialize(RID p_rid) override; + virtual void multimesh_free(RID p_rid) override; virtual void multimesh_allocate_data(RID p_multimesh, int p_instances, RS::MultimeshTransformFormat p_transform_format, bool p_use_colors = false, bool p_use_custom_data = false) override {} virtual int multimesh_get_instance_count(RID p_multimesh) const override { return 0; } @@ -152,8 +158,8 @@ public: virtual Transform2D multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const override { return Transform2D(); } virtual Color multimesh_instance_get_color(RID p_multimesh, int p_index) const override { return Color(); } virtual Color multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const override { return Color(); } - virtual void multimesh_set_buffer(RID p_multimesh, const Vector &p_buffer) override {} - virtual Vector multimesh_get_buffer(RID p_multimesh) const override { return Vector(); } + virtual void multimesh_set_buffer(RID p_multimesh, const Vector &p_buffer) override; + virtual Vector multimesh_get_buffer(RID p_multimesh) const override; virtual void multimesh_set_visible_instances(RID p_multimesh, int p_visible) override {} virtual int multimesh_get_visible_instances(RID p_multimesh) const override { return 0; }