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 #ifndef RENDER_DATA_STORE_DEFAULT_DOTFIELD_H 17 #define RENDER_DATA_STORE_DEFAULT_DOTFIELD_H 18 19 #include <atomic> 20 #include <cstdint> 21 22 #include <base/containers/array_view.h> 23 #include <base/containers/string.h> 24 #include <base/containers/string_view.h> 25 #include <base/containers/vector.h> 26 #include <base/util/uid.h> 27 #include <core/namespace.h> 28 #include <render/datastore/intf_render_data_store.h> 29 #include <render/intf_render_context.h> 30 #include <render/resource_handle.h> 31 32 #include "dotfield/render/intf_render_data_store_default_dotfield.h" 33 34 namespace RENDER_NS { 35 class IRenderContext; 36 class IGpuResourceManager; 37 class IShaderManager; 38 class IRenderDataStoreManager; 39 40 } // namespace RENDER_NS 41 42 namespace Dotfield { 43 /** 44 RenderDataStoreDefaultDotfield 45 46 - Handles/Managers dotfield buffers and effects. 47 */ 48 class RenderDataStoreDefaultDotfield final : public IRenderDataStoreDefaultDotfield { 49 public: 50 RenderDataStoreDefaultDotfield(RENDER_NS::IRenderContext& engine, const BASE_NS::string_view name); 51 ~RenderDataStoreDefaultDotfield() override; 52 53 // IRenderDataStoreDefaultDotfield 54 void AddDotfieldPrimitive(const RenderDataDefaultDotfield::DotfieldPrimitive& dotfieldPrimitive) override; 55 void RemoveDotfieldPrimitive(const CORE_NS::Entity& entity) override; 56 57 BASE_NS::array_view<RenderDataDefaultDotfield::DotfieldPrimitive> GetDotfieldPrimitives() override; 58 BASE_NS::array_view<const RenderDataDefaultDotfield::DotfieldPrimitive> GetDotfieldPrimitives() const override; 59 const RenderDataDefaultDotfield::BufferData& GetBufferData() const override; 60 61 float GetTimeStep() const noexcept override; 62 void SetTimeStep(float time) noexcept override; 63 64 float GetTime() const noexcept override; 65 void SetTime(float time) noexcept override; 66 67 // IRenderDataStore PreRender()68 void PreRender() override {} 69 // Reset and start indexing from the beginning. i.e. frame boundary reset. 70 void PostRender() override; PreRenderBackend()71 void PreRenderBackend() override {} PostRenderBackend()72 void PostRenderBackend() override {} 73 void Clear() override; 74 GetFlags()75 uint32_t GetFlags() const override 76 { 77 return 0; 78 } 79 GetTypeName()80 BASE_NS::string_view GetTypeName() const override 81 { 82 return TYPE_NAME; 83 } 84 GetName()85 BASE_NS::string_view GetName() const override 86 { 87 return name_; 88 } 89 GetUid()90 const BASE_NS::Uid& GetUid() const override 91 { 92 return UID; 93 } 94 95 void Ref() override; 96 void Unref() override; 97 int32_t GetRefCount() override; 98 99 // for plugin / factory interface 100 static constexpr char const *TYPE_NAME = "RenderDataStoreDefaultDotfield"; 101 static BASE_NS::refcnt_ptr<IRenderDataStore> Create(RENDER_NS::IRenderContext& renderContext, char const *name); 102 103 private: 104 RENDER_NS::IRenderContext& context_; 105 BASE_NS::string name_; 106 RENDER_NS::IGpuResourceManager& gpuResourceMgr_; 107 108 BASE_NS::vector<RenderDataDefaultDotfield::DotfieldPrimitive> primitives_; 109 110 // store all dotfield gpu buffers here 111 RenderDataDefaultDotfield::BufferData bufferData_; 112 float timeStep_ { 1.f }; 113 float time_ { 1.f }; 114 115 std::atomic_int32_t refcnt_ { 0 }; 116 }; 117 } // namespace Dotfield 118 119 #endif // RENDER_DATA_STORE_DEFAULT_DOTFIELD_H 120