瀏覽代碼

PixelData inherits from GpuResourceData

Marko Pintera 12 年之前
父節點
當前提交
470c1c979b

+ 10 - 0
BansheeEngine.sln

@@ -89,8 +89,18 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BansheeEngine", "BansheeEng
 	EndProjectSection
 	EndProjectSection
 EndProject
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BansheeForwardRenderer", "BansheeForwardRenderer\BansheeForwardRenderer.vcxproj", "{08975177-4A13-4EE7-BB21-3BB92FB3F3CC}"
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BansheeForwardRenderer", "BansheeForwardRenderer\BansheeForwardRenderer.vcxproj", "{08975177-4A13-4EE7-BB21-3BB92FB3F3CC}"
+	ProjectSection(ProjectDependencies) = postProject
+		{9B21D41C-516B-43BF-9B10-E99B599C7589} = {9B21D41C-516B-43BF-9B10-E99B599C7589}
+		{CC7F9445-71C9-4559-9976-FF0A64DCB582} = {CC7F9445-71C9-4559-9976-FF0A64DCB582}
+		{07B0C186-5173-46F2-BE26-7E4148BD0CCA} = {07B0C186-5173-46F2-BE26-7E4148BD0CCA}
+	EndProjectSection
 EndProject
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BansheeOctreeSM", "BansheeOctreeSM\BansheeOctreeSM.vcxproj", "{41CC18CE-139E-45A5-A9AA-336CBA2E1521}"
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BansheeOctreeSM", "BansheeOctreeSM\BansheeOctreeSM.vcxproj", "{41CC18CE-139E-45A5-A9AA-336CBA2E1521}"
+	ProjectSection(ProjectDependencies) = postProject
+		{9B21D41C-516B-43BF-9B10-E99B599C7589} = {9B21D41C-516B-43BF-9B10-E99B599C7589}
+		{CC7F9445-71C9-4559-9976-FF0A64DCB582} = {CC7F9445-71C9-4559-9976-FF0A64DCB582}
+		{07B0C186-5173-46F2-BE26-7E4148BD0CCA} = {07B0C186-5173-46F2-BE26-7E4148BD0CCA}
+	EndProjectSection
 EndProject
 EndProject
 Global
 Global
 	GlobalSection(SubversionScc) = preSolution
 	GlobalSection(SubversionScc) = preSolution

+ 1 - 0
CamelotCore/CamelotCore.vcxproj

@@ -182,6 +182,7 @@
     <ClInclude Include="Include\CmGpuResourceData.h" />
     <ClInclude Include="Include\CmGpuResourceData.h" />
     <ClInclude Include="Include\CmGpuParamBlockBuffer.h" />
     <ClInclude Include="Include\CmGpuParamBlockBuffer.h" />
     <ClInclude Include="Include\CmGpuResource.h" />
     <ClInclude Include="Include\CmGpuResource.h" />
+    <ClInclude Include="Include\CmGpuResourceDataRTTI.h" />
     <ClInclude Include="Include\CmGpuResourceRTTI.h" />
     <ClInclude Include="Include\CmGpuResourceRTTI.h" />
     <ClInclude Include="Include\CmPixelData.h" />
     <ClInclude Include="Include\CmPixelData.h" />
     <ClInclude Include="Include\CmPixelDataRTTI.h" />
     <ClInclude Include="Include\CmPixelDataRTTI.h" />

+ 3 - 0
CamelotCore/CamelotCore.vcxproj.filters

@@ -435,6 +435,9 @@
     <ClInclude Include="Include\CmPixelData.h">
     <ClInclude Include="Include\CmPixelData.h">
       <Filter>Header Files\Resources</Filter>
       <Filter>Header Files\Resources</Filter>
     </ClInclude>
     </ClInclude>
+    <ClInclude Include="Include\CmGpuResourceDataRTTI.h">
+      <Filter>Header Files\RTTI</Filter>
+    </ClInclude>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\CmApplication.cpp">
     <ClCompile Include="Source\CmApplication.cpp">

+ 9 - 1
CamelotCore/Include/CmGpuResourceData.h

@@ -11,7 +11,7 @@ namespace CamelotFramework
 	 * 			will always remain with the initial instance of the class. If that initial instance
 	 * 			will always remain with the initial instance of the class. If that initial instance
 	 * 			is deleted, any potential copies will point to garbage data.
 	 * 			is deleted, any potential copies will point to garbage data.
 	 */
 	 */
-	class CM_EXPORT GpuResourceData
+	class CM_EXPORT GpuResourceData : public IReflectable
 	{
 	{
 	public:
 	public:
 		GpuResourceData();
 		GpuResourceData();
@@ -61,5 +61,13 @@ namespace CamelotFramework
 		UINT8* mData;
 		UINT8* mData;
 		bool mOwnsData;
 		bool mOwnsData;
 		mutable bool mLocked;
 		mutable bool mLocked;
+
+		/************************************************************************/
+		/* 								SERIALIZATION                      		*/
+		/************************************************************************/
+	public:
+		friend class GpuResourceDataRTTI;
+		static RTTITypeBase* getRTTIStatic();
+		virtual RTTITypeBase* getRTTI() const;
 	};
 	};
 }
 }

+ 33 - 0
CamelotCore/Include/CmGpuResourceDataRTTI.h

@@ -0,0 +1,33 @@
+#pragma once
+
+#include "CmPrerequisites.h"
+#include "CmRTTIType.h"
+#include "CmGpuResourceData.h"
+
+namespace CamelotFramework
+{
+	class CM_EXPORT GpuResourceDataRTTI : public RTTIType<GpuResourceData, IReflectable, GpuResourceDataRTTI>
+	{
+	public:
+		GpuResourceDataRTTI()
+		{
+
+		}
+
+		virtual const String& getRTTIName()
+		{
+			static String name = "GpuResourceData";
+			return name;
+		}
+
+		virtual UINT32 getRTTIId()
+		{
+			return TID_GpuResourceData;
+		}
+
+		virtual std::shared_ptr<IReflectable> newRTTIObject()
+		{
+			CM_EXCEPT(InternalErrorException, "Cannot instantiate an abstract class.");
+		}
+	};
+}

+ 30 - 49
CamelotCore/Include/CmPixelData.h

@@ -2,6 +2,7 @@
 
 
 #include "CmPrerequisites.h"
 #include "CmPrerequisites.h"
 #include "CmBox.h"
 #include "CmBox.h"
+#include "CmGpuResourceData.h"
 #include "CmIReflectable.h"
 #include "CmIReflectable.h"
 
 
 namespace CamelotFramework
 namespace CamelotFramework
@@ -119,15 +120,13 @@ namespace CamelotFramework
      	Pixels are stored as a succession of "depth" slices, each containing "height" rows of 
      	Pixels are stored as a succession of "depth" slices, each containing "height" rows of 
      	"width" pixels.
      	"width" pixels.
     */
     */
