BsMaterialParams.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "BsIReflectable.h"
  6. #include "BsStaticAlloc.h"
  7. #include "BsVector2.h"
  8. #include "BsGpuParams.h"
  9. namespace BansheeEngine
  10. {
  11. /** @addtogroup Material-Internal
  12. * @{
  13. */
  14. struct SHADER_DATA_PARAM_DESC;
  15. struct SHADER_OBJECT_PARAM_DESC;
  16. /** Common functionality for MaterialParams and MaterialParamsCore. */
  17. class BS_CORE_EXPORT MaterialParamsBase
  18. {
  19. public:
  20. /** Type of material parameter. */
  21. enum class ParamType
  22. {
  23. Data, Texture, Sampler, Buffer
  24. };
  25. /** Result codes for getParam method. */
  26. enum class GetParamResult
  27. {
  28. Success,
  29. NotFound,
  30. InvalidType,
  31. IndexOutOfBounds
  32. };
  33. /** Meta-data about a parameter. */
  34. struct ParamData
  35. {
  36. ParamType type;
  37. GpuParamDataType dataType;
  38. UINT32 index;
  39. UINT32 arraySize;
  40. UINT32 dirtyFlags;
  41. };
  42. /**
  43. * Creates a new material params object and initializes enough room for parameters from the provided parameter data.
  44. */
  45. MaterialParamsBase(
  46. const Map<String, SHADER_DATA_PARAM_DESC>& dataParams,
  47. const Map<String, SHADER_OBJECT_PARAM_DESC>& textureParams,
  48. const Map<String, SHADER_OBJECT_PARAM_DESC>& bufferParams,
  49. const Map<String, SHADER_OBJECT_PARAM_DESC>& samplerParams);
  50. /** Constructor for serialization use only. */
  51. MaterialParamsBase() { }
  52. virtual ~MaterialParamsBase();
  53. /**
  54. * Returns the value of a shader data parameter with the specified name at the specified array index. If the
  55. * parameter name, index or type is not valid a warning will be logged and output value will not be retrieved.
  56. *
  57. * @param[in] name Name of the shader parameter.
  58. * @param[in] arrayIdx If the parameter is an array, index of the entry to access.
  59. * @param[out] output If successful, value of the parameter.
  60. *
  61. * @tparam T Native type of the parameter.
  62. */
  63. template <typename T>
  64. void getDataParam(const String& name, UINT32 arrayIdx, T& output) const
  65. {
  66. GpuParamDataType dataType = TGpuDataParamInfo<T>::TypeId;
  67. const ParamData* param = nullptr;
  68. auto result = getParamData(name, ParamType::Data, dataType, arrayIdx, &param);
  69. if (result != GetParamResult::Success)
  70. return;
  71. const GpuParamDataTypeInfo& typeInfo = GpuParams::PARAM_SIZES.lookup[dataType];
  72. UINT32 paramTypeSize = typeInfo.numColumns * typeInfo.numRows * typeInfo.baseTypeSize;
  73. output = *(T*)(mDataParamsBuffer[param->index + arrayIdx * paramTypeSize]);
  74. memcpy(output, &mDataParamsBuffer[param->index + arrayIdx * paramTypeSize], sizeof(paramTypeSize));
  75. }
  76. /**
  77. * Sets the value of a shader data parameter with the specified name at the specified array index. If the
  78. * parameter name, index or type is not valid a warning will be logged and output value will not be set.
  79. *
  80. * @param[in] name Name of the shader parameter.
  81. * @param[in] arrayIdx If the parameter is an array, index of the entry to access.
  82. * @param[in] input New value of the parameter.
  83. *
  84. * @tparam T Native type of the parameter.
  85. */
  86. template <typename T>
  87. void setDataParam(const String& name, UINT32 arrayIdx, const T& input) const
  88. {
  89. GpuParamDataType dataType = TGpuDataParamInfo<T>::TypeId;
  90. const ParamData* param = nullptr;
  91. auto result = getParamData(name, ParamType::Data, dataType, arrayIdx, &param);
  92. if (result != GetParamResult::Success)
  93. return;
  94. const GpuParamDataTypeInfo& typeInfo = GpuParams::PARAM_SIZES.lookup[dataType];
  95. UINT32 paramTypeSize = typeInfo.numColumns * typeInfo.numRows * typeInfo.baseTypeSize;
  96. memcpy(&mDataParamsBuffer[param->index + arrayIdx * paramTypeSize], input, sizeof(paramTypeSize));
  97. }
  98. /**
  99. * Returns data about a parameter and reports an error if there is a type or size mismatch, or if the parameter
  100. * does exist.
  101. *
  102. * @param[in] name Name of the shader parameter.
  103. * @param[in] type Type of the parameter retrieve. Error will be logged if actual type of the parameter
  104. * doesn't match.
  105. * @param[in] dataType Only relevant if the parameter is a data type. Determines exact data type of the parameter
  106. * to retrieve.
  107. * @param[in] arrayIdx Array index of the entry to retrieve.
  108. * @param[out] output Object describing the parameter with an index to its data. If the parameter was not found
  109. * this value is undefined. This value will still be valid if parameter was found but
  110. * some other error was reported.
  111. *
  112. * @return Success or error state of the request.
  113. */
  114. GetParamResult getParamData(const String& name, ParamType type, GpuParamDataType dataType, UINT32 arrayIdx,
  115. const ParamData** output) const;
  116. /**
  117. * Logs an error that was reported by getParamData().
  118. *
  119. * @param[in] errorCode Information about the error.
  120. * @param[in] name Name of the shader parameter for which the error occurred.
  121. * @param[in] arrayIdx Array index for which the error occurred.
  122. */
  123. void reportGetParamError(GetParamResult errorCode, const String& name, UINT32 arrayIdx) const;
  124. /**
  125. * Equivalent to getDataParam(const String&, UINT32, T&) except it uses the internal parameter index
  126. * directly, avoiding the name lookup. Caller must guarantee the index is valid.
  127. */
  128. template <typename T>
  129. void getDataParam(UINT32 index, UINT32 arrayIdx, T& output) const
  130. {
  131. GpuParamDataType dataType = (GpuParamDataType)TGpuDataParamInfo<T>::TypeId;
  132. const GpuParamDataTypeInfo& typeInfo = GpuParams::PARAM_SIZES.lookup[dataType];
  133. UINT32 paramTypeSize = typeInfo.numColumns * typeInfo.numRows * typeInfo.baseTypeSize;
  134. assert(sizeof(output) == paramTypeSize);
  135. memcpy(&output, &mDataParamsBuffer[index + arrayIdx * paramTypeSize], paramTypeSize);
  136. }
  137. /**
  138. * Equivalent to setDataParam(const String&, UINT32, T&) except it uses the internal parameter index
  139. * directly, avoiding the name lookup. Caller must guarantee the index is valid.
  140. */
  141. template <typename T>
  142. void setDataParam(UINT32 index, UINT32 arrayIdx, const T& input) const
  143. {
  144. GpuParamDataType dataType = (GpuParamDataType)TGpuDataParamInfo<T>::TypeId;
  145. const GpuParamDataTypeInfo& typeInfo = GpuParams::PARAM_SIZES.lookup[dataType];
  146. UINT32 paramTypeSize = typeInfo.numColumns * typeInfo.numRows * typeInfo.baseTypeSize;
  147. assert(sizeof(input) == paramTypeSize);
  148. memcpy(&mDataParamsBuffer[index + arrayIdx * paramTypeSize], &input, paramTypeSize);
  149. }
  150. protected:
  151. const static UINT32 STATIC_BUFFER_SIZE = 256;
  152. UnorderedMap<String, UINT32> mParamLookup;
  153. Vector<ParamData> mParams;
  154. UINT8* mDataParamsBuffer = nullptr;
  155. UINT32 mDataSize = 0;
  156. UINT32 mNumStructParams = 0;
  157. UINT32 mNumTextureParams = 0;
  158. UINT32 mNumBufferParams = 0;
  159. UINT32 mNumSamplerParams = 0;
  160. mutable StaticAlloc<STATIC_BUFFER_SIZE, STATIC_BUFFER_SIZE> mAlloc;
  161. };
  162. /** Raw data for a single structure parameter. */
  163. class BS_CORE_EXPORT MaterialParamStructDataCore
  164. {
  165. public:
  166. UINT8* data;
  167. UINT32 dataSize;
  168. };
  169. /** Raw data for a single structure parameter. */
  170. class BS_CORE_EXPORT MaterialParamStructData : public IReflectable
  171. {
  172. public:
  173. UINT8* data;
  174. UINT32 dataSize;
  175. friend class MaterialParamStructDataRTTI;
  176. static RTTITypeBase* getRTTIStatic();
  177. RTTITypeBase* getRTTI() const override;
  178. };
  179. /** Data for a single texture parameter. */
  180. class BS_CORE_EXPORT MaterialParamTextureDataCore
  181. {
  182. public:
  183. SPtr<TextureCore> value;
  184. bool isLoadStore;
  185. TextureSurface surface;
  186. };
  187. /** Data for a single texture parameter. */
  188. class BS_CORE_EXPORT MaterialParamTextureData : public IReflectable
  189. {
  190. public:
  191. HTexture value;
  192. bool isLoadStore;
  193. TextureSurface surface;
  194. friend class MaterialParamTextureDataRTTI;
  195. static RTTITypeBase* getRTTIStatic();
  196. RTTITypeBase* getRTTI() const override;
  197. };
  198. /** Data for a single buffer parameter. */
  199. class BS_CORE_EXPORT MaterialParamBufferDataCore
  200. {
  201. public:
  202. SPtr<GpuBufferCore> value;
  203. };
  204. /** Data for a single buffer parameter. */
  205. class BS_CORE_EXPORT MaterialParamBufferData
  206. {
  207. public:
  208. SPtr<GpuBuffer> value;
  209. };
  210. /** Data for a single sampler state parameter. */
  211. class BS_CORE_EXPORT MaterialParamSamplerStateDataCore
  212. {
  213. public:
  214. SPtr<SamplerStateCore> value;
  215. };
  216. /** Data for a single sampler state parameter. */
  217. class BS_CORE_EXPORT MaterialParamSamplerStateData
  218. {
  219. public:
  220. SPtr<SamplerState> value;
  221. };
  222. /** Helper typedefs that reference types used by either core or sim thread implementation of TMaterialParams<Core>. */
  223. template<bool Core> struct TMaterialParamsTypes { };
  224. template<> struct TMaterialParamsTypes < false >
  225. {
  226. typedef GpuParams GpuParamsType;
  227. typedef HTexture TextureType;
  228. typedef SPtr<GpuBuffer> BufferType;
  229. typedef SPtr<SamplerState> SamplerType;
  230. typedef SPtr<GpuParamBlockBuffer> ParamsBufferType;
  231. typedef MaterialParamStructData StructParamDataType;
  232. typedef MaterialParamTextureData TextureParamDataType;
  233. typedef MaterialParamBufferData BufferParamDataType;
  234. typedef MaterialParamSamplerStateData SamplerStateParamDataType;
  235. typedef HShader ShaderType;
  236. };
  237. template<> struct TMaterialParamsTypes < true >
  238. {
  239. typedef GpuParamsCore GpuParamsType;
  240. typedef SPtr<TextureCore> TextureType;
  241. typedef SPtr<GpuBufferCore> BufferType;
  242. typedef SPtr<SamplerStateCore> SamplerType;
  243. typedef SPtr<GpuParamBlockBufferCore> ParamsBufferType;
  244. typedef MaterialParamStructDataCore StructParamDataType;
  245. typedef MaterialParamTextureDataCore TextureParamDataType;
  246. typedef MaterialParamBufferDataCore BufferParamDataType;
  247. typedef MaterialParamSamplerStateDataCore SamplerStateParamDataType;
  248. typedef SPtr<ShaderCore> ShaderType;
  249. };
  250. /** Common code that may be specialized for both MaterialParams and MaterialParamsCore. */
  251. template<bool Core>
  252. class BS_CORE_EXPORT TMaterialParams : public MaterialParamsBase
  253. {
  254. public:
  255. typedef typename TMaterialParamsTypes<Core>::GpuParamsType GpuParamsType;
  256. typedef typename TMaterialParamsTypes<Core>::TextureType TextureType;
  257. typedef typename TMaterialParamsTypes<Core>::BufferType BufferType;
  258. typedef typename TMaterialParamsTypes<Core>::SamplerType SamplerType;
  259. typedef typename TMaterialParamsTypes<Core>::ShaderType ShaderType;
  260. typedef typename TMaterialParamsTypes<Core>::StructParamDataType ParamStructDataType;
  261. typedef typename TMaterialParamsTypes<Core>::TextureParamDataType ParamTextureDataType;
  262. typedef typename TMaterialParamsTypes<Core>::BufferParamDataType ParamBufferDataType;
  263. typedef typename TMaterialParamsTypes<Core>::SamplerStateParamDataType ParamSamplerStateDataType;
  264. /** Creates a new material params object and initializes enough room for parameters from the provided shader. */
  265. TMaterialParams(const ShaderType& shader);
  266. /** Constructor for serialization use only. */
  267. TMaterialParams() { }
  268. virtual ~TMaterialParams();
  269. /**
  270. * Returns the value of a shader structure parameter with the specified name at the specified array index. If the
  271. * parameter name, index or type is not valid a warning will be logged and output value will not be retrieved.
  272. *
  273. * @param[in] name Name of the shader parameter.
  274. * @param[out] value Pre-allocated buffer of @p size bytes where the value will be retrieved.
  275. * @param[in] size Size of the buffer into which to write the value. Must match parameter struct's size.
  276. * @param[in] arrayIdx If the parameter is an array, index of the entry to access.
  277. */
  278. void getStructData(const String& name, void* value, UINT32 size, UINT32 arrayIdx) const;
  279. /**
  280. * Sets the value of a shader structure parameter with the specified name at the specified array index. If the
  281. * parameter name, index or type is not valid a warning will be logged and output value will not be retrieved.
  282. *
  283. * @param[in] name Name of the shader parameter.
  284. * @param[in] value Buffer of @p size bytes containing the new value of the structure.
  285. * @param[in] size Size of the buffer from which to retrieve the value. Must match parameter struct's size.
  286. * @param[in] arrayIdx If the parameter is an array, index of the entry to access.
  287. */
  288. void setStructData(const String& name, const void* value, UINT32 size, UINT32 arrayIdx);
  289. /**
  290. * Returns the value of a shader texture parameter with the specified name. If the parameter name or type is not
  291. * valid a warning will be logged and output value will not be retrieved.
  292. *
  293. * @param[in] name Name of the shader parameter.
  294. * @param[out] value Output value of the parameter.
  295. */
  296. void getTexture(const String& name, TextureType& value) const;
  297. /**
  298. * Sets the value of a shader texture parameter with the specified name. If the parameter name or type is not
  299. * valid a warning will be logged and output value will not be set.
  300. *
  301. * @param[in] name Name of the shader parameter.
  302. * @param[in] value New value of the parameter.
  303. */
  304. void setTexture(const String& name, const TextureType& value);
  305. /**
  306. * Returns the value of a shader load/store texture parameter with the specified name. If the parameter name or
  307. * type is not valid a warning will be logged and output value will not be retrieved.
  308. *
  309. * @param[in] name Name of the shader parameter.
  310. * @param[out] value Output value of the parameter.
  311. * @param[out] surface Surface describing which part of the texture is being accessed.
  312. */
  313. void getLoadStoreTexture(const String& name, TextureType& value, TextureSurface& surface) const;
  314. /**
  315. * Sets the value of a shader load/store texture parameter with the specified name. If the parameter name or
  316. * type is not valid a warning will be logged and the value will not be set.
  317. *
  318. * @param[in] name Name of the shader parameter.
  319. * @param[in] value New value of the parameter.
  320. * @param[in] surface Surface describing which part of the texture is being accessed.
  321. */
  322. void setLoadStoreTexture(const String& name, const TextureType& value, const TextureSurface& surface);
  323. /**
  324. * Returns the value of a shader buffer parameter with the specified name. If the parameter name or type is not
  325. * valid a warning will be logged and output value will not be retrieved.
  326. *
  327. * @param[in] name Name of the shader parameter.
  328. * @param[out] value Output value of the parameter.
  329. */
  330. void getBuffer(const String& name, BufferType& value) const;
  331. /**
  332. * Sets the value of a shader buffer parameter with the specified name. If the parameter name or type is not
  333. * valid a warning will be logged and output value will not be set.
  334. *
  335. * @param[in] name Name of the shader parameter.
  336. * @param[in] value New value of the parameter.
  337. */
  338. void setBuffer(const String& name, const BufferType& value);
  339. /**
  340. * Sets the value of a shader sampler state parameter with the specified name. If the parameter name or type is not
  341. * valid a warning will be logged and output value will not be set.
  342. *
  343. * @param[in] name Name of the shader parameter.
  344. * @param[out] value Output value of the parameter.
  345. */
  346. void getSamplerState(const String& name, SamplerType& value) const;
  347. /**
  348. * Sets the value of a shader sampler state parameter with the specified name. If the parameter name or type is not
  349. * valid a warning will be logged and output value will not be set.
  350. *
  351. * @param[in] name Name of the shader parameter.
  352. * @param[in] value New value of the parameter.
  353. */
  354. void setSamplerState(const String& name, const SamplerType& value);
  355. /**
  356. * Equivalent to getStructData(const String&, UINT32, void*, UINT32) except it uses the internal parameter index
  357. * directly, avoiding the name lookup. Caller must guarantee the index is valid.
  358. */
  359. void getStructData(UINT32 index, void* value, UINT32 size) const;
  360. /**
  361. * Equivalent to setStructData(const String&, UINT32, void*, UINT32) except it uses the internal parameter index
  362. * directly, avoiding the name lookup. Caller must guarantee the index is valid.
  363. */
  364. void setStructData(UINT32 index, const void* value, UINT32 size);
  365. /**
  366. * Returns a size of a struct parameter in bytes, using the internal parameter index. Caller must guarantee the
  367. * index is valid.
  368. */
  369. UINT32 getStructSize(UINT32 index) const;
  370. /**
  371. * Equivalent to getTexture(const String&, HTexture&) except it uses the internal parameter index directly,
  372. * avoiding the name lookup. Caller must guarantee the index is valid.
  373. */
  374. void getTexture(UINT32 index, TextureType& value) const;
  375. /**
  376. * Equivalent to setTexture(const String&, HTexture&) except it uses the internal parameter index directly,
  377. * avoiding the name lookup. Caller must guarantee the index is valid.
  378. */
  379. void setTexture(UINT32 index, const TextureType& value);
  380. /**
  381. * Equivalent to getBuffer(const String&, SPtr<GpuBuffer>&) except it uses the internal parameter index directly,
  382. * avoiding the name lookup. Caller must guarantee the index is valid.
  383. */
  384. void getBuffer(UINT32 index, BufferType& value) const;
  385. /**
  386. * Equivalent to setBuffer(const String&, SPtr<GpuBuffer>&) except it uses the internal parameter index directly,
  387. * avoiding the name lookup. Caller must guarantee the index is valid.
  388. */
  389. void setBuffer(UINT32 index, const BufferType& value);
  390. /**
  391. * Equivalent to getLoadStoreTexture(const String&, HTexture&, TextureSurface&) except it uses the internal
  392. * parameter index directly, avoiding the name lookup. Caller must guarantee the index is valid.
  393. */
  394. void getLoadStoreTexture(UINT32 index, TextureType& value, TextureSurface& surface) const;
  395. /**
  396. * Equivalent to setLoadStoreTexture(const String&, HTexture&, TextureSurface&) except it uses the internal
  397. * parameter index directly, avoiding the name lookup. Caller must guarantee the index is valid.
  398. */
  399. void setLoadStoreTexture(UINT32 index, const TextureType& value, const TextureSurface& surface);
  400. /**
  401. * Checks is a texture with the specified index a load/store texture or a normal one. Caller must guarantee the
  402. * index is valid.
  403. */
  404. bool getIsTextureLoadStore(UINT32 index) const;
  405. /**
  406. * Equivalent to getSamplerState(const String&, SPtr<SamplerState>&) except it uses the internal parameter index
  407. * directly, avoiding the name lookup. Caller must guarantee the index is valid.
  408. */
  409. void getSamplerState(UINT32 index, SamplerType& value) const;
  410. /**
  411. * Equivalent to setSamplerState(const String&, SPtr<SamplerState>&) except it uses the internal parameter index
  412. * directly, avoiding the name lookup. Caller must guarantee the index is valid.
  413. */
  414. void setSamplerState(UINT32 index, const SamplerType& value);
  415. /**
  416. * Returns the default texture (one assigned when no other is provided), if available for the specified index.
  417. * Index is the internal parameter index and the caller must guarantee the index is valid.
  418. */
  419. void getDefaultTexture(UINT32 index, TextureType& value) const;
  420. /**
  421. * Returns the default sampler state (one assigned when no other is provided), if available for the specified index.
  422. * Index is the internal parameter index and the caller must guarantee the index is valid.
  423. */
  424. void getDefaultSamplerState(UINT32 index, SamplerType& value) const;
  425. protected:
  426. ParamStructDataType* mStructParams = nullptr;
  427. ParamTextureDataType* mTextureParams = nullptr;
  428. ParamBufferDataType* mBufferParams = nullptr;
  429. ParamSamplerStateDataType* mSamplerStateParams = nullptr;
  430. TextureType* mDefaultTextureParams = nullptr;
  431. SamplerType* mDefaultSamplerStateParams = nullptr;
  432. };
  433. class MaterialParams;
  434. /** Core thread version of MaterialParams. */
  435. class BS_CORE_EXPORT MaterialParamsCore : public TMaterialParams<true>
  436. {
  437. public:
  438. /** Initializes the core thread version of MaterialParams from its sim thread counterpart. */
  439. MaterialParamsCore(const SPtr<ShaderCore>& shader, const SPtr<MaterialParams>& params);
  440. /** @copydoc TMaterialParams<Core>::TMaterialParams */
  441. MaterialParamsCore(const SPtr<ShaderCore>& shader);
  442. /**
  443. * Updates the stored parameters from the provided buffer, allowing changed to be transfered between the sim and
  444. * core thread material param objects. Buffer must be retrieved from MaterialParams::getSyncData.
  445. *
  446. * @param[in] buffer Buffer containing the dirty data.
  447. * @param[in, out] size Size of the provided buffer.
  448. */
  449. void setSyncData(UINT8* buffer, UINT32 size);
  450. };
  451. /**
  452. * Contains all parameter values set in a Material. This is similar to GpuParams which also stores parameter values,
  453. * however GpuParams are built for use on the GPU-side and don't store parameters that don't exist in a compiled GPU
  454. * program. This object on the other hand stores all parameters defined in a shader, regardless or not if they actually
  455. * exist in the GPU program. Additionally GpuParams are defined per-program (for example vertex, fragment) while this
  456. * object exists for the entire material.
  457. *
  458. * @note
  459. * This introduces redundancy as parameters stored by GpuParams and this object are duplicated. If this is an issue the
  460. * implementation can be modified to only store parameters not included in GpuParams.
  461. * @note
  462. * The reason why parameters in this class and GpuParams differ is most often compiler optimizations. If a compiler
  463. * optimizes out a variable in a GPU program we should still be able to store it, either for later when the variable
  464. * will be introduced, or for other techniques that might have that variable implemented.
  465. */
  466. class BS_CORE_EXPORT MaterialParams : public IReflectable, public TMaterialParams<false>
  467. {
  468. public:
  469. /** @copydoc TMaterialParams<Core>::TMaterialParams */
  470. MaterialParams(const HShader& shader);
  471. /**
  472. * Populates the provided buffer with parameters that can be used for syncing this object with its core-thread
  473. * counterpart. Can be applied by calling MaterialParamsCore::setSyncData.
  474. *
  475. * @param[in] buffer Pre-allocated buffer to store the sync data in. Set to null to calculate the size
  476. * of the required buffer.
  477. * @param[in, out] size Size of the provided allocated buffer. Or if the buffer is null, this parameter will
  478. * contain the required buffer size when the method executes.
  479. */
  480. void getSyncData(UINT8* buffer, UINT32& size);
  481. private:
  482. friend class MaterialParamsCore;
  483. /************************************************************************/
  484. /* RTTI */
  485. /************************************************************************/
  486. public:
  487. MaterialParams() { } // Only for serialization
  488. friend class MaterialParamsRTTI;
  489. static RTTITypeBase* getRTTIStatic();
  490. RTTITypeBase* getRTTI() const override;
  491. };
  492. /** @} */
  493. }