BsMaterial.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsResource.h"
  4. #include "BsMaterialParam.h"
  5. #include "BsVector2.h"
  6. #include "BsVector3.h"
  7. #include "BsVector4.h"
  8. #include "BsMatrix3.h"
  9. #include "BsMatrix4.h"
  10. namespace BansheeEngine
  11. {
  12. /**
  13. * @brief Helper class containing parameters for all types
  14. * of GPU programs used in a pass.
  15. */
  16. template<bool Core>
  17. class TPassParameters
  18. {
  19. public:
  20. typedef typename TGpuParamsPtrType<Core>::Type GpuParamsType;
  21. /**
  22. * @brief Returns a set of GPU parameters based on an index.
  23. *
  24. * @note Useful when needing to iterate over all sets of GPU parameters.
  25. */
  26. GpuParamsType& getParamByIdx(UINT32 idx)
  27. {
  28. GpuParamsType* paramArray[] = { &mVertParams, &mFragParams, &mGeomParams, &mHullParams, &mDomainParams, &mComputeParams };
  29. return *paramArray[idx];
  30. }
  31. /**
  32. * @brief Sets GPU parameters based on an index.
  33. *
  34. * @note Useful when needing to iterate over all sets of GPU parameters.
  35. */
  36. void setParamByIdx(UINT32 idx, const GpuParamsType& params)
  37. {
  38. GpuParamsType* paramArray[] = { &mVertParams, &mFragParams, &mGeomParams, &mHullParams, &mDomainParams, &mComputeParams };
  39. (*paramArray[idx]) = params;
  40. }
  41. /**
  42. * @brief Returns the total number of stored sets of
  43. * GPU parameters in this object.
  44. */
  45. UINT32 getNumParams() const { return 6; }
  46. GpuParamsType mVertParams;
  47. GpuParamsType mFragParams;
  48. GpuParamsType mGeomParams;
  49. GpuParamsType mHullParams;
  50. GpuParamsType mDomainParams;
  51. GpuParamsType mComputeParams;
  52. };
  53. template<bool Core> struct TGpuParamBlockBufferPtrType { };
  54. template<> struct TGpuParamBlockBufferPtrType<false> { typedef SPtr<GpuParamBlockBuffer> Type; };
  55. template<> struct TGpuParamBlockBufferPtrType<true> { typedef SPtr<GpuParamBlockBufferCore> Type; };
  56. template<bool Core> struct TGpuProgramType { };
  57. template<> struct TGpuProgramType<false> { typedef HGpuProgram Type; };
  58. template<> struct TGpuProgramType<true> { typedef SPtr<GpuProgramCore> Type; };
  59. typedef TPassParameters<false> PassParameters;
  60. typedef TPassParameters<true> PassParametersCore;
  61. /**
  62. * @brief Material represents a shader and parameters used to set up
  63. * that shader. It provides a simple interface for manipulating the
  64. * parameters.
  65. */
  66. class BS_CORE_EXPORT MaterialBase
  67. {
  68. public:
  69. /**
  70. * @brief Data used to described a structure defined within a shader.
  71. */
  72. struct StructData
  73. {
  74. StructData()
  75. :size(0), data(nullptr)
  76. { }
  77. StructData(UINT32 _size)
  78. :size(_size)
  79. {
  80. data = std::shared_ptr<void>(bs_alloc<ScratchAlloc>(_size), &bs_free<ScratchAlloc>);
  81. }
  82. /**
  83. * @brief Writes the specified data to the internal buffer. Caller
  84. * must ensure size of the provided buffer is correct.
  85. */
  86. void write(void* _data)
  87. {
  88. memcpy(data.get(), _data, size);
  89. }
  90. std::shared_ptr<void> data;
  91. UINT32 size;
  92. };
  93. virtual ~MaterialBase() { }
  94. protected:
  95. /**
  96. * @brief Retrieves a list of all shader GPU parameters, and the GPU program variable names they map to.
  97. */
  98. const Map<String, String>& getValidParamNames() const { return mValidParams; }
  99. /**
  100. * @copydoc CoreObject::markCoreDirty
  101. */
  102. virtual void _markCoreDirty() { }
  103. /**
  104. * @brief Returns all GPU parameter descriptions in the specified technique.
  105. */
  106. static Vector<GpuParamDescPtr> getAllParamDescs(const SPtr<Technique>& technique);
  107. /**
  108. * @brief Returns all GPU parameter descriptions in the specified technique.
  109. */
  110. static Vector<GpuParamDescPtr> getAllParamDescs(const SPtr<TechniqueCore>& technique);
  111. Set<String> mValidShareableParamBlocks;
  112. Map<String, String> mValidParams; // Also maps Shader param name -> gpu variable name
  113. };
  114. template<bool Core>
  115. class BS_CORE_EXPORT TMaterial : public MaterialBase
  116. {
  117. public:
  118. template<bool Core> struct TPassType {};
  119. template<> struct TPassType < false > { typedef SPtr<Pass> Type; };
  120. template<> struct TPassType < true > { typedef SPtr<PassCore> Type; };
  121. template<bool Core> struct TTechniqueType {};
  122. template<> struct TTechniqueType < false > { typedef SPtr<Technique> Type; };
  123. template<> struct TTechniqueType < true > { typedef SPtr<TechniqueCore> Type; };
  124. template<bool Core> struct TShaderType {};
  125. template<> struct TShaderType < false > { typedef SPtr<Shader> Type; };
  126. template<> struct TShaderType < true > { typedef SPtr<ShaderCore> Type; };
  127. template<bool Core> struct TGpuParamBlockBufferType {};
  128. template<> struct TGpuParamBlockBufferType < false > { typedef GpuParamBlockBuffer Type; };
  129. template<> struct TGpuParamBlockBufferType < true > { typedef GpuParamBlockBufferCore Type; };
  130. typedef typename TGpuParamsPtrType<Core>::Type GpuParamsType;
  131. typedef typename TGpuParamTextureType<Core>::Type TextureType;
  132. typedef typename TGpuParamSamplerStateType<Core>::Type SamplerStateType;
  133. typedef typename TGpuParamBlockBufferPtrType<Core>::Type ParamBlockPtrType;
  134. typedef typename TGpuParamBlockBufferType<Core>::Type ParamBlockType;
  135. typedef typename TGpuProgramType<Core>::Type GpuProgramType;
  136. typedef typename TPassType<Core>::Type PassType;
  137. typedef typename TTechniqueType<Core>::Type TechniqueType;
  138. typedef typename TShaderType<Core>::Type ShaderType;
  139. /**
  140. * @brief Sets a shader that will be used by the material. Best technique within the
  141. * provided shader will be used for the material.
  142. *
  143. * @note Shader must be set before doing any other operations with the material.
  144. *
  145. * After setting the shader if change any systems that a shader technique is
  146. * dependent upon (render system, renderer, etc), you will need to call this
  147. * method again on all your Materials to make sure technique used is updated.
  148. */
  149. void setShader(ShaderType shader);
  150. /**
  151. * @brief Returns the currently active shader.
  152. */
  153. ShaderType getShader() const { return mShader; }
  154. /**
  155. * @brief Returns the number of passes that are used
  156. * by the shader used in the material.
  157. */
  158. UINT32 getNumPasses() const;
  159. /**
  160. * @brief Retrieves a specific shader pass.
  161. */
  162. PassType getPass(UINT32 passIdx) const;
  163. /**
  164. * @brief Assigns a float value to the shader parameter with the specified name.
  165. *
  166. * Optionally if the parameter is an array you may provide an array index to assign the value to.
  167. */
  168. void setFloat(const String& name, float value, UINT32 arrayIdx = 0) { return getParamFloat(name).set(value, arrayIdx); }
  169. /**
  170. * @brief Assigns a color to the shader parameter with the specified name.
  171. *
  172. * Optionally if the parameter is an array you may provide an array index to assign the value to.
  173. */
  174. void setColor(const String& name, const Color& value, UINT32 arrayIdx = 0)
  175. {
  176. return getParamVec4(name).set(Vector4(value.r, value.g, value.b, value.a), arrayIdx);
  177. }
  178. /**
  179. * @brief Assigns a 2D vector to the shader parameter with the specified name.
  180. *
  181. * Optionally if the parameter is an array you may provide an array index to assign the value to.
  182. */
  183. void setVec2(const String& name, const Vector2& value, UINT32 arrayIdx = 0) { return getParamVec2(name).set(value, arrayIdx); }
  184. /**
  185. * @brief Assigns a 3D vector to the shader parameter with the specified name.
  186. *
  187. * Optionally if the parameter is an array you may provide an array index to assign the value to.
  188. */
  189. void setVec3(const String& name, const Vector3& value, UINT32 arrayIdx = 0) { return getParamVec3(name).set(value, arrayIdx); }
  190. /**
  191. * @brief Assigns a 4D vector to the shader parameter with the specified name.
  192. *
  193. * Optionally if the parameter is an array you may provide an array index to assign the value to.
  194. */
  195. void setVec4(const String& name, const Vector4& value, UINT32 arrayIdx = 0) { return getParamVec4(name).set(value, arrayIdx); }
  196. /**
  197. * @brief Assigns a 3x3 matrix to the shader parameter with the specified name.
  198. *
  199. * Optionally if the parameter is an array you may provide an array index to assign the value to.
  200. */
  201. void setMat3(const String& name, const Matrix3& value, UINT32 arrayIdx = 0) { return getParamMat3(name).set(value, arrayIdx); }
  202. /**
  203. * @brief Assigns a 4x4 matrix to the shader parameter with the specified name.
  204. *
  205. * Optionally if the parameter is an array you may provide an array index to assign the value to.
  206. */
  207. void setMat4(const String& name, const Matrix4& value, UINT32 arrayIdx = 0) { return getParamMat4(name).set(value, arrayIdx); }
  208. /**
  209. * @brief Assigns a structure to the shader parameter with the specified name.
  210. *
  211. * Structure is provided as a raw buffer and caller must ensure structure in buffer
  212. * matches what the shader expects.
  213. *
  214. * Optionally if the parameter is an array you may provide an array index to assign the value to.
  215. */
  216. void setStructData(const String& name, void* value, UINT32 size, UINT32 arrayIdx = 0) { return getParamStruct(name).set(value, size, arrayIdx); }
  217. /** @brief Assigns a texture to the shader parameter with the specified name. */
  218. void setTexture(const String& name, const TextureType& value) { return getParamTexture(name).set(value); }
  219. /**
  220. * @brief Assigns a texture to be used for random load/store operations to the
  221. * shader parameter with the specified name.
  222. */
  223. void setLoadStoreTexture(const String& name, const TextureType& value, const TextureSurface& surface)
  224. {
  225. return getParamLoadStoreTexture(name).set(value, surface);
  226. }
  227. /** @brief Assigns a sampler state to the shader parameter with the specified name. */
  228. void setSamplerState(const String& name, const SamplerStateType& value) { return getParamSamplerState(name).set(value); }
  229. /**
  230. * @brief Returns a float value assigned with the parameter with the specified name.
  231. *
  232. * Optionally if the parameter is an array you may provide an array index you which to retrieve.
  233. */
  234. float getFloat(const String& name, UINT32 arrayIdx = 0) const { return getParamFloat(name).get(arrayIdx); }
  235. /**
  236. * @brief Returns a color assigned with the parameter with the specified name.
  237. *
  238. * Optionally if the parameter is an array you may provide an array index you which to retrieve.
  239. */
  240. Color getColor(const String& name, UINT32 arrayIdx = 0) const { return getParamColor(name).get(arrayIdx); }
  241. /**
  242. * @brief Returns a 2D vector assigned with the parameter with the specified name.
  243. *
  244. * Optionally if the parameter is an array you may provide an array index you which to retrieve.
  245. */
  246. Vector2 getVec2(const String& name, UINT32 arrayIdx = 0) const { return getParamVec2(name).get(arrayIdx); }
  247. /**
  248. * @brief Returns a 3D vector assigned with the parameter with the specified name.
  249. *
  250. * Optionally if the parameter is an array you may provide an array index you which to retrieve.
  251. */
  252. Vector3 getVec3(const String& name, UINT32 arrayIdx = 0) const { return getParamVec3(name).get(arrayIdx); }
  253. /**
  254. * @brief Returns a 4D vector assigned with the parameter with the specified name.
  255. *
  256. * Optionally if the parameter is an array you may provide an array index you which to retrieve.
  257. */
  258. Vector4 getVec4(const String& name, UINT32 arrayIdx = 0) const { return getParamVec4(name).get(arrayIdx); }
  259. /**
  260. * @brief Returns a 3x3 matrix assigned with the parameter with the specified name.
  261. *
  262. * Optionally if the parameter is an array you may provide an array index you which to retrieve.
  263. */
  264. Matrix3 getMat3(const String& name, UINT32 arrayIdx = 0) const { return getParamMat3(name).get(arrayIdx); }
  265. /**
  266. * @brief Returns a 4x4 matrix assigned with the parameter with the specified name.
  267. *
  268. * Optionally if the parameter is an array you may provide an array index you which to retrieve.
  269. */
  270. Matrix4 getMat4(const String& name, UINT32 arrayIdx = 0) const { return getParamMat4(name).get(arrayIdx); }
  271. /** @brief Returns a texture assigned with the parameter with the specified name. */
  272. TextureType getTexture(const String& name) const { return getParamTexture(name).get(); }
  273. /** @brief Returns a sampler state assigned with the parameter with the specified name. */
  274. SamplerStateType getSamplerState(const String& name) const { return getParamSamplerState(name).get(); }
  275. /**
  276. * @brief Returns a buffer representing a structure assigned to the parameter with the specified name.
  277. *
  278. * Optionally if the parameter is an array you may provide an array index you which to retrieve.
  279. */
  280. MaterialBase::StructData getStructData(const String& name, UINT32 arrayIdx = 0) const
  281. {
  282. TMaterialParamStruct<Core> structParam = getParamStruct(name);
  283. MaterialBase::StructData data(structParam.getElementSize());
  284. structParam.get(data.data.get(), structParam.getElementSize(), arrayIdx);
  285. return data;
  286. }
  287. /**
  288. * @brief Returns a float GPU parameter. This parameter may be used for
  289. * more efficiently getting/setting GPU parameter values than calling
  290. * Material::get* / Material::set* methods.
  291. *
  292. * @note Expected behavior is that you would retrieve this parameter when
  293. * initially constructing the material, and then use it throughout material
  294. * lifetime to assign and retrieve parameter values.
  295. *
  296. * If material shader changes this handle will be invalidated.
  297. */
  298. TMaterialDataParam<float, Core> getParamFloat(const String& name) const
  299. {
  300. TMaterialDataParam<float, Core> gpuParam;
  301. getParam(name, gpuParam);
  302. return gpuParam;
  303. }
  304. /**
  305. * @brief Returns a color GPU parameter. This parameter may be used for
  306. * more efficiently getting/setting GPU parameter values than calling
  307. * Material::get* / Material::set* methods.
  308. *
  309. * @note Expected behavior is that you would retrieve this parameter when
  310. * initially constructing the material, and then use it throughout material
  311. * lifetime to assign and retrieve parameter values.
  312. *
  313. * If material shader changes this handle will be invalidated.
  314. */
  315. TMaterialDataParam<Color, Core> getParamColor(const String& name) const
  316. {
  317. TMaterialDataParam<Color, Core> gpuParam;
  318. getParam(name, gpuParam);
  319. return gpuParam;
  320. }
  321. /**
  322. * @brief Returns a 2D vector GPU parameter. This parameter may be used for
  323. * more efficiently getting/setting GPU parameter values than calling
  324. * Material::get* / Material::set* methods.
  325. *
  326. * @note Expected behavior is that you would retrieve this parameter when
  327. * initially constructing the material, and then use it throughout material
  328. * lifetime to assign and retrieve parameter values.
  329. *
  330. * If material shader changes this handle will be invalidated.
  331. */
  332. TMaterialDataParam<Vector2, Core> getParamVec2(const String& name) const
  333. {
  334. TMaterialDataParam<Vector2, Core> gpuParam;
  335. getParam(name, gpuParam);
  336. return gpuParam;
  337. }
  338. /**
  339. * @brief Returns a 3D vector GPU parameter. This parameter may be used for
  340. * more efficiently getting/setting GPU parameter values than calling
  341. * Material::get* / Material::set* methods.
  342. *
  343. * @note Expected behavior is that you would retrieve this parameter when
  344. * initially constructing the material, and then use it throughout material
  345. * lifetime to assign and retrieve parameter values.
  346. *
  347. * If material shader changes this handle will be invalidated.
  348. */
  349. TMaterialDataParam<Vector3, Core> getParamVec3(const String& name) const
  350. {
  351. TMaterialDataParam<Vector3, Core> gpuParam;
  352. getParam(name, gpuParam);
  353. return gpuParam;
  354. }
  355. /**
  356. * @brief Returns a 4D vector GPU parameter. This parameter may be used for
  357. * more efficiently getting/setting GPU parameter values than calling
  358. * Material::get* / Material::set* methods.
  359. *
  360. * @note Expected behavior is that you would retrieve this parameter when
  361. * initially constructing the material, and then use it throughout material
  362. * lifetime to assign and retrieve parameter values.
  363. *
  364. * If material shader changes this handle will be invalidated.
  365. */
  366. TMaterialDataParam<Vector4, Core> getParamVec4(const String& name) const
  367. {
  368. TMaterialDataParam<Vector4, Core> gpuParam;
  369. getParam(name, gpuParam);
  370. return gpuParam;
  371. }
  372. /**
  373. * @brief Returns a 3x3 matrix GPU parameter. This parameter may be used for
  374. * more efficiently getting/setting GPU parameter values than calling
  375. * Material::get* / Material::set* methods.
  376. *
  377. * @note Expected behavior is that you would retrieve this parameter when
  378. * initially constructing the material, and then use it throughout material
  379. * lifetime to assign and retrieve parameter values.
  380. *
  381. * If material shader changes this handle will be invalidated.
  382. */
  383. TMaterialDataParam<Matrix3, Core> getParamMat3(const String& name) const
  384. {
  385. TMaterialDataParam<Matrix3, Core> gpuParam;
  386. getParam(name, gpuParam);
  387. return gpuParam;
  388. }
  389. /**
  390. * @brief Returns a 4x4 matrix GPU parameter. This parameter may be used for
  391. * more efficiently getting/setting GPU parameter values than calling
  392. * Material::get* / Material::set* methods.
  393. *
  394. * @note Expected behavior is that you would retrieve this parameter when
  395. * initially constructing the material, and then use it throughout material
  396. * lifetime to assign and retrieve parameter values.
  397. *
  398. * If material shader changes this handle will be invalidated.
  399. */
  400. TMaterialDataParam<Matrix4, Core> getParamMat4(const String& name) const
  401. {
  402. TMaterialDataParam<Matrix4, Core> gpuParam;
  403. getParam(name, gpuParam);
  404. return gpuParam;
  405. }
  406. /**
  407. * @brief Returns a structure GPU parameter. This parameter may be used for
  408. * more efficiently getting/setting GPU parameter values than calling
  409. * Material::get* / Material::set* methods.
  410. *
  411. * @note Expected behavior is that you would retrieve this parameter when
  412. * initially constructing the material, and then use it throughout material
  413. * lifetime to assign and retrieve parameter values.
  414. *
  415. * If material shader changes this handle will be invalidated.
  416. */
  417. TMaterialParamStruct<Core> getParamStruct(const String& name) const;
  418. /**
  419. * @brief Returns a texture GPU parameter. This parameter may be used for
  420. * more efficiently getting/setting GPU parameter values than calling
  421. * Material::get* / Material::set* methods.
  422. *
  423. * @note Expected behavior is that you would retrieve this parameter when
  424. * initially constructing the material, and then use it throughout material
  425. * lifetime to assign and retrieve parameter values.
  426. *
  427. * If material shader changes this handle will be invalidated.
  428. */
  429. TMaterialParamTexture<Core> getParamTexture(const String& name) const;
  430. /**
  431. * @brief Returns a GPU parameter for binding a load/store texture. This parameter
  432. * may be used for more efficiently getting/setting GPU parameter values
  433. * than calling Material::get* / Material::set* methods.
  434. *
  435. * @note Expected behavior is that you would retrieve this parameter when
  436. * initially constructing the material, and then use it throughout material
  437. * lifetime to assign and retrieve parameter values.
  438. *
  439. * If material shader changes this handle will be invalidated.
  440. */
  441. TMaterialParamLoadStoreTexture<Core> getParamLoadStoreTexture(const String& name) const;
  442. /**
  443. * @brief Returns a sampler state GPU parameter. This parameter may be used for
  444. * more efficiently getting/setting GPU parameter values than calling
  445. * Material::get* / Material::set* methods.
  446. *
  447. * @note Expected behavior is that you would retrieve this parameter when
  448. * initially constructing the material, and then use it throughout material
  449. * lifetime to assign and retrieve parameter values.
  450. *
  451. * If material shader changes this handle will be invalidated.
  452. */
  453. TMaterialParamSampState<Core> getParamSamplerState(const String& name) const;
  454. /**
  455. * @brief Returns a set of parameters for all GPU programs
  456. * in the specified shader pass.
  457. */
  458. SPtr<TPassParameters<Core>> getPassParameters(UINT32 passIdx) const { return mParametersPerPass[passIdx]; }
  459. /**
  460. * @brief Assign a parameter block buffer with the specified name.
  461. *
  462. * @note Parameter block buffers can be used as quick way of setting multiple parameters on a material at once, or
  463. * potentially sharing parameters between multiple materials. This reduces driver overhead as the parameters
  464. * in the buffers need only be set once and then reused multiple times.
  465. */
  466. void setParamBlockBuffer(const String& name, const ParamBlockPtrType& paramBlock);
  467. protected:
  468. /**
  469. * @brief Allows you to retrieve a handle to a parameter that you can then use for quickly
  470. * setting and retrieving parameter data. This allows you to set/get parameter data
  471. * without all the cost of extra lookups otherwise required.
  472. *
  473. * @note All of these handles will be invalidated if material shader ever changes. It is up to the
  474. * caller to keep track of that.
  475. */
  476. template <typename T>
  477. void getParam(const String& name, TMaterialDataParam<T, Core>& output) const;
  478. /**
  479. * @brief Initializes the material by using the best technique from the currently set shader. Shader
  480. * must contain the technique that matches the current renderer and render system.
  481. */
  482. void initBestTechnique();
  483. /**
  484. * @brief Throw an exception if no shader is set, or no acceptable
  485. * technique was found.
  486. */
  487. void throwIfNotInitialized() const;
  488. Vector<SPtr<TPassParameters<Core>>> mParametersPerPass;
  489. ShaderType mShader;
  490. TechniqueType mBestTechnique;
  491. };
  492. /**
  493. * @copydoc MaterialBase
  494. */
  495. class BS_CORE_EXPORT MaterialCore : public CoreObjectCore, public TMaterial<true>
  496. {
  497. public:
  498. ~MaterialCore() { }
  499. /**
  500. * @brief Creates a new material with the specified shader.
  501. */
  502. static SPtr<MaterialCore> create(const SPtr<ShaderCore>& shader);
  503. private:
  504. friend class Material;
  505. MaterialCore() { }
  506. MaterialCore(const SPtr<ShaderCore>& shader);
  507. MaterialCore(const SPtr<ShaderCore>& shader, const SPtr<TechniqueCore>& bestTechnique,
  508. const Set<String>& validShareableParamBlocks, const Map<String, String>& validParams,
  509. const Vector<SPtr<PassParametersCore>>& passParams);
  510. /**
  511. * @copydoc CoreObjectCore::syncToCore
  512. */
  513. void syncToCore(const CoreSyncData& data);
  514. };
  515. /**
  516. * @copydoc MaterialBase
  517. */
  518. class BS_CORE_EXPORT Material : public Resource, public TMaterial<false>
  519. {
  520. public:
  521. ~Material() { }
  522. /**
  523. * @brief Retrieves an implementation of a material usable only from the
  524. * core thread.
  525. */
  526. SPtr<MaterialCore> getCore() const;
  527. /**
  528. * @brief Creates a new empty material.
  529. *
  530. * @note Make sure you call Material::setShader before using it.
  531. */
  532. static HMaterial create();
  533. /**
  534. * @brief Creates a new material with the specified shader.
  535. */
  536. static HMaterial create(ShaderPtr shader);
  537. private:
  538. friend class MaterialManager;
  539. Material() { }
  540. Material(const ShaderPtr& shader);
  541. /**
  542. * @copydoc CoreObject::createCore
  543. */
  544. SPtr<CoreObjectCore> createCore() const;
  545. /**
  546. * @copydoc CoreObject::syncToCore
  547. */
  548. CoreSyncData syncToCore(FrameAlloc* allocator);
  549. /**
  550. * @copydoc CoreObject::markCoreDirty
  551. */
  552. void _markCoreDirty();
  553. /************************************************************************/
  554. /* RTTI */
  555. /************************************************************************/
  556. public:
  557. friend class MaterialRTTI;
  558. static RTTITypeBase* getRTTIStatic();
  559. virtual RTTITypeBase* getRTTI() const;
  560. };
  561. }