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 "Image/BsPixelData.h"
7#include "Reflection/BsRTTIType.h"
8#include "FileSystem/BsDataStream.h"
9
10namespace bs
11{
12 /** @cond RTTI */
13 /** @addtogroup RTTI-Impl-Core
14 * @{
15 */
16
17 class BS_CORE_EXPORT PixelDataRTTI : public RTTIType<PixelData, GpuResourceData, PixelDataRTTI>
18 {
19 UINT32& getLeft(PixelData* obj) { return obj->mExtents.left; }
20 void setLeft(PixelData* obj, UINT32& val) { obj->mExtents.left = val; }
21
22 UINT32& getTop(PixelData* obj) { return obj->mExtents.top; }
23 void setTop(PixelData* obj, UINT32& val) { obj->mExtents.top = val; }
24
25 UINT32& getRight(PixelData* obj) { return obj->mExtents.right; }
26 void setRight(PixelData* obj, UINT32& val) { obj->mExtents.right = val; }
27
28 UINT32& getBottom(PixelData* obj) { return obj->mExtents.bottom; }
29 void setBottom(PixelData* obj, UINT32& val) { obj->mExtents.bottom = val; }
30
31 UINT32& getFront(PixelData* obj) { return obj->mExtents.front; }
32 void setFront(PixelData* obj, UINT32& val) { obj->mExtents.front = val; }
33
34 UINT32& getBack(PixelData* obj) { return obj->mExtents.back; }
35 void setBack(PixelData* obj, UINT32& val) { obj->mExtents.back = val; }
36
37 UINT32& getRowPitch(PixelData* obj) { return obj->mRowPitch; }
38 void setRowPitch(PixelData* obj, UINT32& val) { obj->mRowPitch = val; }
39
40 UINT32& getSlicePitch(PixelData* obj) { return obj->mSlicePitch; }
41 void setSlicePitch(PixelData* obj, UINT32& val) { obj->mSlicePitch = val; }
42
43 PixelFormat& getFormat(PixelData* obj) { return obj->mFormat; }
44 void setFormat(PixelData* obj, PixelFormat& val) { obj->mFormat = val; }
45
46 SPtr<DataStream> getData(PixelData* obj, UINT32& size)
47 {
48 size = obj->getConsecutiveSize();
49
50 return bs_shared_ptr_new<MemoryDataStream>(obj->getData(), size, false);
51 }
52
53 void setData(PixelData* obj, const SPtr<DataStream>& value, UINT32 size)
54 {
55 obj->allocateInternalBuffer(size);
56 value->read(obj->getData(), size);
57 }
58
59 public:
60 PixelDataRTTI()
61 {
62 addPlainField("left", 0, &PixelDataRTTI::getLeft, &PixelDataRTTI::setLeft);
63 addPlainField("top", 1, &PixelDataRTTI::getTop, &PixelDataRTTI::setTop);
64 addPlainField("right", 2, &PixelDataRTTI::getRight, &PixelDataRTTI::setRight);
65 addPlainField("bottom", 3, &PixelDataRTTI::getBottom, &PixelDataRTTI::setBottom);
66 addPlainField("front", 4, &PixelDataRTTI::getFront, &PixelDataRTTI::setFront);
67 addPlainField("back", 5, &PixelDataRTTI::getBack, &PixelDataRTTI::setBack);
68 addPlainField("rowPitch", 6, &PixelDataRTTI::getRowPitch, &PixelDataRTTI::setRowPitch);
69 addPlainField("slicePitch", 7, &PixelDataRTTI::getSlicePitch, &PixelDataRTTI::setSlicePitch);
70 addPlainField("format", 8, &PixelDataRTTI::getFormat, &PixelDataRTTI::setFormat);
71 addDataBlockField("data", 9, &PixelDataRTTI::getData, &PixelDataRTTI::setData);
72 }
73
74 virtual const String& getRTTIName() override
75 {
76 static String name = "PixelData";
77 return name;
78 }
79
80 virtual UINT32 getRTTIId() override
81 {
82 return TID_PixelData;
83 }
84
85 virtual SPtr<IReflectable> newRTTIObject() override
86 {
87 SPtr<PixelData> newPixelData = bs_shared_ptr_new<PixelData>();
88
89 return newPixelData;
90 }
91 };
92
93 /** @} */
94 /** @endcond */
95}