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 "Material/BsShaderVariation.h"
8
9namespace bs
10{
11 /** @cond RTTI */
12 /** @addtogroup RTTI-Impl-Core
13 * @{
14 */
15
16 template<>
17 struct RTTIPlainType<ShaderVariation::Param>
18 {
19 enum { id = TID_ShaderVariationParam }; enum { hasDynamicSize = 1 };
20
21 /** @copydoc RTTIPlainType::toMemory */
22 static void toMemory(const ShaderVariation::Param& data, char* memory)
23 {
24 UINT32 size = sizeof(UINT32);
25 char* memoryStart = memory;
26 memory += sizeof(UINT32);
27
28 UINT8 version = 0;
29 memory = rttiWriteElem(version, memory, size);
30 memory = rttiWriteElem(data.name, memory, size);
31 memory = rttiWriteElem(data.type, memory, size);
32 memory = rttiWriteElem(data.i, memory, size);
33
34 memcpy(memoryStart, &size, sizeof(UINT32));
35 }
36
37 /** @copydoc RTTIPlainType::fromMemory */
38 static UINT32 fromMemory(ShaderVariation::Param& data, char* memory)
39 {
40 UINT32 size = 0;
41 memory = rttiReadElem(size, memory);
42
43 UINT8 version;
44 memory = rttiReadElem(version, memory);
45 assert(version == 0);
46
47 memory = rttiReadElem(data.name, memory);
48 memory = rttiReadElem(data.type, memory);
49 memory = rttiReadElem(data.i, memory);
50
51 return size;
52 }
53
54 /** @copydoc RTTIPlainType::getDynamicSize */
55 static UINT32 getDynamicSize(const ShaderVariation::Param& data)
56 {
57 UINT64 dataSize = sizeof(UINT8) + sizeof(UINT32);
58 dataSize += rttiGetElemSize(data.name);
59 dataSize += rttiGetElemSize(data.type);
60 dataSize += rttiGetElemSize(data.i);
61
62 assert(dataSize <= std::numeric_limits<UINT32>::max());
63
64 return (UINT32)dataSize;
65 }
66 };
67
68 class BS_CORE_EXPORT ShaderVariationRTTI : public RTTIType <ShaderVariation, IReflectable, ShaderVariationRTTI>
69 {
70 private:
71 BS_BEGIN_RTTI_MEMBERS
72 BS_RTTI_MEMBER_PLAIN(mParams, 0)
73 BS_END_RTTI_MEMBERS
74 public:
75 const String& getRTTIName() override
76 {
77 static String name = "ShaderVariation";
78 return name;
79 }
80
81 UINT32 getRTTIId() override
82 {
83 return TID_ShaderVariation;
84 }
85
86 SPtr<IReflectable> newRTTIObject() override
87 {
88 return bs_shared_ptr_new<ShaderVariation>();
89 }
90 };
91
92 /** @} */
93 /** @endcond */
94}
95