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 API_3D_RENDER_IRENDER_DATA_STORE_MORPH_H
17 #define API_3D_RENDER_IRENDER_DATA_STORE_MORPH_H
18 
19 #include <cstdint>
20 
21 #include <3d/namespace.h>
22 #include <3d/render/render_data_defines_3d.h>
23 #include <base/containers/array_view.h>
24 #include <base/containers/vector.h>
25 #include <render/datastore/intf_render_data_store.h>
26 #include <render/render_data_structures.h>
27 #include <render/resource_handle.h>
28 
29 CORE3D_BEGIN_NAMESPACE()
30 /** @ingroup group_render_irenderdatastoremorph */
31 /**
32 RenderDataMorph.
33 */
34 struct RenderDataMorph {
35     /** Max vertex buffer count */
36     static constexpr uint32_t MAX_VERTEX_BUFFER_COUNT { 3 };
37 
38     /** Submesh */
39     struct Submesh {
40         /** Vertex count */
41         uint32_t vertexCount;
42 
43         /** {0 = position, 1 = normal, 2 = tangent} */
44         RenderVertexBuffer vertexBuffers[MAX_VERTEX_BUFFER_COUNT];
45 
46         /** Vertex buffer count */
47         uint32_t vertexBufferCount { 0 };
48 
49         /** Buffer contains base position/normal/tangent and all morph target deltas (position/normal/tangent) */
50         RenderVertexBuffer morphTargetBuffer;
51 
52         /** Number of morph targets */
53         uint32_t morphTargetCount { 0 };
54 
55         struct Target {
56             /** Target ID */
57             uint32_t id;
58             /** Weight value for target (must be non-zero) */
59             float weight;
60         };
61         /** Targets with non-zero weights */
62         BASE_NS::vector<Target> activeTargets;
63     };
64 };
65 
66 /** @ingroup group_render_irenderdatastoremorph */
67 /**
68 RenderDataStoreMorph interface.
69 Not internally syncronized.
70 */
71 class IRenderDataStoreMorph : public RENDER_NS::IRenderDataStore {
72 public:
73     static constexpr BASE_NS::Uid UID { "230e8df1-9465-4894-af8f-f47f38413000" };
74 
75     /** Reserve size */
76     struct ReserveSize {
77         /** Submesh count */
78         uint32_t submeshCount { 0 };
79     };
80 
81     ~IRenderDataStoreMorph() override = default;
82 
83     /** Add submeshes safely. */
84     virtual void AddSubmesh(const RenderDataMorph::Submesh& submesh) = 0;
85 
86     /** Get submeshes
87      * @return Return array view of morph submeshes
88      */
89     virtual BASE_NS::array_view<const RenderDataMorph::Submesh> GetSubmeshes() const = 0;
90 
91 protected:
92     IRenderDataStoreMorph() = default;
93 };
94 CORE3D_END_NAMESPACE()
95 
96 #endif // API_3D_RENDER_IRENDER_DATA_STORE_MORPH_H
97