-    class CM_EXPORT PixelData : public IReflectable
+    class CM_EXPORT PixelData : public GpuResourceData
 	{
 	{
     public:
     public:
     	/// Parameter constructor for setting the members manually
     	/// Parameter constructor for setting the members manually
     	PixelData() {}
     	PixelData() {}
-		~PixelData() 
-		{
-			freeInternalBuffer();
-		}
+		~PixelData() {}
+
 		/** Constructor providing extents in the form of a Box object. This constructor
 		/** Constructor providing extents in the form of a Box object. This constructor
     		assumes the pixel data is laid out consecutively in memory. (this
     		assumes the pixel data is laid out consecutively in memory. (this
     		means row after row, slice after slice, with no space in between)
     		means row after row, slice after slice, with no space in between)
@@ -136,7 +135,7 @@ namespace CamelotFramework
     		@param pixelData	Pointer to the actual data
     		@param pixelData	Pointer to the actual data
     	*/
     	*/
 		PixelData(const Box &extents, PixelFormat pixelFormat)
 		PixelData(const Box &extents, PixelFormat pixelFormat)
-			:mExtents(extents), data(nullptr), format(pixelFormat), ownsData(false)
+			:mExtents(extents), mFormat(pixelFormat)
 		{
 		{
 			setConsecutive();
 			setConsecutive();
 		}
 		}
@@ -151,55 +150,31 @@ namespace CamelotFramework
     		@param pixelData    Pointer to the actual data
     		@param pixelData    Pointer to the actual data
     	*/
     	*/
     	PixelData(UINT32 width, UINT32 height, UINT32 depth, PixelFormat pixelFormat)
     	PixelData(UINT32 width, UINT32 height, UINT32 depth, PixelFormat pixelFormat)
-			: mExtents(0, 0, 0, width, height, depth),
-    		data(nullptr), format(pixelFormat), ownsData(false)
+			: mExtents(0, 0, 0, width, height, depth), mFormat(pixelFormat)
     	{
     	{
     		setConsecutive();
     		setConsecutive();
     	}
     	}
 
 
 		PixelData(const PixelData& copy);
 		PixelData(const PixelData& copy);
-    	
-		/**
-		 * @brief	Allocates an internal buffer for storing data.
-		 */
-		UINT8* allocateInternalBuffer(UINT32 size);
-
-		/**
-		 * @brief	Frees the buffer data. Normally you don't need to call this manually as the
-		 * 			data will be freed automatically when an instance of PixelData is freed.
-		 */
-		void freeInternalBuffer();
 
 
-		void setExternalBuffer(UINT8* data);
+		UINT32 getRowPitch() const { return mRowPitch; }
+		UINT32 getSlicePitch() const { return mSlicePitch; }
 
 
-		void* getData() const { return data; }
+		void setRowPitch(UINT32 rowPitch) { mRowPitch = rowPitch; }
+        void setSlicePitch(UINT32 slicePitch) { mSlicePitch = slicePitch; }
 
 
-        /// The pixel format 
-        PixelFormat format;
-        /** Number of elements between the leftmost pixel of one row and the left
-         	pixel of the next. This value must always be equal to getWidth() (consecutive) 
-			for compressed formats.
-        */
-        UINT32 rowPitch;
-        /** Number of elements between the top left pixel of one (depth) slice and 
-         	the top left pixel of the next. This can be a negative value. Must be a multiple of
-         	rowPitch. This value must always be equal to getWidth()*getHeight() (consecutive) 
-			for compressed formats.
-        */
-        UINT32 slicePitch;
-        
         /**	Get the number of elements between one past the rightmost pixel of 
         /**	Get the number of elements between one past the rightmost pixel of 
          	one row and the leftmost pixel of the next row. (IE this is zero if rows
          	one row and the leftmost pixel of the next row. (IE this is zero if rows
          	are consecutive).
          	are consecutive).
         */
         */
-        UINT32 getRowSkip() const { return rowPitch - getWidth(); }
+        UINT32 getRowSkip() const { return mRowPitch - getWidth(); }
         /** Get the number of elements between one past the right bottom pixel of
         /** Get the number of elements between one past the right bottom pixel of
          	one slice and the left top pixel of the next slice. (IE this is zero if slices
          	one slice and the left top pixel of the next slice. (IE this is zero if slices
          	are consecutive).
          	are consecutive).
         */
         */
-        UINT32 getSliceSkip() const { return slicePitch - (getHeight() * rowPitch); }
+        UINT32 getSliceSkip() const { return mSlicePitch - (getHeight() * mRowPitch); }
 
 
-		PixelFormat getFormat() const { return format; }
+		PixelFormat getFormat() const { return mFormat; }
 
 
 		UINT32 getWidth() const { return mExtents.getWidth(); }
 		UINT32 getWidth() const { return mExtents.getWidth(); }
 		UINT32 getHeight() const { return mExtents.getHeight(); }
 		UINT32 getHeight() const { return mExtents.getHeight(); }
@@ -219,7 +194,7 @@ namespace CamelotFramework
         */        
         */        
         bool isConsecutive() const 
         bool isConsecutive() const 
 		{ 
 		{ 
-			return rowPitch == getWidth() && slicePitch == getWidth()*getHeight(); 
+			return mRowPitch == getWidth() && mSlicePitch == getWidth()*getHeight(); 
 		}
 		}
         /** Return the size (in bytes) this image would take if it was
         /** Return the size (in bytes) this image would take if it was
         	laid out consecutive in memory
         	laid out consecutive in memory
@@ -250,23 +225,29 @@ namespace CamelotFramework
         void setColourAt(Color const &cv, UINT32 x, UINT32 y, UINT32 z);
         void setColourAt(Color const &cv, UINT32 x, UINT32 y, UINT32 z);
 
 
 	private:
 	private:
-		/// The data pointer 
-		void *data;
-
-		/**
-		 * @brief	If true then PixelData owns the data buffer and will release it when destroyed.
-		 */
-		bool ownsData;
-
 		Box mExtents;
 		Box mExtents;
 
 
+        /// The pixel format 
+        PixelFormat mFormat;
+        /** Number of elements between the leftmost pixel of one row and the left
+         	pixel of the next. This value must always be equal to getWidth() (consecutive) 
+			for compressed formats.
+        */
+        UINT32 mRowPitch;
+        /** Number of elements between the top left pixel of one (depth) slice and 
+         	the top left pixel of the next. This can be a negative value. Must be a multiple of
+         	rowPitch. This value must always be equal to getWidth()*getHeight() (consecutive) 
+			for compressed formats.
+        */
+        UINT32 mSlicePitch;
+
 		/** Set the rowPitch and slicePitch so that the buffer is laid out consecutive 
 		/** Set the rowPitch and slicePitch so that the buffer is laid out consecutive 
          	in memory.
          	in memory.
         */        
         */        
         void setConsecutive()
         void setConsecutive()
         {
         {
-            rowPitch = getWidth();
-            slicePitch = getWidth()*getHeight();
+            mRowPitch = getWidth();
+            mSlicePitch = getWidth()*getHeight();
         }
         }
 
 
 		/************************************************************************/
 		/************************************************************************/

+ 13 - 11
CamelotCore/Include/CmPixelDataRTTI.h

@@ -7,7 +7,7 @@
 
 
 namespace CamelotFramework
 namespace CamelotFramework
 {
 {
-	class CM_EXPORT PixelDataRTTI : public RTTIType<PixelData, IReflectable, PixelDataRTTI>
+	class CM_EXPORT PixelDataRTTI : public RTTIType<PixelData, GpuResourceData, PixelDataRTTI>
 	{
 	{
 		UINT32& getLeft(PixelData* obj) { return obj->mExtents.left; }
 		UINT32& getLeft(PixelData* obj) { return obj->mExtents.left; }
 		void setLeft(PixelData* obj, UINT32& val) { obj->mExtents.left = val; }
 		void setLeft(PixelData* obj, UINT32& val) { obj->mExtents.left = val; }
@@ -27,14 +27,14 @@ namespace CamelotFramework
 		UINT32& getBack(PixelData* obj) { return obj->mExtents.back; }
 		UINT32& getBack(PixelData* obj) { return obj->mExtents.back; }
 		void setBack(PixelData* obj, UINT32& val) { obj->mExtents.back = val; }
 		void setBack(PixelData* obj, UINT32& val) { obj->mExtents.back = val; }
 
 
-		UINT32& getRowPitch(PixelData* obj) { return obj->rowPitch; }
-		void setRowPitch(PixelData* obj, UINT32& val) { obj->rowPitch = val; }
+		UINT32& getRowPitch(PixelData* obj) { return obj->mRowPitch; }
+		void setRowPitch(PixelData* obj, UINT32& val) { obj->mRowPitch = val; }
 
 
-		UINT32& getSlicePitch(PixelData* obj) { return obj->slicePitch; }
-		void setSlicePitch(PixelData* obj, UINT32& val) { obj->slicePitch = val; }
+		UINT32& getSlicePitch(PixelData* obj) { return obj->mSlicePitch; }
+		void setSlicePitch(PixelData* obj, UINT32& val) { obj->mSlicePitch = val; }
 
 
-		PixelFormat& getFormat(PixelData* obj) { return obj->format; }
-		void setFormat(PixelData* obj, PixelFormat& val) { obj->format = val; }
+		PixelFormat& getFormat(PixelData* obj) { return obj->mFormat; }
+		void setFormat(PixelData* obj, PixelFormat& val) { obj->mFormat = val; }
 
 
 		ManagedDataBlock getData(PixelData* obj) 
 		ManagedDataBlock getData(PixelData* obj) 
 		{ 
 		{ 
@@ -44,12 +44,15 @@ namespace CamelotFramework
 
 
 		void setData(PixelData* obj, ManagedDataBlock val) 
 		void setData(PixelData* obj, ManagedDataBlock val) 
 		{ 
 		{ 
-			obj->data = val.getData();
+			// Nothing to do here, the pointer we provided already belongs to PixelData
+			// so the data is already written
 		}
 		}
 
 
-		static UINT8* allocateData(UINT32 numBytes)
+		static UINT8* allocateData(PixelData* obj, UINT32 numBytes)
 		{
 		{
-			return CM_NEW_BYTES(numBytes, ScratchAlloc);
+			obj->allocateInternalBuffer(numBytes);
+
+			return obj->getData();
 		}
 		}
 
 
 	public:
 	public:
@@ -83,7 +86,6 @@ namespace CamelotFramework
 		{
 		{
 			PixelDataPtr newPixelData(CM_NEW(PixelData, PoolAlloc) PixelData(),
 			PixelDataPtr newPixelData(CM_NEW(PixelData, PoolAlloc) PixelData(),
 				&MemAllocDeleter<PixelData, PoolAlloc>::deleter);
 				&MemAllocDeleter<PixelData, PoolAlloc>::deleter);
-			newPixelData->ownsData = true;
 
 
 			return newPixelData;
 			return newPixelData;
 		}
 		}

+ 2 - 1
CamelotCore/Include/CmPrerequisites.h

@@ -282,7 +282,8 @@ namespace CamelotFramework
 		TID_SceneObject = 1059,
 		TID_SceneObject = 1059,
 		TID_GameObject = 1060,
 		TID_GameObject = 1060,
 		TID_GpuResource = 1061,
 		TID_GpuResource = 1061,
-		TID_PixelData = 1062
+		TID_PixelData = 1062,
+		TID_GpuResourceData = 1063
 	};
 	};
 
 
 	/**
 	/**

+ 15 - 0
CamelotCore/Source/CmGpuResourceData.cpp

@@ -1,4 +1,5 @@
 #include "CmGpuResourceData.h"
 #include "CmGpuResourceData.h"
+#include "CmGpuResourceDataRTTI.h"
 #include "CmRenderSystem.h"
 #include "CmRenderSystem.h"
 #include "CmException.h"
 #include "CmException.h"
 
 
@@ -93,4 +94,18 @@ namespace CamelotFramework
 	{
 	{
 		mLocked = false;
 		mLocked = false;
 	}
 	}
+
+	/************************************************************************/
+	/* 								SERIALIZATION                      		*/
+	/************************************************************************/
+
+	RTTITypeBase* GpuResourceData::getRTTIStatic()
+	{
+		return GpuResourceDataRTTI::instance();
+	}
+
+	RTTITypeBase* GpuResourceData::getRTTI() const
+	{
+		return GpuResourceData::getRTTIStatic();
+	}
 }
 }

+ 4 - 32
CamelotCore/Source/CmPixelData.cpp

@@ -5,40 +5,12 @@
 namespace CamelotFramework
 namespace CamelotFramework
 {
 {
 	PixelData::PixelData(const PixelData& copy)
 	PixelData::PixelData(const PixelData& copy)
-		:IReflectable(copy)
+		:GpuResourceData(copy)
 	{
 	{
-		data = copy.data;
-		format = copy.format;
-		rowPitch = copy.rowPitch;
-		slicePitch = copy.slicePitch;
+		mFormat = copy.mFormat;
+		mRowPitch = copy.mRowPitch;
+		mSlicePitch = copy.mSlicePitch;
 		mExtents = copy.mExtents;
 		mExtents = copy.mExtents;
-		ownsData = false;
-	}
-
-	UINT8* PixelData::allocateInternalBuffer(UINT32 size)
-	{
-		data = CM_NEW_BYTES(size, ScratchAlloc);
-		ownsData = true;
-
-		return (UINT8*)data;
-	}
-
-	void PixelData::freeInternalBuffer()
-	{
-		if(ownsData && getData() != nullptr)
-		{
-			CM_DELETE_BYTES(getData(), ScratchAlloc);
-
-			data = nullptr;
-		}
-	}
-
-	void PixelData::setExternalBuffer(UINT8* data)
-	{
-		freeInternalBuffer();
-
-		this->data = data;
-		ownsData = false;
 	}
 	}
 
 
 	/************************************************************************/
 	/************************************************************************/

+ 60 - 59
CamelotCore/Source/CmPixelUtil.cpp

@@ -68,11 +68,11 @@ namespace CamelotFramework {
 			// for the center of the destination pixel, not the top-left corner
 			// for the center of the destination pixel, not the top-left corner
 			UINT64 sz_48 = (stepz >> 1) - 1;
 			UINT64 sz_48 = (stepz >> 1) - 1;
 			for (size_t z = dst.getFront(); z < dst.getBack(); z++, sz_48 += stepz) {
 			for (size_t z = dst.getFront(); z < dst.getBack(); z++, sz_48 += stepz) {
-				size_t srczoff = (size_t)(sz_48 >> 48) * src.slicePitch;
+				size_t srczoff = (size_t)(sz_48 >> 48) * src.getSlicePitch();
 
 
 				UINT64 sy_48 = (stepy >> 1) - 1;
 				UINT64 sy_48 = (stepy >> 1) - 1;
 				for (size_t y = dst.getTop(); y < dst.getBottom(); y++, sy_48 += stepy) {
 				for (size_t y = dst.getTop(); y < dst.getBottom(); y++, sy_48 += stepy) {
-					size_t srcyoff = (size_t)(sy_48 >> 48) * src.rowPitch;
+					size_t srcyoff = (size_t)(sy_48 >> 48) * src.getRowPitch();
 
 
 					UINT64 sx_48 = (stepx >> 1) - 1;
 					UINT64 sx_48 = (stepx >> 1) - 1;
 					for (size_t x = dst.getLeft(); x < dst.getRight(); x++, sx_48 += stepx) {
 					for (size_t x = dst.getLeft(); x < dst.getRight(); x++, sx_48 += stepx) {
@@ -92,8 +92,8 @@ namespace CamelotFramework {
 	// default floating-point linear resampler, does format conversion
 	// default floating-point linear resampler, does format conversion
 	struct LinearResampler {
 	struct LinearResampler {
 		static void scale(const PixelData& src, const PixelData& dst) {
 		static void scale(const PixelData& src, const PixelData& dst) {
-			size_t srcelemsize = PixelUtil::getNumElemBytes(src.format);
-			size_t dstelemsize = PixelUtil::getNumElemBytes(dst.format);
+			size_t srcelemsize = PixelUtil::getNumElemBytes(src.getFormat());
+			size_t dstelemsize = PixelUtil::getNumElemBytes(dst.getFormat());
 
 
 			// srcdata stays at beginning, pdst is a moving pointer
 			// srcdata stays at beginning, pdst is a moving pointer
 			UINT8* srcdata = (UINT8*)src.getData();
 			UINT8* srcdata = (UINT8*)src.getData();
@@ -140,8 +140,8 @@ namespace CamelotFramework {
 						Color x1y1z1, x2y1z1, x1y2z1, x2y2z1;
 						Color x1y1z1, x2y1z1, x1y2z1, x2y2z1;
 						Color x1y1z2, x2y1z2, x1y2z2, x2y2z2;
 						Color x1y1z2, x2y1z2, x1y2z2, x2y2z2;
 
 
-#define UNPACK(dst,x,y,z) PixelUtil::unpackColour(&dst, src.format, \
-	srcdata + srcelemsize*((x)+(y)*src.rowPitch+(z)*src.slicePitch))
+#define UNPACK(dst,x,y,z) PixelUtil::unpackColour(&dst, src.getFormat(), \
+	srcdata + srcelemsize*((x)+(y)*src.getRowPitch()+(z)*src.getSlicePitch()))
 
 
 						UNPACK(x1y1z1,sx1,sy1,sz1); UNPACK(x2y1z1,sx2,sy1,sz1);
 						UNPACK(x1y1z1,sx1,sy1,sz1); UNPACK(x2y1z1,sx2,sy1,sz1);
 						UNPACK(x1y2z1,sx1,sy2,sz1); UNPACK(x2y2z1,sx2,sy2,sz1);
 						UNPACK(x1y2z1,sx1,sy2,sz1); UNPACK(x2y2z1,sx2,sy2,sz1);
@@ -159,7 +159,7 @@ namespace CamelotFramework {
 							x1y2z2 * ((1.0f - sxf)*        syf *        szf ) +
 							x1y2z2 * ((1.0f - sxf)*        syf *        szf ) +
 							x2y2z2 * (        sxf *        syf *        szf );
 							x2y2z2 * (        sxf *        syf *        szf );
 
 
-						PixelUtil::packColour(accum, dst.format, pdst);
+						PixelUtil::packColour(accum, dst.getFormat(), pdst);
 
 
 						pdst += dstelemsize;
 						pdst += dstelemsize;
 					}
 					}
@@ -175,8 +175,8 @@ namespace CamelotFramework {
 	// avoids overhead of pixel unpack/repack function calls
 	// avoids overhead of pixel unpack/repack function calls
 	struct LinearResampler_Float32 {
 	struct LinearResampler_Float32 {
 		static void scale(const PixelData& src, const PixelData& dst) {
 		static void scale(const PixelData& src, const PixelData& dst) {
-			size_t srcchannels = PixelUtil::getNumElemBytes(src.format) / sizeof(float);
-			size_t dstchannels = PixelUtil::getNumElemBytes(dst.format) / sizeof(float);
+			size_t srcchannels = PixelUtil::getNumElemBytes(src.getFormat()) / sizeof(float);
+			size_t dstchannels = PixelUtil::getNumElemBytes(dst.getFormat()) / sizeof(float);
 			// assert(srcchannels == 3 || srcchannels == 4);
 			// assert(srcchannels == 3 || srcchannels == 4);
 			// assert(dstchannels == 3 || dstchannels == 4);
 			// assert(dstchannels == 3 || dstchannels == 4);
 
 
@@ -227,13 +227,13 @@ namespace CamelotFramework {
 
 
 #define ACCUM3(x,y,z,factor) \
 #define ACCUM3(x,y,z,factor) \
 						{ float f = factor; \
 						{ float f = factor; \
-						size_t off = (x+y*src.rowPitch+z*src.slicePitch)*srcchannels; \
+						size_t off = (x+y*src.getRowPitch()+z*src.getSlicePitch())*srcchannels; \
 						accum[0]+=srcdata[off+0]*f; accum[1]+=srcdata[off+1]*f; \
 						accum[0]+=srcdata[off+0]*f; accum[1]+=srcdata[off+1]*f; \
 						accum[2]+=srcdata[off+2]*f; }
 						accum[2]+=srcdata[off+2]*f; }
 
 
 #define ACCUM4(x,y,z,factor) \
 #define ACCUM4(x,y,z,factor) \
 						{ float f = factor; \
 						{ float f = factor; \
-						size_t off = (x+y*src.rowPitch+z*src.slicePitch)*srcchannels; \
+						size_t off = (x+y*src.getRowPitch()+z*src.getSlicePitch())*srcchannels; \
 						accum[0]+=srcdata[off+0]*f; accum[1]+=srcdata[off+1]*f; \
 						accum[0]+=srcdata[off+0]*f; accum[1]+=srcdata[off+1]*f; \
 						accum[2]+=srcdata[off+2]*f; accum[3]+=srcdata[off+3]*f; }
 						accum[2]+=srcdata[off+2]*f; accum[3]+=srcdata[off+3]*f; }
 
 
@@ -313,8 +313,8 @@ namespace CamelotFramework {
 				unsigned int syf = temp & 0xFFF;
 				unsigned int syf = temp & 0xFFF;
 				size_t sy1 = temp >> 12;
 				size_t sy1 = temp >> 12;
 				size_t sy2 = std::min(sy1+1, (size_t)src.getBottom()-src.getTop()-1);
 				size_t sy2 = std::min(sy1+1, (size_t)src.getBottom()-src.getTop()-1);
-				size_t syoff1 = sy1 * src.rowPitch;
-				size_t syoff2 = sy2 * src.rowPitch;
+				size_t syoff1 = sy1 * src.getRowPitch();
+				size_t syoff2 = sy2 * src.getRowPitch();
 
 
 				UINT64 sx_48 = (stepx >> 1) - 1;
 				UINT64 sx_48 = (stepx >> 1) - 1;
 				for (size_t x = dst.getLeft(); x < dst.getRight(); x++, sx_48+=stepx) {
 				for (size_t x = dst.getLeft(); x < dst.getRight(); x++, sx_48+=stepx) {
@@ -777,11 +777,11 @@ namespace CamelotFramework {
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
 	UINT32 PixelData::getConsecutiveSize() const
 	UINT32 PixelData::getConsecutiveSize() const
 	{
 	{
-		return PixelUtil::getMemorySize(getWidth(), getHeight(), getDepth(), format);
+		return PixelUtil::getMemorySize(getWidth(), getHeight(), getDepth(), mFormat);
 	}
 	}
 	PixelData PixelData::getSubVolume(const Box &def) const
 	PixelData PixelData::getSubVolume(const Box &def) const
 	{
 	{
-		if(PixelUtil::isCompressed(format))
+		if(PixelUtil::isCompressed(mFormat))
 		{
 		{
 			if(def.left == getLeft() && def.top == getTop() && def.front == getFront() &&
 			if(def.left == getLeft() && def.top == getTop() && def.front == getFront() &&
 			   def.right == getRight() && def.bottom == getBottom() && def.back == getBack())
 			   def.right == getRight() && def.bottom == getBottom() && def.back == getBack())
@@ -796,19 +796,19 @@ namespace CamelotFramework {
 			CM_EXCEPT(InvalidParametersException, "Bounds out of range");
 			CM_EXCEPT(InvalidParametersException, "Bounds out of range");
 		}
 		}
 
 
-		const size_t elemSize = PixelUtil::getNumElemBytes(format);
+		const size_t elemSize = PixelUtil::getNumElemBytes(mFormat);
 		// Calculate new data origin
 		// Calculate new data origin
 		// Notice how we do not propagate left/top/front from the incoming box, since
 		// Notice how we do not propagate left/top/front from the incoming box, since
 		// the returned pointer is already offset
 		// the returned pointer is already offset
-		PixelData rval(def.getWidth(), def.getHeight(), def.getDepth(), format);
+		PixelData rval(def.getWidth(), def.getHeight(), def.getDepth(), mFormat);
 
 
 		rval.setExternalBuffer(((UINT8*)getData()) + ((def.left-getLeft())*elemSize)
 		rval.setExternalBuffer(((UINT8*)getData()) + ((def.left-getLeft())*elemSize)
-			+ ((def.top-getTop())*rowPitch*elemSize)
-			+ ((def.front-getFront())*slicePitch*elemSize));
+			+ ((def.top-getTop())*mRowPitch*elemSize)
+			+ ((def.front-getFront())*mSlicePitch*elemSize));
 
 
-		rval.rowPitch = rowPitch;
-		rval.slicePitch = slicePitch;
-		rval.format = format;
+		rval.mRowPitch = mRowPitch;
+		rval.mSlicePitch = mSlicePitch;
+		rval.mFormat = mFormat;
 
 
 		return rval;
 		return rval;
 	}
 	}
@@ -1236,9 +1236,9 @@ namespace CamelotFramework {
 			   src.getDepth() == dst.getDepth());
 			   src.getDepth() == dst.getDepth());
 
 
 		// Check for compressed formats, we don't support decompression, compression or recoding
 		// Check for compressed formats, we don't support decompression, compression or recoding
-		if(PixelUtil::isCompressed(src.format) || PixelUtil::isCompressed(dst.format))
+		if(PixelUtil::isCompressed(src.getFormat()) || PixelUtil::isCompressed(dst.getFormat()))
 		{
 		{
-			if(src.format == dst.format)
+			if(src.getFormat() == dst.getFormat())
 			{
 			{
 				memcpy(dst.getData(), src.getData(), src.getConsecutiveSize());
 				memcpy(dst.getData(), src.getData(), src.getConsecutiveSize());
 				return;
 				return;
@@ -1250,7 +1250,7 @@ namespace CamelotFramework {
 		}
 		}
 
 
         // The easy case
         // The easy case
-        if(src.format == dst.format) {
+        if(src.getFormat() == dst.getFormat()) {
             // Everything consecutive?
             // Everything consecutive?
             if(src.isConsecutive() && dst.isConsecutive())
             if(src.isConsecutive() && dst.isConsecutive())
             {
             {
@@ -1258,19 +1258,19 @@ namespace CamelotFramework {
                 return;
                 return;
             }
             }
 
 
-            const size_t srcPixelSize = PixelUtil::getNumElemBytes(src.format);
-            const size_t dstPixelSize = PixelUtil::getNumElemBytes(dst.format);
+            const size_t srcPixelSize = PixelUtil::getNumElemBytes(src.getFormat());
+            const size_t dstPixelSize = PixelUtil::getNumElemBytes(dst.getFormat());
             UINT8 *srcptr = static_cast<UINT8*>(src.getData())
             UINT8 *srcptr = static_cast<UINT8*>(src.getData())
-                + (src.getLeft() + src.getTop() * src.rowPitch + src.getFront() * src.slicePitch) * srcPixelSize;
+                + (src.getLeft() + src.getTop() * src.getRowPitch() + src.getFront() * src.getSlicePitch()) * srcPixelSize;
             UINT8 *dstptr = static_cast<UINT8*>(dst.getData())
             UINT8 *dstptr = static_cast<UINT8*>(dst.getData())
-				+ (dst.getLeft() + dst.getTop() * dst.rowPitch + dst.getFront() * dst.slicePitch) * dstPixelSize;
+				+ (dst.getLeft() + dst.getTop() * dst.getRowPitch() + dst.getFront() * dst.getSlicePitch()) * dstPixelSize;
 
 
             // Calculate pitches+skips in bytes
             // Calculate pitches+skips in bytes
-            const size_t srcRowPitchBytes = src.rowPitch*srcPixelSize;
+            const size_t srcRowPitchBytes = src.getRowPitch()*srcPixelSize;
             //const size_t srcRowSkipBytes = src.getRowSkip()*srcPixelSize;
             //const size_t srcRowSkipBytes = src.getRowSkip()*srcPixelSize;
             const size_t srcSliceSkipBytes = src.getSliceSkip()*srcPixelSize;
             const size_t srcSliceSkipBytes = src.getSliceSkip()*srcPixelSize;
 
 
-            const size_t dstRowPitchBytes = dst.rowPitch*dstPixelSize;
+            const size_t dstRowPitchBytes = dst.getRowPitch()*dstPixelSize;
             //const size_t dstRowSkipBytes = dst.getRowSkip()*dstPixelSize;
             //const size_t dstRowSkipBytes = dst.getRowSkip()*dstPixelSize;
             const size_t dstSliceSkipBytes = dst.getSliceSkip()*dstPixelSize;
             const size_t dstSliceSkipBytes = dst.getSliceSkip()*dstPixelSize;
 
 
@@ -1291,33 +1291,34 @@ namespace CamelotFramework {
         }
         }
 		// Converting to PF_X8R8G8B8 is exactly the same as converting to
 		// Converting to PF_X8R8G8B8 is exactly the same as converting to
 		// PF_A8R8G8B8. (same with PF_X8B8G8R8 and PF_A8B8G8R8)
 		// PF_A8R8G8B8. (same with PF_X8B8G8R8 and PF_A8B8G8R8)
-		if(dst.format == PF_X8R8G8B8 || dst.format == PF_X8B8G8R8)
+		if(dst.getFormat() == PF_X8R8G8B8 || dst.getFormat() == PF_X8B8G8R8)
 		{
 		{
 			// Do the same conversion, with PF_A8R8G8B8, which has a lot of
 			// Do the same conversion, with PF_A8R8G8B8, which has a lot of
 			// optimized conversions
 			// optimized conversions
-			PixelData tempdst = dst;
-			tempdst.format = dst.format==PF_X8R8G8B8?PF_A8R8G8B8:PF_A8B8G8R8;
+			PixelFormat tempFormat = dst.getFormat()==PF_X8R8G8B8?PF_A8R8G8B8:PF_A8B8G8R8;
+			PixelData tempdst(dst.getWidth(), dst.getHeight(), dst.getDepth(), tempFormat);
 			bulkPixelConversion(src, tempdst);
 			bulkPixelConversion(src, tempdst);
 			return;
 			return;
 		}
 		}
 		// Converting from PF_X8R8G8B8 is exactly the same as converting from
 		// Converting from PF_X8R8G8B8 is exactly the same as converting from
 		// PF_A8R8G8B8, given that the destination format does not have alpha.
 		// PF_A8R8G8B8, given that the destination format does not have alpha.
-		if((src.format == PF_X8R8G8B8||src.format == PF_X8B8G8R8) && !hasAlpha(dst.format))
+		if((src.getFormat() == PF_X8R8G8B8||src.getFormat() == PF_X8B8G8R8) && !hasAlpha(dst.getFormat()))
 		{
 		{
 			// Do the same conversion, with PF_A8R8G8B8, which has a lot of
 			// Do the same conversion, with PF_A8R8G8B8, which has a lot of
 			// optimized conversions
 			// optimized conversions
-			PixelData tempsrc = src;
-			tempsrc.format = src.format==PF_X8R8G8B8?PF_A8R8G8B8:PF_A8B8G8R8;
+			PixelFormat tempFormat = src.getFormat()==PF_X8R8G8B8?PF_A8R8G8B8:PF_A8B8G8R8;
+			PixelData tempsrc(src.getWidth(), src.getHeight(), src.getDepth(), tempFormat);
+			tempsrc.setExternalBuffer(src.getData());
 			bulkPixelConversion(tempsrc, dst);
 			bulkPixelConversion(tempsrc, dst);
 			return;
 			return;
 		}
 		}
 
 
-        const size_t srcPixelSize = PixelUtil::getNumElemBytes(src.format);
-        const size_t dstPixelSize = PixelUtil::getNumElemBytes(dst.format);
+        const size_t srcPixelSize = PixelUtil::getNumElemBytes(src.getFormat());
+        const size_t dstPixelSize = PixelUtil::getNumElemBytes(dst.getFormat());
         UINT8 *srcptr = static_cast<UINT8*>(src.getData())
         UINT8 *srcptr = static_cast<UINT8*>(src.getData())
-            + (src.getLeft() + src.getTop() * src.rowPitch + src.getFront() * src.slicePitch) * srcPixelSize;
+            + (src.getLeft() + src.getTop() * src.getRowPitch() + src.getFront() * src.getSlicePitch()) * srcPixelSize;
         UINT8 *dstptr = static_cast<UINT8*>(dst.getData())
         UINT8 *dstptr = static_cast<UINT8*>(dst.getData())
-            + (dst.getLeft() + dst.getTop() * dst.rowPitch + dst.getFront() * dst.slicePitch) * dstPixelSize;
+            + (dst.getLeft() + dst.getTop() * dst.getRowPitch() + dst.getFront() * dst.getSlicePitch()) * dstPixelSize;
 		
 		
 		// Old way, not taking into account box dimensions
 		// Old way, not taking into account box dimensions
 		//UINT8 *srcptr = static_cast<UINT8*>(src.data), *dstptr = static_cast<UINT8*>(dst.data);
 		//UINT8 *srcptr = static_cast<UINT8*>(src.data), *dstptr = static_cast<UINT8*>(dst.data);
@@ -1336,8 +1337,8 @@ namespace CamelotFramework {
             {
             {
                 for(size_t x=src.getLeft(); x<src.getRight(); x++)
                 for(size_t x=src.getLeft(); x<src.getRight(); x++)
                 {
                 {
-                    unpackColour(&r, &g, &b, &a, src.format, srcptr);
-                    packColour(r, g, b, a, dst.format, dstptr);
+                    unpackColour(&r, &g, &b, &a, src.getFormat(), srcptr);
+                    packColour(r, g, b, a, dst.getFormat(), dstptr);
                     srcptr += srcPixelSize;
                     srcptr += srcPixelSize;
                     dstptr += dstPixelSize;
                     dstptr += dstPixelSize;
                 }
                 }
@@ -1351,15 +1352,15 @@ namespace CamelotFramework {
 
 
 	void PixelUtil::scale(const PixelData &src, const PixelData &scaled, Filter filter)
 	void PixelUtil::scale(const PixelData &src, const PixelData &scaled, Filter filter)
 	{
 	{
-		assert(PixelUtil::isAccessible(src.format));
-		assert(PixelUtil::isAccessible(scaled.format));
+		assert(PixelUtil::isAccessible(src.getFormat()));
+		assert(PixelUtil::isAccessible(scaled.getFormat()));
 
 
 		PixelData temp;
 		PixelData temp;
 		switch (filter) 
 		switch (filter) 
 		{
 		{
 		default:
 		default:
 		case FILTER_NEAREST:
 		case FILTER_NEAREST:
-			if(src.format == scaled.format) 
+			if(src.getFormat() == scaled.getFormat()) 
 			{
 			{
 				// No intermediate buffer needed
 				// No intermediate buffer needed
 				temp = scaled;
 				temp = scaled;
@@ -1367,11 +1368,11 @@ namespace CamelotFramework {
 			else
 			else
 			{
 			{
 				// Allocate temporary buffer of destination size in source format 
 				// Allocate temporary buffer of destination size in source format 
-				temp = PixelData(scaled.getWidth(), scaled.getHeight(), scaled.getDepth(), src.format);
+				temp = PixelData(scaled.getWidth(), scaled.getHeight(), scaled.getDepth(), src.getFormat());
 				temp.allocateInternalBuffer(temp.getConsecutiveSize());
 				temp.allocateInternalBuffer(temp.getConsecutiveSize());
 			}
 			}
 			// super-optimized: no conversion
 			// super-optimized: no conversion
-			switch (PixelUtil::getNumElemBytes(src.format)) 
+			switch (PixelUtil::getNumElemBytes(src.getFormat())) 
 			{
 			{
 			case 1: NearestResampler<1>::scale(src, temp); break;
 			case 1: NearestResampler<1>::scale(src, temp); break;
 			case 2: NearestResampler<2>::scale(src, temp); break;
 			case 2: NearestResampler<2>::scale(src, temp); break;
@@ -1396,14 +1397,14 @@ namespace CamelotFramework {
 
 
 		case FILTER_LINEAR:
 		case FILTER_LINEAR:
 		case FILTER_BILINEAR:
 		case FILTER_BILINEAR:
-			switch (src.format) 
+			switch (src.getFormat()) 
 			{
 			{
 			case PF_R8G8:
 			case PF_R8G8:
 			case PF_R8G8B8: case PF_B8G8R8:
 			case PF_R8G8B8: case PF_B8G8R8:
 			case PF_R8G8B8A8: case PF_B8G8R8A8:
 			case PF_R8G8B8A8: case PF_B8G8R8A8:
 			case PF_A8B8G8R8: case PF_A8R8G8B8:
 			case PF_A8B8G8R8: case PF_A8R8G8B8:
 			case PF_X8B8G8R8: case PF_X8R8G8B8:
 			case PF_X8B8G8R8: case PF_X8R8G8B8:
-				if(src.format == scaled.format) 
+				if(src.getFormat() == scaled.getFormat()) 
 				{
 				{
 					// No intermediate buffer needed
 					// No intermediate buffer needed
 					temp = scaled;
 					temp = scaled;
@@ -1411,11 +1412,11 @@ namespace CamelotFramework {
 				else
 				else
 				{
 				{
 					// Allocate temp buffer of destination size in source format 
 					// Allocate temp buffer of destination size in source format 
-					temp = PixelData(scaled.getWidth(), scaled.getHeight(), scaled.getDepth(), src.format);
+					temp = PixelData(scaled.getWidth(), scaled.getHeight(), scaled.getDepth(), src.getFormat());
 					temp.allocateInternalBuffer(temp.getConsecutiveSize());
 					temp.allocateInternalBuffer(temp.getConsecutiveSize());
 				}
 				}
 				// super-optimized: byte-oriented math, no conversion
 				// super-optimized: byte-oriented math, no conversion
-				switch (PixelUtil::getNumElemBytes(src.format)) 
+				switch (PixelUtil::getNumElemBytes(src.getFormat())) 
 				{
 				{
 				case 1: LinearResampler_Byte<1>::scale(src, temp); break;
 				case 1: LinearResampler_Byte<1>::scale(src, temp); break;
 				case 2: LinearResampler_Byte<2>::scale(src, temp); break;
 				case 2: LinearResampler_Byte<2>::scale(src, temp); break;
@@ -1434,7 +1435,7 @@ namespace CamelotFramework {
 				break;
 				break;
 			case PF_FLOAT32_RGB:
 			case PF_FLOAT32_RGB:
 			case PF_FLOAT32_RGBA:
 			case PF_FLOAT32_RGBA:
-				if (scaled.format == PF_FLOAT32_RGB || scaled.format == PF_FLOAT32_RGBA)
+				if (scaled.getFormat() == PF_FLOAT32_RGB || scaled.getFormat() == PF_FLOAT32_RGBA)
 				{
 				{
 					// float32 to float32, avoid unpack/repack overhead
 					// float32 to float32, avoid unpack/repack overhead
 					LinearResampler_Float32::scale(src, scaled);
 					LinearResampler_Float32::scale(src, scaled);
@@ -1493,17 +1494,17 @@ namespace CamelotFramework {
     {
     {
         Color cv;
         Color cv;
 
 
-        UINT32 pixelSize = PixelUtil::getNumElemBytes(format);
-        UINT32 pixelOffset = pixelSize * (z * slicePitch + y * rowPitch + x);
-        PixelUtil::unpackColour(&cv, format, (unsigned char *)getData() + pixelOffset);
+        UINT32 pixelSize = PixelUtil::getNumElemBytes(mFormat);
+        UINT32 pixelOffset = pixelSize * (z * mSlicePitch + y * mRowPitch + x);
+        PixelUtil::unpackColour(&cv, mFormat, (unsigned char *)getData() + pixelOffset);
 
 
         return cv;
         return cv;
     }
     }
 
 
     void PixelData::setColourAt(Color const &cv, UINT32 x, UINT32 y, UINT32 z)
     void PixelData::setColourAt(Color const &cv, UINT32 x, UINT32 y, UINT32 z)
     {
     {
-        UINT32 pixelSize = PixelUtil::getNumElemBytes(format);
-        UINT32 pixelOffset = pixelSize * (z * slicePitch + y * rowPitch + x);
-        PixelUtil::packColour(cv, format, (unsigned char *)getData() + pixelOffset);
+        UINT32 pixelSize = PixelUtil::getNumElemBytes(mFormat);
+        UINT32 pixelOffset = pixelSize * (z * mSlicePitch + y * mRowPitch + x);
+        PixelUtil::packColour(cv, mFormat, (unsigned char *)getData() + pixelOffset);
     }
     }
 }
 }

+ 3 - 1
CamelotCore/Source/CmTexture.cpp

@@ -140,7 +140,9 @@ namespace CamelotFramework {
 
 
 		PixelDataPtr dst(CM_NEW(PixelData, PoolAlloc) PixelData(width, height, depth, getFormat()),
 		PixelDataPtr dst(CM_NEW(PixelData, PoolAlloc) PixelData(width, height, depth, getFormat()),
 			&MemAllocDeleter<PixelData, PoolAlloc>::deleter);
 			&MemAllocDeleter<PixelData, PoolAlloc>::deleter);
-		UINT8* buffer = (UINT8*)dst->allocateInternalBuffer(totalSize);
+
+		dst->allocateInternalBuffer(totalSize);
+		UINT8* buffer = (UINT8*)dst->getData();
 
 
 		PixelData myData = lock(GBL_READ_ONLY, mip, face);
 		PixelData myData = lock(GBL_READ_ONLY, mip, face);
 
 

+ 2 - 1
CamelotD3D11RenderSystem/Source/CmD3D11Texture.cpp

@@ -519,8 +519,9 @@ namespace CamelotFramework
 		mLockedSubresourceIdx = D3D11CalcSubresource(mipLevel, face, getNumMipmaps()+1);
 		mLockedSubresourceIdx = D3D11CalcSubresource(mipLevel, face, getNumMipmaps()+1);
 
 
 		mStaticBuffer = CM_NEW(PixelData, PoolAlloc) PixelData(lock.getWidth(), lock.getHeight(), lock.getDepth(), lock.getFormat());
 		mStaticBuffer = CM_NEW(PixelData, PoolAlloc) PixelData(lock.getWidth(), lock.getHeight(), lock.getDepth(), lock.getFormat());
+		mStaticBuffer->allocateInternalBuffer(sizeOfImage);
 
 
-		return mStaticBuffer->allocateInternalBuffer(sizeOfImage);
+		return mStaticBuffer->getData();
 	}
 	}
 
 
 	void D3D11Texture::_unmapstaticbuffer()
 	void D3D11Texture::_unmapstaticbuffer()

+ 2 - 2
CamelotD3D9Renderer/Source/CmD3D9Device.cpp

@@ -1328,8 +1328,8 @@ namespace CamelotFramework
 
 
 		PixelData src(dst.getWidth(), dst.getHeight(), 1, format);
 		PixelData src(dst.getWidth(), dst.getHeight(), 1, format);
 		src.setExternalBuffer((UINT8*)lockedRect.pBits);
 		src.setExternalBuffer((UINT8*)lockedRect.pBits);
-		src.rowPitch = lockedRect.Pitch / PixelUtil::getNumElemBytes(format);
-		src.slicePitch = desc.Height * src.rowPitch;
+		src.setRowPitch(lockedRect.Pitch / PixelUtil::getNumElemBytes(format));
+		src.setSlicePitch(desc.Height * src.getRowPitch());
 
 
 		PixelUtil::bulkPixelConversion(src, dst);
 		PixelUtil::bulkPixelConversion(src, dst);
 
 

+ 27 - 27
CamelotD3D9Renderer/Source/CmD3D9PixelBuffer.cpp

@@ -239,17 +239,17 @@ namespace CamelotFramework
 	// Util functions to convert a D3D locked box to a pixel box
 	// Util functions to convert a D3D locked box to a pixel box
 	void fromD3DLock(PixelData &rval, const D3DLOCKED_RECT &lrect)
 	void fromD3DLock(PixelData &rval, const D3DLOCKED_RECT &lrect)
 	{
 	{
-		UINT32 bpp = PixelUtil::getNumElemBytes(rval.format);
+		UINT32 bpp = PixelUtil::getNumElemBytes(rval.getFormat());
 		if (bpp != 0)
 		if (bpp != 0)
 		{
 		{
-			rval.rowPitch = lrect.Pitch / bpp;
-			rval.slicePitch = rval.rowPitch * rval.getHeight();
+			rval.setRowPitch(lrect.Pitch / bpp);
+			rval.setSlicePitch(rval.getRowPitch() * rval.getHeight());
 			assert((lrect.Pitch % bpp)==0);
 			assert((lrect.Pitch % bpp)==0);
 		}
 		}
-		else if (PixelUtil::isCompressed(rval.format))
+		else if (PixelUtil::isCompressed(rval.getFormat()))
 		{
 		{
-			rval.rowPitch = rval.getWidth();
-			rval.slicePitch = rval.getWidth() * rval.getHeight();
+			rval.setRowPitch(rval.getWidth());
+			rval.setSlicePitch(rval.getWidth() * rval.getHeight());
 		}
 		}
 		else
 		else
 		{
 		{
@@ -260,18 +260,18 @@ namespace CamelotFramework
 	}
 	}
 	void fromD3DLock(PixelData &rval, const D3DLOCKED_BOX &lbox)
 	void fromD3DLock(PixelData &rval, const D3DLOCKED_BOX &lbox)
 	{
 	{
-		UINT32 bpp = PixelUtil::getNumElemBytes(rval.format);
+		UINT32 bpp = PixelUtil::getNumElemBytes(rval.getFormat());
 		if (bpp != 0)
 		if (bpp != 0)
 		{
 		{
-			rval.rowPitch = lbox.RowPitch / bpp;
-			rval.slicePitch = lbox.SlicePitch / bpp;
+			rval.setRowPitch(lbox.RowPitch / bpp);
+			rval.setSlicePitch(lbox.SlicePitch / bpp);
 			assert((lbox.RowPitch % bpp)==0);
 			assert((lbox.RowPitch % bpp)==0);
 			assert((lbox.SlicePitch % bpp)==0);
 			assert((lbox.SlicePitch % bpp)==0);
 		}
 		}
-		else if (PixelUtil::isCompressed(rval.format))
+		else if (PixelUtil::isCompressed(rval.getFormat()))
 		{
 		{
-			rval.rowPitch = rval.getWidth();
-			rval.slicePitch = rval.getWidth() * rval.getHeight();
+			rval.setRowPitch(rval.getWidth());
+			rval.setSlicePitch(rval.getWidth() * rval.getHeight());
 		}
 		}
 		else
 		else
 		{
 		{
@@ -601,7 +601,7 @@ namespace CamelotFramework
 		PixelData converted = src;
 		PixelData converted = src;
 
 
 		// convert to pixelbuffer's native format if necessary
 		// convert to pixelbuffer's native format if necessary
-		if (D3D9Mappings::_getPF(src.format) == D3DFMT_UNKNOWN)
+		if (D3D9Mappings::_getPF(src.getFormat()) == D3DFMT_UNKNOWN)
 		{
 		{
 			converted = PixelData(src.getWidth(), src.getHeight(), src.getDepth(), mFormat);
 			converted = PixelData(src.getWidth(), src.getHeight(), src.getDepth(), mFormat);
 			converted.allocateInternalBuffer(PixelUtil::getMemorySize(src.getWidth(), src.getHeight(), src.getDepth(), mFormat));
 			converted.allocateInternalBuffer(PixelUtil::getMemorySize(src.getWidth(), src.getHeight(), src.getDepth(), mFormat));
@@ -609,24 +609,24 @@ namespace CamelotFramework
 		}
 		}
 
 
 		UINT32 rowWidth;
 		UINT32 rowWidth;
-		if (PixelUtil::isCompressed(converted.format))
+		if (PixelUtil::isCompressed(converted.getFormat()))
 		{
 		{
 			// D3D wants the width of one row of cells in bytes
 			// D3D wants the width of one row of cells in bytes
-			if (converted.format == PF_DXT1)
+			if (converted.getFormat() == PF_DXT1)
 			{
 			{
 				// 64 bits (8 bytes) per 4x4 block
 				// 64 bits (8 bytes) per 4x4 block
-				rowWidth = (converted.rowPitch / 4) * 8;
+				rowWidth = (converted.getRowPitch() / 4) * 8;
 			}
 			}
 			else
 			else
 			{
 			{
 				// 128 bits (16 bytes) per 4x4 block
 				// 128 bits (16 bytes) per 4x4 block
-				rowWidth = (converted.rowPitch / 4) * 16;
+				rowWidth = (converted.getRowPitch() / 4) * 16;
 			}
 			}
 
 
 		}
 		}
 		else
 		else
 		{
 		{
-			rowWidth = converted.rowPitch * PixelUtil::getNumElemBytes(converted.format);
+			rowWidth = converted.getRowPitch() * PixelUtil::getNumElemBytes(converted.getFormat());
 		}
 		}
 
 
 		if (dstBufferResources->surface)
 		if (dstBufferResources->surface)
@@ -636,7 +636,7 @@ namespace CamelotFramework
 			destRect = toD3DRECT(dstBox);
 			destRect = toD3DRECT(dstBox);
 
 
 			if(D3DXLoadSurfaceFromMemory(dstBufferResources->surface, NULL, &destRect, 
 			if(D3DXLoadSurfaceFromMemory(dstBufferResources->surface, NULL, &destRect, 
-				converted.getData(), D3D9Mappings::_getPF(converted.format),
+				converted.getData(), D3D9Mappings::_getPF(converted.getFormat()),
 				static_cast<UINT>(rowWidth),
 				static_cast<UINT>(rowWidth),
 				NULL, &srcRect, D3DX_DEFAULT, 0) != D3D_OK)
 				NULL, &srcRect, D3DX_DEFAULT, 0) != D3D_OK)
 			{
 			{
@@ -649,28 +649,28 @@ namespace CamelotFramework
 			srcBox = toD3DBOX(converted.getExtents());
 			srcBox = toD3DBOX(converted.getExtents());
 			destBox = toD3DBOX(dstBox);
 			destBox = toD3DBOX(dstBox);
 			UINT32 sliceWidth;
 			UINT32 sliceWidth;
-			if (PixelUtil::isCompressed(converted.format))
+			if (PixelUtil::isCompressed(converted.getFormat()))
 			{
 			{
 				// D3D wants the width of one slice of cells in bytes
 				// D3D wants the width of one slice of cells in bytes
-				if (converted.format == PF_DXT1)
+				if (converted.getFormat() == PF_DXT1)
 				{
 				{
 					// 64 bits (8 bytes) per 4x4 block
 					// 64 bits (8 bytes) per 4x4 block
-					sliceWidth = (converted.slicePitch / 16) * 8;
+					sliceWidth = (converted.getSlicePitch() / 16) * 8;
 				}
 				}
 				else
 				else
 				{
 				{
 					// 128 bits (16 bytes) per 4x4 block
 					// 128 bits (16 bytes) per 4x4 block
-					sliceWidth = (converted.slicePitch / 16) * 16;
+					sliceWidth = (converted.getSlicePitch() / 16) * 16;
 				}
 				}
 
 
 			}
 			}
 			else
 			else
 			{
 			{
-				sliceWidth = converted.slicePitch * PixelUtil::getNumElemBytes(converted.format);
+				sliceWidth = converted.getSlicePitch() * PixelUtil::getNumElemBytes(converted.getFormat());
 			}
 			}
 
 
 			if(D3DXLoadVolumeFromMemory(dstBufferResources->volume, NULL, &destBox, 
 			if(D3DXLoadVolumeFromMemory(dstBufferResources->volume, NULL, &destBox, 
-				converted.getData(), D3D9Mappings::_getPF(converted.format),
+				converted.getData(), D3D9Mappings::_getPF(converted.getFormat()),
 				static_cast<UINT>(rowWidth), static_cast<UINT>(sliceWidth),
 				static_cast<UINT>(rowWidth), static_cast<UINT>(sliceWidth),
 				NULL, &srcBox, D3DX_DEFAULT, 0) != D3D_OK)
 				NULL, &srcBox, D3DX_DEFAULT, 0) != D3D_OK)
 			{
 			{
@@ -702,9 +702,9 @@ namespace CamelotFramework
 	{
 	{
 		// Decide on pixel format of temp surface
 		// Decide on pixel format of temp surface
 		PixelFormat tmpFormat = mFormat; 
 		PixelFormat tmpFormat = mFormat; 
-		if(D3D9Mappings::_getPF(dst.format) != D3DFMT_UNKNOWN)
+		if(D3D9Mappings::_getPF(dst.getFormat()) != D3DFMT_UNKNOWN)
 		{
 		{
-			tmpFormat = dst.format;
+			tmpFormat = dst.getFormat();
 		}
 		}
 
 
 		if (srcBufferResources->surface)
 		if (srcBufferResources->surface)

+ 2 - 1
CamelotFontImporter/Source/CmFontImporter.cpp

@@ -133,7 +133,8 @@ namespace CamelotFramework
 
 
 				PixelData pixelData(pageIter->width, pageIter->height, 1, PF_R8G8);
 				PixelData pixelData(pageIter->width, pageIter->height, 1, PF_R8G8);
 
 
-				UINT8* pixelBuffer = pixelData.allocateInternalBuffer(bufferSize);
+				pixelData.allocateInternalBuffer(bufferSize);
+				UINT8* pixelBuffer = pixelData.getData();
 				memset(pixelBuffer, 0, bufferSize);
 				memset(pixelBuffer, 0, bufferSize);
 
 
 				for(size_t elementIdx = 0; elementIdx < atlasElements.size(); elementIdx++)
 				for(size_t elementIdx = 0; elementIdx < atlasElements.size(); elementIdx++)

+ 24 - 24
CamelotGLRenderer/Source/CmGLPixelBuffer.cpp

@@ -114,7 +114,7 @@ namespace CamelotFramework
 			scaled = mBuffer.getSubVolume(dstBox);
 			scaled = mBuffer.getSubVolume(dstBox);
 			PixelUtil::scale(src, scaled, PixelUtil::FILTER_BILINEAR);
 			PixelUtil::scale(src, scaled, PixelUtil::FILTER_BILINEAR);
 		}
 		}
-		else if(GLPixelUtil::getGLOriginFormat(src.format) == 0)
+		else if(GLPixelUtil::getGLOriginFormat(src.getFormat()) == 0)
 		{
 		{
 			// Extents match, but format is not accepted as valid source format for GL
 			// Extents match, but format is not accepted as valid source format for GL
 			// do conversion in temporary buffer
 			// do conversion in temporary buffer
@@ -143,7 +143,7 @@ namespace CamelotFramework
 		   dst.getWidth() == getWidth() &&
 		   dst.getWidth() == getWidth() &&
 		   dst.getHeight() == getHeight() &&
 		   dst.getHeight() == getHeight() &&
 		   dst.getDepth() == getDepth() &&
 		   dst.getDepth() == getDepth() &&
-		   GLPixelUtil::getGLOriginFormat(dst.format) != 0)
+		   GLPixelUtil::getGLOriginFormat(dst.getFormat()) != 0)
 		{
 		{
 			// The direct case: the user wants the entire texture in a format supported by GL
 			// The direct case: the user wants the entire texture in a format supported by GL
 			// so we don't need an intermediate buffer
 			// so we don't need an intermediate buffer
@@ -248,9 +248,9 @@ namespace CamelotFramework
 			CM_EXCEPT(NotImplementedException, "Writing to render texture from CPU not supported.");
 			CM_EXCEPT(NotImplementedException, "Writing to render texture from CPU not supported.");
 
 
 		glBindTexture( mTarget, mTextureID );
 		glBindTexture( mTarget, mTextureID );
-		if(PixelUtil::isCompressed(data.format))
+		if(PixelUtil::isCompressed(data.getFormat()))
 		{
 		{
-			if(data.format != mFormat || !data.isConsecutive())
+			if(data.getFormat() != mFormat || !data.isConsecutive())
 				CM_EXCEPT(InvalidParametersException, 
 				CM_EXCEPT(InvalidParametersException, 
 				"Compressed images must be consecutive, in the source format");
 				"Compressed images must be consecutive, in the source format");
 			GLenum format = GLPixelUtil::getClosestGLInternalFormat(mFormat);
 			GLenum format = GLPixelUtil::getClosestGLInternalFormat(mFormat);
@@ -329,13 +329,13 @@ namespace CamelotFramework
 		} 
 		} 
 		else
 		else
 		{
 		{
-			if(data.getWidth() != data.rowPitch)
-				glPixelStorei(GL_UNPACK_ROW_LENGTH, data.rowPitch);
-			if(data.getHeight()*data.getWidth() != data.slicePitch)
-				glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, (data.slicePitch/data.getWidth()));
+			if(data.getWidth() != data.getRowPitch())
+				glPixelStorei(GL_UNPACK_ROW_LENGTH, data.getRowPitch());
+			if(data.getHeight()*data.getWidth() != data.getSlicePitch())
+				glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, (data.getSlicePitch()/data.getWidth()));
 			if(data.getLeft() > 0 || data.getTop() > 0 || data.getFront() > 0)
 			if(data.getLeft() > 0 || data.getTop() > 0 || data.getFront() > 0)
-				glPixelStorei(GL_UNPACK_SKIP_PIXELS, data.getLeft() + data.rowPitch * data.getTop() + data.slicePitch * data.getFront());
-			if((data.getWidth()*PixelUtil::getNumElemBytes(data.format)) & 3) {
+				glPixelStorei(GL_UNPACK_SKIP_PIXELS, data.getLeft() + data.getRowPitch() * data.getTop() + data.getSlicePitch() * data.getFront());
+			if((data.getWidth()*PixelUtil::getNumElemBytes(data.getFormat())) & 3) {
 				// Standard alignment of 4 is not right
 				// Standard alignment of 4 is not right
 				glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 				glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 			}
 			}
@@ -344,7 +344,7 @@ namespace CamelotFramework
 					glTexSubImage1D(GL_TEXTURE_1D, mLevel, 
 					glTexSubImage1D(GL_TEXTURE_1D, mLevel, 
 						dest.left,
 						dest.left,
 						dest.getWidth(),
 						dest.getWidth(),
-						GLPixelUtil::getGLOriginFormat(data.format), GLPixelUtil::getGLOriginDataType(data.format),
+						GLPixelUtil::getGLOriginFormat(data.getFormat()), GLPixelUtil::getGLOriginDataType(data.getFormat()),
 						data.getData());
 						data.getData());
 					break;
 					break;
 				case GL_TEXTURE_2D:
 				case GL_TEXTURE_2D:
@@ -352,7 +352,7 @@ namespace CamelotFramework
 					glTexSubImage2D(mFaceTarget, mLevel, 
 					glTexSubImage2D(mFaceTarget, mLevel, 
 						dest.left, dest.top, 
 						dest.left, dest.top, 
 						dest.getWidth(), dest.getHeight(),
 						dest.getWidth(), dest.getHeight(),
-						GLPixelUtil::getGLOriginFormat(data.format), GLPixelUtil::getGLOriginDataType(data.format),
+						GLPixelUtil::getGLOriginFormat(data.getFormat()), GLPixelUtil::getGLOriginDataType(data.getFormat()),
 						data.getData());
 						data.getData());
 					break;
 					break;
 				case GL_TEXTURE_3D:
 				case GL_TEXTURE_3D:
@@ -360,7 +360,7 @@ namespace CamelotFramework
 						GL_TEXTURE_3D, mLevel, 
 						GL_TEXTURE_3D, mLevel, 
 						dest.left, dest.top, dest.front,
 						dest.left, dest.top, dest.front,
 						dest.getWidth(), dest.getHeight(), dest.getDepth(),
 						dest.getWidth(), dest.getHeight(), dest.getDepth(),
-						GLPixelUtil::getGLOriginFormat(data.format), GLPixelUtil::getGLOriginDataType(data.format),
+						GLPixelUtil::getGLOriginFormat(data.getFormat()), GLPixelUtil::getGLOriginDataType(data.getFormat()),
 						data.getData());
 						data.getData());
 					break;
 					break;
 			}	
 			}	
@@ -386,9 +386,9 @@ namespace CamelotFramework
 			data.getDepth() != getDepth())
 			data.getDepth() != getDepth())
 			CM_EXCEPT(InvalidParametersException, "only download of entire buffer is supported by GL");
 			CM_EXCEPT(InvalidParametersException, "only download of entire buffer is supported by GL");
 		glBindTexture( mTarget, mTextureID );
 		glBindTexture( mTarget, mTextureID );
-		if(PixelUtil::isCompressed(data.format))
+		if(PixelUtil::isCompressed(data.getFormat()))
 		{
 		{
-			if(data.format != mFormat || !data.isConsecutive())
+			if(data.getFormat() != mFormat || !data.isConsecutive())
 				CM_EXCEPT(InvalidParametersException, 
 				CM_EXCEPT(InvalidParametersException, 
 				"Compressed images must be consecutive, in the source format");
 				"Compressed images must be consecutive, in the source format");
 			// Data must be consecutive and at beginning of buffer as PixelStorei not allowed
 			// Data must be consecutive and at beginning of buffer as PixelStorei not allowed
@@ -397,19 +397,19 @@ namespace CamelotFramework
 		} 
 		} 
 		else
 		else
 		{
 		{
-			if(data.getWidth() != data.rowPitch)
-				glPixelStorei(GL_PACK_ROW_LENGTH, data.rowPitch);
-			if(data.getHeight()*data.getWidth() != data.slicePitch)
-				glPixelStorei(GL_PACK_IMAGE_HEIGHT, (data.slicePitch/data.getWidth()));
+			if(data.getWidth() != data.getRowPitch())
+				glPixelStorei(GL_PACK_ROW_LENGTH, data.getRowPitch());
+			if(data.getHeight()*data.getWidth() != data.getSlicePitch())
+				glPixelStorei(GL_PACK_IMAGE_HEIGHT, (data.getSlicePitch()/data.getWidth()));
 			if(data.getLeft() > 0 || data.getTop() > 0 || data.getFront() > 0)
 			if(data.getLeft() > 0 || data.getTop() > 0 || data.getFront() > 0)
-				glPixelStorei(GL_PACK_SKIP_PIXELS, data.getLeft() + data.rowPitch * data.getTop() + data.slicePitch * data.getFront());
-			if((data.getWidth()*PixelUtil::getNumElemBytes(data.format)) & 3) {
+				glPixelStorei(GL_PACK_SKIP_PIXELS, data.getLeft() + data.getRowPitch() * data.getTop() + data.getSlicePitch() * data.getFront());
+			if((data.getWidth()*PixelUtil::getNumElemBytes(data.getFormat())) & 3) {
 				// Standard alignment of 4 is not right
 				// Standard alignment of 4 is not right
 				glPixelStorei(GL_PACK_ALIGNMENT, 1);
 				glPixelStorei(GL_PACK_ALIGNMENT, 1);
 			}
 			}
 			// We can only get the entire texture
 			// We can only get the entire texture
 			glGetTexImage(mFaceTarget, mLevel, 
 			glGetTexImage(mFaceTarget, mLevel, 
-				GLPixelUtil::getGLOriginFormat(data.format), GLPixelUtil::getGLOriginDataType(data.format),
+				GLPixelUtil::getGLOriginFormat(data.getFormat()), GLPixelUtil::getGLOriginDataType(data.getFormat()),
 				data.getData());
 				data.getData());
 			// Restore defaults
 			// Restore defaults
 			glPixelStorei(GL_PACK_ROW_LENGTH, 0);
 			glPixelStorei(GL_PACK_ROW_LENGTH, 0);
@@ -693,7 +693,7 @@ namespace CamelotFramework
 		PixelData src;
 		PixelData src;
     
     
 		/// First, convert the srcbox to a OpenGL compatible pixel format
 		/// First, convert the srcbox to a OpenGL compatible pixel format
-		if(GLPixelUtil::getGLOriginFormat(src_orig.format) == 0)
+		if(GLPixelUtil::getGLOriginFormat(src_orig.getFormat()) == 0)
 		{
 		{
 			/// Convert to buffer internal format
 			/// Convert to buffer internal format
 			src = PixelData(src_orig.getWidth(), src_orig.getHeight(), src_orig.getDepth(), mFormat);
 			src = PixelData(src_orig.getWidth(), src_orig.getHeight(), src_orig.getDepth(), mFormat);
@@ -712,7 +712,7 @@ namespace CamelotFramework
 		GLsizei width = GLPixelUtil::optionalPO2(src.getWidth());
 		GLsizei width = GLPixelUtil::optionalPO2(src.getWidth());
 		GLsizei height = GLPixelUtil::optionalPO2(src.getHeight());
 		GLsizei height = GLPixelUtil::optionalPO2(src.getHeight());
 		GLsizei depth = GLPixelUtil::optionalPO2(src.getDepth());
 		GLsizei depth = GLPixelUtil::optionalPO2(src.getDepth());
-		GLenum format = GLPixelUtil::getClosestGLInternalFormat(src.format);
+		GLenum format = GLPixelUtil::getClosestGLInternalFormat(src.getFormat());
     
     
 		/// Generate texture name
 		/// Generate texture name
 		glGenTextures(1, &id);
 		glGenTextures(1, &id);

+ 3 - 3
CamelotGLRenderer/Source/CmWin32Window.cpp

@@ -638,8 +638,8 @@ namespace CamelotFramework {
 			buffer = mIsFullScreen? FB_FRONT : FB_BACK;
 			buffer = mIsFullScreen? FB_FRONT : FB_BACK;
 		}
 		}
 
 
-		GLenum format = CamelotFramework::GLPixelUtil::getGLOriginFormat(dst.format);
-		GLenum type = CamelotFramework::GLPixelUtil::getGLOriginDataType(dst.format);
+		GLenum format = CamelotFramework::GLPixelUtil::getGLOriginFormat(dst.getFormat());
+		GLenum type = CamelotFramework::GLPixelUtil::getGLOriginDataType(dst.getFormat());
 
 
 		if ((format == GL_NONE) || (type == 0))
 		if ((format == GL_NONE) || (type == 0))
 		{
 		{
@@ -659,7 +659,7 @@ namespace CamelotFramework {
 
 
 		//vertical flip
 		//vertical flip
 		{
 		{
-			size_t rowSpan = dst.getWidth() * PixelUtil::getNumElemBytes(dst.format);
+			size_t rowSpan = dst.getWidth() * PixelUtil::getNumElemBytes(dst.getFormat());
 			size_t height = dst.getHeight();
 			size_t height = dst.getHeight();
 			UINT8 *tmpData = CM_NEW_BYTES((UINT32)(rowSpan * height), ScratchAlloc);
 			UINT8 *tmpData = CM_NEW_BYTES((UINT32)(rowSpan * height), ScratchAlloc);
 			UINT8 *srcRow = (UINT8 *)dst.getData(), *tmpRow = tmpData + (height - 1) * rowSpan;
 			UINT8 *srcRow = (UINT8 *)dst.getData(), *tmpRow = tmpData + (height - 1) * rowSpan;

+ 15 - 9
CamelotUtility/Include/CmRTTIManagedDataBlockField.h

@@ -8,18 +8,12 @@ namespace CamelotFramework
 {
 {
 	struct RTTIManagedDataBlockFieldBase : public RTTIField
 	struct RTTIManagedDataBlockFieldBase : public RTTIField
 	{
 	{
-		boost::function<UINT8*(UINT32)> mCustomAllocator;
+		boost::any mCustomAllocator;
 
 
 		virtual ManagedDataBlock getValue(void* object) = 0;
 		virtual ManagedDataBlock getValue(void* object) = 0;
 		virtual void setValue(void* object, ManagedDataBlock value) = 0;
 		virtual void setValue(void* object, ManagedDataBlock value) = 0;
 
 
-		UINT8* allocate(UINT32 bytes)
-		{
-			if(mCustomAllocator.empty())
-				return CM_NEW_BYTES(bytes, ScratchAlloc);
-			else
-				return mCustomAllocator(bytes);
-		}
+		virtual UINT8* allocate(void* object, UINT32 bytes) = 0;
 	};
 	};
 
 
 	template <class DataType, class ObjectType>
 	template <class DataType, class ObjectType>
@@ -38,7 +32,7 @@ namespace CamelotFramework
 		 * @param	flags		Various flags you can use to specialize how systems handle this field
 		 * @param	flags		Various flags you can use to specialize how systems handle this field
 		 * @param	customAllocator (optional) Custom allocator that will be used when de-serializing DataBlock memory.
 		 * @param	customAllocator (optional) Custom allocator that will be used when de-serializing DataBlock memory.
 		 */
 		 */
-		void initSingle(const std::string& name, UINT16 uniqueId, boost::any getter, boost::any setter, UINT64 flags, boost::function<UINT8*(UINT32)> customAllocator = 0)
+		void initSingle(const std::string& name, UINT16 uniqueId, boost::any getter, boost::any setter, UINT64 flags, boost::any customAllocator = boost::any())
 		{
 		{
 			initAll(getter, setter, nullptr, nullptr, name, uniqueId, false, SerializableFT_DataBlock, flags);
 			initAll(getter, setter, nullptr, nullptr, name, uniqueId, false, SerializableFT_DataBlock, flags);
 			mCustomAllocator = customAllocator;
 			mCustomAllocator = customAllocator;
@@ -79,5 +73,17 @@ namespace CamelotFramework
 			boost::function<void(ObjectType*, ManagedDataBlock)> f = boost::any_cast<boost::function<void(ObjectType*, ManagedDataBlock)>>(valueSetter);
 			boost::function<void(ObjectType*, ManagedDataBlock)> f = boost::any_cast<boost::function<void(ObjectType*, ManagedDataBlock)>>(valueSetter);
 			f(castObj, value);
 			f(castObj, value);
 		}
 		}
+
+		virtual UINT8* allocate(void* object, UINT32 bytes)
+		{
+			if(mCustomAllocator.empty())
+				return CM_NEW_BYTES(bytes, ScratchAlloc);
+			else
+			{
+				ObjectType* castObj = static_cast<ObjectType*>(object);
+				boost::function<UINT8*(ObjectType*, UINT32)> f = boost::any_cast<boost::function<UINT8*(ObjectType*, UINT32)>>(mCustomAllocator);
+				return f(castObj, bytes);
+			}
+		}
 	};
 	};
 }
 }

+ 17 - 6
CamelotUtility/Include/CmRTTIType.h

@@ -458,7 +458,7 @@ namespace CamelotFramework
 
 
 		template<class ObjectType>
 		template<class ObjectType>
 		void addDataBlockField(const std::string& name, UINT32 uniqueId, ManagedDataBlock (ObjectType::*getter)(), 
 		void addDataBlockField(const std::string& name, UINT32 uniqueId, ManagedDataBlock (ObjectType::*getter)(), 
-			void (ObjectType::*setter)(ManagedDataBlock) = nullptr, UINT64 flags = 0, boost::function<UINT8*(UINT32)> customAllocator = 0)
+			void (ObjectType::*setter)(ManagedDataBlock) = nullptr, UINT64 flags = 0, UINT8* (customAllocator)(ObjectType*, UINT32) = 0)
 		{
 		{
 			addDataBlockField<ObjectType>(name, uniqueId, 
 			addDataBlockField<ObjectType>(name, uniqueId, 
 				boost::function<ManagedDataBlock(ObjectType*)>(getter),  
 				boost::function<ManagedDataBlock(ObjectType*)>(getter),  
@@ -558,11 +558,22 @@ namespace CamelotFramework
 
 
 		template<class InterfaceType, class ObjectType>
 		template<class InterfaceType, class ObjectType>
 		void addDataBlockField(const std::string& name, UINT32 uniqueId, ManagedDataBlock (InterfaceType::*getter)(ObjectType*), 
 		void addDataBlockField(const std::string& name, UINT32 uniqueId, ManagedDataBlock (InterfaceType::*getter)(ObjectType*), 
-			void (InterfaceType::*setter)(ObjectType*, ManagedDataBlock), UINT64 flags = 0, boost::function<UINT8*(UINT32)> customAllocator = 0)
+			void (InterfaceType::*setter)(ObjectType*, ManagedDataBlock), UINT64 flags = 0, 
+			UINT8* (customAllocator)(ObjectType*, UINT32) = 0)
 		{
 		{
-			addDataBlockField<ObjectType>(name, uniqueId, 
-				boost::function<ManagedDataBlock(ObjectType*)>(boost::bind(getter, static_cast<InterfaceType*>(this), _1)),  
-				boost::function<void(ObjectType*, ManagedDataBlock)>(boost::bind(setter, static_cast<InterfaceType*>(this), _1, _2)), flags, customAllocator);
+			if(customAllocator != 0)
+			{
+				addDataBlockField<ObjectType>(name, uniqueId, 
+					boost::function<ManagedDataBlock(ObjectType*)>(boost::bind(getter, static_cast<InterfaceType*>(this), _1)),  
+					boost::function<void(ObjectType*, ManagedDataBlock)>(boost::bind(setter, static_cast<InterfaceType*>(this), _1, _2)), flags, 
+					boost::function<UINT8*(ObjectType*, UINT32)>(customAllocator));
+			}
+			else
+			{
+				addDataBlockField<ObjectType>(name, uniqueId, 
+					boost::function<ManagedDataBlock(ObjectType*)>(boost::bind(getter, static_cast<InterfaceType*>(this), _1)),  
+					boost::function<void(ObjectType*, ManagedDataBlock)>(boost::bind(setter, static_cast<InterfaceType*>(this), _1, _2)), flags);
+			}
 		}	
 		}	
 
 
 	private:
 	private:
@@ -642,7 +653,7 @@ namespace CamelotFramework
 		}
 		}
 
 
 		template<class ObjectType>
 		template<class ObjectType>
-		void addDataBlockField(const std::string& name, UINT32 uniqueId, boost::any getter, boost::any setter, UINT64 flags, boost::function<UINT8*(UINT32)> customAllocator = 0)
+		void addDataBlockField(const std::string& name, UINT32 uniqueId, boost::any getter, boost::any setter, UINT64 flags, boost::any customAllocator = boost::any())
 		{
 		{
 			RTTIManagedDataBlockField<ManagedDataBlock, ObjectType>* newField = 
 			RTTIManagedDataBlockField<ManagedDataBlock, ObjectType>* newField = 
 				CM_NEW(RTTIManagedDataBlockField<ManagedDataBlock BOOST_PP_COMMA() ObjectType>, GenAlloc) RTTIManagedDataBlockField<ManagedDataBlock, ObjectType>();
 				CM_NEW(RTTIManagedDataBlockField<ManagedDataBlock BOOST_PP_COMMA() ObjectType>, GenAlloc) RTTIManagedDataBlockField<ManagedDataBlock, ObjectType>();

+ 1 - 1
CamelotUtility/Source/CmBinarySerializer.cpp

@@ -760,7 +760,7 @@ namespace CamelotFramework
 						// Data block data
 						// Data block data
 						if(curField != nullptr)
 						if(curField != nullptr)
 						{
 						{
-							UINT8* dataCopy = curField->allocate(dataBlockSize); // TODO - Low priority. I need to read files better, so I
+							UINT8* dataCopy = curField->allocate(object.get(), dataBlockSize); // TODO - Low priority. I need to read files better, so I
 							memcpy(dataCopy, data, dataBlockSize);		//    can just pass the buffer pointer directly without copying (possibly large amounts of data)
 							memcpy(dataCopy, data, dataBlockSize);		//    can just pass the buffer pointer directly without copying (possibly large amounts of data)
 
 
 							ManagedDataBlock value(dataCopy, dataBlockSize); // Not managed because I assume the owner class will decide whether to delete the data or keep it
 							ManagedDataBlock value(dataCopy, dataBlockSize); // Not managed because I assume the owner class will decide whether to delete the data or keep it

+ 3 - 1
TODODoc.txt

@@ -11,4 +11,6 @@
       - I can't determine the size of struct or object arrays, as GL compiler will optimize out unused elements
       - I can't determine the size of struct or object arrays, as GL compiler will optimize out unused elements
  - Can't determine size of individual struct either, for the same reason (some struct members might get optimized out)
  - Can't determine size of individual struct either, for the same reason (some struct members might get optimized out)
   - Texture limitations: Only 1D, 2D, 3D and Cube textures (and their samplers) are supported. Support for multisampled textures
   - Texture limitations: Only 1D, 2D, 3D and Cube textures (and their samplers) are supported. Support for multisampled textures
-     is included where necessary to implement render targets. Support for texture arrays and is not included.
+     is included where necessary to implement render targets. Support for texture arrays and is not included.
+ - Multiple inheritance is not supported on any class that is serialized with the help of RTTI. If you use it you can expect
+   very weird issues.