1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "render_data_store_morph.h"
17
18 #include <cstdint>
19
20 #include <3d/render/intf_render_data_store_morph.h>
21 #include <base/containers/array_view.h>
22 #include <render/resource_handle.h>
23
24 CORE3D_BEGIN_NAMESPACE()
25 using namespace BASE_NS;
26 using namespace RENDER_NS;
27
RenderDataStoreMorph(const string_view name)28 RenderDataStoreMorph::RenderDataStoreMorph(const string_view name) : name_(name) {}
29
Init(const IRenderDataStoreMorph::ReserveSize & reserveSize)30 void RenderDataStoreMorph::Init(const IRenderDataStoreMorph::ReserveSize& reserveSize)
31 {
32 submeshes_.reserve(reserveSize.submeshCount);
33 }
34
PostRender()35 void RenderDataStoreMorph::PostRender()
36 {
37 Clear();
38 }
39
Clear()40 void RenderDataStoreMorph::Clear()
41 {
42 submeshes_.clear();
43 }
44
Ref()45 void RenderDataStoreMorph::Ref()
46 {
47 refcnt_.fetch_add(1, std::memory_order_relaxed);
48 }
49
Unref()50 void RenderDataStoreMorph::Unref()
51 {
52 if (std::atomic_fetch_sub_explicit(&refcnt_, 1, std::memory_order_release) == 1) {
53 std::atomic_thread_fence(std::memory_order_acquire);
54 delete this;
55 }
56 }
57
GetRefCount()58 int32_t RenderDataStoreMorph::GetRefCount()
59 {
60 return refcnt_;
61 }
62
AddSubmesh(const RenderDataMorph::Submesh & submesh)63 void RenderDataStoreMorph::AddSubmesh(const RenderDataMorph::Submesh& submesh)
64 {
65 submeshes_.push_back(submesh);
66 }
67
GetSubmeshes() const68 array_view<const RenderDataMorph::Submesh> RenderDataStoreMorph::GetSubmeshes() const
69 {
70 return submeshes_;
71 }
72
73 // for plugin / factory interface
Create(RENDER_NS::IRenderContext &,char const * name)74 refcnt_ptr<IRenderDataStore> RenderDataStoreMorph::Create(RENDER_NS::IRenderContext&, char const* name)
75 {
76 return refcnt_ptr<IRenderDataStore>(new RenderDataStoreMorph(name));
77 }
78 CORE3D_END_NAMESPACE()
79