BsBlendStateRTTI.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsRTTIType.h"
  4. #include "BsBlendState.h"
  5. #include "BsRenderStateManager.h"
  6. namespace BansheeEngine
  7. {
  8. template<> struct RTTIPlainType<BLEND_STATE_DESC>
  9. {
  10. enum { id = TID_BLEND_STATE_DESC }; enum { hasDynamicSize = 1 };
  11. static void toMemory(const BLEND_STATE_DESC& data, char* memory)
  12. {
  13. UINT32 size = getDynamicSize(data);
  14. memcpy(memory, &size, sizeof(UINT32));
  15. memory += sizeof(UINT32);
  16. size -= sizeof(UINT32);
  17. memcpy(memory, &data, size);
  18. }
  19. static UINT32 fromMemory(BLEND_STATE_DESC& data, char* memory)
  20. {
  21. UINT32 size;
  22. memcpy(&size, memory, sizeof(UINT32));
  23. memory += sizeof(UINT32);
  24. UINT32 dataSize = size - sizeof(UINT32);
  25. memcpy((void*)&data, memory, dataSize);
  26. return size;
  27. }
  28. static UINT32 getDynamicSize(const BLEND_STATE_DESC& data)
  29. {
  30. UINT64 dataSize = sizeof(data) + sizeof(UINT32);
  31. #if BS_DEBUG_MODE
  32. if(dataSize > std::numeric_limits<UINT32>::max())
  33. {
  34. BS_EXCEPT(InternalErrorException, "Data overflow! Size doesn't fit into 32 bits.");
  35. }
  36. #endif
  37. return (UINT32)dataSize;
  38. }
  39. };
  40. class BS_CORE_EXPORT BlendStateRTTI : public RTTIType<BlendState, IReflectable, BlendStateRTTI>
  41. {
  42. private:
  43. BLEND_STATE_DESC& getData(BlendState* obj) { return obj->mData; }
  44. void setData(BlendState* obj, BLEND_STATE_DESC& val)
  45. {
  46. obj->mRTTIData = val;
  47. }
  48. public:
  49. BlendStateRTTI()
  50. {
  51. addPlainField("mData", 0, &BlendStateRTTI::getData, &BlendStateRTTI::setData);
  52. }
  53. virtual void onDeserializationEnded(IReflectable* obj)
  54. {
  55. BlendState* blendState = static_cast<BlendState*>(obj);
  56. if(!blendState->mRTTIData.empty())
  57. {
  58. BLEND_STATE_DESC desc = any_cast<BLEND_STATE_DESC>(blendState->mRTTIData);
  59. blendState->initialize(desc);
  60. }
  61. }
  62. virtual const String& getRTTIName()
  63. {
  64. static String name = "BlendState";
  65. return name;
  66. }
  67. virtual UINT32 getRTTIId()
  68. {
  69. return TID_BlendState;
  70. }
  71. virtual std::shared_ptr<IReflectable> newRTTIObject()
  72. {
  73. return RenderStateManager::instance().createEmptyBlendState();
  74. }
  75. };
  76. }