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 "Reflection/BsRTTIType.h" |
7 | #include "RenderAPI/BsVertexBuffer.h" |
8 | #include "Managers/BsHardwareBufferManager.h" |
9 | #include "RenderAPI/BsVertexDataDesc.h" |
10 | |
11 | namespace bs |
12 | { |
13 | /** @cond RTTI */ |
14 | /** @addtogroup RTTI-Impl-Core |
15 | * @{ |
16 | */ |
17 | |
18 | class VertexDeclarationRTTI : public RTTIType<VertexDeclaration, IReflectable, VertexDeclarationRTTI> |
19 | { |
20 | private: |
21 | VertexElement& getElement(VertexDeclaration* obj, UINT32 idx) |
22 | { |
23 | Vector<VertexElement>& elemList = obj->mProperties.mElementList; |
24 | |
25 | auto iter = elemList.begin(); |
26 | for(UINT32 i = 0; i < idx; i++) |
27 | ++iter; |
28 | |
29 | return *iter; |
30 | } |
31 | |
32 | void setElement(VertexDeclaration* obj, UINT32 idx, VertexElement& data) |
33 | { |
34 | Vector<VertexElement>& elemList = obj->mProperties.mElementList; |
35 | |
36 | auto iter = elemList.begin(); |
37 | for(UINT32 i = 0; i < idx; i++) |
38 | ++iter; |
39 | |
40 | *iter = data; |
41 | } |
42 | |
43 | UINT32 getElementArraySize(VertexDeclaration* obj) |
44 | { |
45 | Vector<VertexElement>& elemList = obj->mProperties.mElementList; |
46 | |
47 | return (UINT32)elemList.size(); |
48 | } |
49 | |
50 | void setElementArraySize(VertexDeclaration* obj, UINT32 size) |
51 | { |
52 | Vector<VertexElement>& elemList = obj->mProperties.mElementList; |
53 | |
54 | for (size_t i = elemList.size(); i < size; i++) |
55 | elemList.push_back(VertexElement()); |
56 | } |
57 | |
58 | public: |
59 | VertexDeclarationRTTI() |
60 | { |
61 | addPlainArrayField("mElementList" , 0, &VertexDeclarationRTTI::getElement, &VertexDeclarationRTTI::getElementArraySize, |
62 | &VertexDeclarationRTTI::setElement, &VertexDeclarationRTTI::setElementArraySize); |
63 | } |
64 | |
65 | SPtr<IReflectable> newRTTIObject() override |
66 | { |
67 | return HardwareBufferManager::instance().createVertexDeclaration(VertexDataDesc::create()); |
68 | } |
69 | |
70 | const String& getRTTIName() override |
71 | { |
72 | static String name = "VertexDeclaration" ; |
73 | return name; |
74 | } |
75 | |
76 | UINT32 getRTTIId() override |
77 | { |
78 | return TID_VertexDeclaration; |
79 | } |
80 | }; |
81 | |
82 | /** @} */ |
83 | /** @endcond */ |
84 | } |