1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #pragma once |
4 | |
5 | #include "BsCorePrerequisites.h" |
6 | #include "Mesh/BsMeshBase.h" |
7 | |
8 | namespace bs |
9 | { |
10 | /** @addtogroup Resources |
11 | * @{ |
12 | */ |
13 | |
14 | /** |
15 | * Represents a single mesh entry in the MeshHeap. This can be used as a normal mesh but due to the nature of the |
16 | * mesh heap it is not the type of mesh you should use for storing static data. |
17 | * |
18 | * Transient meshes don't keep internal index/vertex buffers but instead use the ones provided by their parent mesh heap. |
19 | * |
20 | * @note Sim thread. |
21 | */ |
22 | class BS_CORE_EXPORT TransientMesh : public MeshBase |
23 | { |
24 | public: |
25 | virtual ~TransientMesh(); |
26 | |
27 | /** Retrieves a core implementation of a mesh usable only from the core thread. */ |
28 | SPtr<ct::TransientMesh> getCore() const; |
29 | |
30 | protected: |
31 | friend class MeshHeap; |
32 | |
33 | /** |
34 | * Constructs a new transient mesh. |
35 | * |
36 | * @see MeshHeap::alloc |
37 | */ |
38 | TransientMesh(const SPtr<MeshHeap>& parentHeap, UINT32 id, UINT32 numVertices, |
39 | UINT32 numIndices, DrawOperationType drawOp = DOT_TRIANGLE_LIST); |
40 | |
41 | /** Marks the mesh as destroyed so we know that we don't need to destroy it ourselves. */ |
42 | void markAsDestroyed() { mIsDestroyed = true; } |
43 | |
44 | /** @copydoc MeshBase::createCore */ |
45 | SPtr<ct::CoreObject> createCore() const override; |
46 | |
47 | protected: |
48 | bool mIsDestroyed; |
49 | SPtr<MeshHeap> mParentHeap; |
50 | UINT32 mId; |
51 | }; |
52 | |
53 | /** @} */ |
54 | |
55 | namespace ct |
56 | { |
57 | /** @addtogroup Resources-Internal |
58 | * @{ |
59 | */ |
60 | |
61 | /** |
62 | * Core thread portion of a bs::TransientMesh. |
63 | * |
64 | * @note Core thread. |
65 | */ |
66 | class BS_CORE_EXPORT TransientMesh : public MeshBase |
67 | { |
68 | public: |
69 | TransientMesh(const SPtr<MeshHeap>& parentHeap, UINT32 id, UINT32 numVertices, |
70 | UINT32 numIndices, const Vector<SubMesh>& subMeshes); |
71 | |
72 | /** @copydoc MeshBase::getVertexData */ |
73 | SPtr<VertexData> getVertexData() const override; |
74 | |
75 | /** @copydoc MeshBase::getIndexBuffer */ |
76 | SPtr<IndexBuffer> getIndexBuffer() const override; |
77 | |
78 | /** @copydoc MeshBase::getVertexDesc */ |
79 | SPtr<VertexDataDesc> getVertexDesc() const override; |
80 | |
81 | /** Returns the ID that uniquely identifies this mesh in the parent heap. */ |
82 | UINT32 getMeshHeapId() const { return mId; } |
83 | |
84 | /** @copydoc MeshBase::getVertexOffset */ |
85 | UINT32 getVertexOffset() const override; |
86 | |
87 | /** @copydoc MeshBase::getIndexOffset */ |
88 | UINT32 getIndexOffset() const override; |
89 | |
90 | /** @copydoc MeshBase::_notifyUsedOnGPU */ |
91 | void _notifyUsedOnGPU() override; |
92 | |
93 | protected: |
94 | friend class bs::TransientMesh; |
95 | |
96 | SPtr<MeshHeap> mParentHeap; |
97 | UINT32 mId; |
98 | }; |
99 | |
100 | /** @} */ |
101 | } |
102 | } |