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/BsGpuProgram.h"
8#include "RenderAPI/BsGpuParamDesc.h"
9#include "Managers/BsGpuProgramManager.h"
10
11namespace bs
12{
13 /** @cond RTTI */
14 /** @addtogroup RTTI-Impl-Core
15 * @{
16 */
17
18 class BS_CORE_EXPORT GpuProgramBytecodeRTTI : public RTTIType<GpuProgramBytecode, IReflectable, GpuProgramBytecodeRTTI>
19 {
20 private:
21 BS_BEGIN_RTTI_MEMBERS
22 BS_RTTI_MEMBER_PLAIN(instructions, 0)
23 BS_RTTI_MEMBER_REFLPTR(paramDesc, 1)
24 BS_RTTI_MEMBER_PLAIN(vertexInput, 2)
25 BS_RTTI_MEMBER_PLAIN(messages, 3)
26 BS_RTTI_MEMBER_PLAIN(compilerId, 4)
27 BS_RTTI_MEMBER_PLAIN(compilerVersion, 5)
28 BS_END_RTTI_MEMBERS
29
30 public:
31 const String& getRTTIName() override
32 {
33 static String name = "GpuProgramBytecode";
34 return name;
35 }
36
37 UINT32 getRTTIId() override
38 {
39 return TID_GpuProgramBytecode;
40 }
41
42 SPtr<IReflectable> newRTTIObject() override
43 {
44 return bs_shared_ptr_new<GpuProgramBytecode>();
45 }
46 };
47
48 class BS_CORE_EXPORT GpuParamDescRTTI : public RTTIType<GpuParamDesc, IReflectable, GpuParamDescRTTI>
49 {
50 private:
51 BS_BEGIN_RTTI_MEMBERS
52 BS_RTTI_MEMBER_PLAIN(paramBlocks, 0)
53 BS_RTTI_MEMBER_PLAIN(params, 1)
54 BS_RTTI_MEMBER_PLAIN(samplers, 2)
55 BS_RTTI_MEMBER_PLAIN(textures, 3)
56 BS_RTTI_MEMBER_PLAIN(loadStoreTextures, 4)
57 BS_RTTI_MEMBER_PLAIN(buffers, 5)
58 BS_END_RTTI_MEMBERS
59
60 public:
61 const String& getRTTIName() override
62 {
63 static String name = "GpuParamDesc";
64 return name;
65 }
66
67 UINT32 getRTTIId() override
68 {
69 return TID_GpuParamDesc;
70 }
71
72 SPtr<IReflectable> newRTTIObject() override
73 {
74 return bs_shared_ptr_new<GpuParamDesc>();
75 }
76 };
77
78 class BS_CORE_EXPORT GpuProgramRTTI : public RTTIType<GpuProgram, IReflectable, GpuProgramRTTI>
79 {
80 private:
81 BS_BEGIN_RTTI_MEMBERS
82 BS_RTTI_MEMBER_PLAIN(mType, 2)
83 BS_RTTI_MEMBER_PLAIN(mNeedsAdjacencyInfo, 3)
84 BS_RTTI_MEMBER_PLAIN(mEntryPoint, 4)
85 BS_RTTI_MEMBER_PLAIN(mSource, 6)
86 BS_RTTI_MEMBER_PLAIN(mLanguage, 7)
87 BS_END_RTTI_MEMBERS
88
89 public:
90 void onSerializationStarted(IReflectable* obj, SerializationContext* context) override
91 {
92 // Need to ensure the core thread object is initialized
93 GpuProgram* gpuProgram = static_cast<GpuProgram*>(obj);
94 gpuProgram->blockUntilCoreInitialized();
95 }
96
97 void onDeserializationEnded(IReflectable* obj, SerializationContext* context) override
98 {
99 GpuProgram* gpuProgram = static_cast<GpuProgram*>(obj);
100 gpuProgram->initialize();
101 }
102
103 const String& getRTTIName() override
104 {
105 static String name = "GpuProgram";
106 return name;
107 }
108
109 UINT32 getRTTIId() override
110 {
111 return TID_GpuProgram;
112 }
113
114 SPtr<IReflectable> newRTTIObject() override
115 {
116 return GpuProgramManager::instance().createEmpty("", GPT_VERTEX_PROGRAM); // Params don't matter, they'll get overwritten
117 }
118 };
119
120 /** @} */
121 /** @endcond */
122}
123