BsBlendStateRTTI.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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->mProperties.mData; }
  44. void setData(BlendState* obj, BLEND_STATE_DESC& val) { obj->mProperties.mData = val; }
  45. public:
  46. BlendStateRTTI()
  47. {
  48. addPlainField("mData", 0, &BlendStateRTTI::getData, &BlendStateRTTI::setData);
  49. }
  50. virtual void onDeserializationEnded(IReflectable* obj) override
  51. {
  52. BlendState* blendState = static_cast<BlendState*>(obj);
  53. blendState->initialize();
  54. }
  55. virtual const String& getRTTIName() override
  56. {
  57. static String name = "BlendState";
  58. return name;
  59. }
  60. virtual UINT32 getRTTIId() override
  61. {
  62. return TID_BlendState;
  63. }
  64. virtual std::shared_ptr<IReflectable> newRTTIObject() override
  65. {
  66. return RenderStateManager::instance()._createBlendStatePtr(BLEND_STATE_DESC());
  67. }
  68. };
  69. }