瀏覽代碼

More work on preparing documentation for Doxygen generation

BearishSun 10 年之前
父節點
當前提交
b707bee12e

+ 2 - 2
BansheeCore/Include/BsMesh.h

@@ -10,7 +10,7 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	/** @addtogroup Renderer
+	/** @addtogroup Resources
 	 *  @{
 	 *  @{
 	 */
 	 */
 
 
@@ -60,7 +60,7 @@ namespace BansheeEngine
 		 * Reads a part of the current resource into the provided @p data parameter.	Data buffer needs to be pre-allocated.
 		 * Reads a part of the current resource into the provided @p data parameter.	Data buffer needs to be pre-allocated.
 		 *
 		 *
 		 * @param[in]	subresourceIdx		Index of the subresource to update, if the mesh has more than one.
 		 * @param[in]	subresourceIdx		Index of the subresource to update, if the mesh has more than one.
-		 * @param[in]	data				Buffer that will receive the data. Should be allocated with 
+		 * @param[out]	data				Buffer that will receive the data. Should be allocated with 
 		 *									allocateSubresourceBuffer() to ensure it is of valid type and size.
 		 *									allocateSubresourceBuffer() to ensure it is of valid type and size.
 		 */
 		 */
 		virtual void readSubresource(UINT32 subresourceIdx, MeshData& data);
 		virtual void readSubresource(UINT32 subresourceIdx, MeshData& data);

+ 2 - 2
BansheeCore/Include/BsMeshBase.h

@@ -8,7 +8,7 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	/** @addtogroup Renderer
+	/** @addtogroup Resources
 	 *  @{
 	 *  @{
 	 */
 	 */
 
 
@@ -23,7 +23,7 @@ namespace BansheeEngine
 		MU_CPUCACHED = 0x1000 /**< All mesh data will also be cached in CPU memory, making it readable with GPU reads. */
 		MU_CPUCACHED = 0x1000 /**< All mesh data will also be cached in CPU memory, making it readable with GPU reads. */
 	};
 	};
 
 
-	/** Contains various properties describing a mesh. */
+	/** Properties of a Mesh. Shared between sim and core thread versions of a Mesh. */
 	class BS_CORE_EXPORT MeshProperties
 	class BS_CORE_EXPORT MeshProperties
 	{
 	{
 	public:
 	public:

+ 1 - 1
BansheeCore/Include/BsMeshData.h

@@ -11,7 +11,7 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	/** @addtogroup Renderer
+	/** @addtogroup Resources
 	 *  @{
 	 *  @{
 	 */
 	 */
 
 

+ 229 - 265
BansheeCore/Include/BsMeshHeap.h

@@ -1,266 +1,230 @@
-#pragma once
-
-#include "BsCorePrerequisites.h"
-#include "BsCoreObject.h"
-#include "BsDrawOps.h"
-#include "BsIndexBuffer.h"
-
-namespace BansheeEngine
-{
-	/**
-	 * @brief	Core thread version of MeshHeap.
-	 *
-	 * @see		MeshHeap
-	 *
-	 * @note	Core thread only.
-	 */
-	class BS_CORE_EXPORT MeshHeapCore : public CoreObjectCore
-	{
-		/**
-		 * @brief	Signifies how is a data chunk used.
-		 */
-		enum class UseFlags
-		{
-			Used, /**< Data chunk is used by both CPU and GPU. */
-			CPUFree, /**< Data chunk was released by CPU but not GPU. */
-			GPUFree, /**< Data chunk was released by GPU but not CPU. */
-			Free /**< Data chunk was released by both CPU and GPU. */
-		};
-
-		/**
-		 * @brief	Represents a continuous chunk of memory.
-		 */
-		struct ChunkData
-		{
-			UINT32 start, size;
-		};
-
-		/**
-		 * @brief	Represents an allocated piece of data representing a mesh.
-		 */
-		struct AllocatedData
-		{
-			UINT32 vertChunkIdx;
-			UINT32 idxChunkIdx;
-
-			UseFlags useFlags;
-			UINT32 eventQueryIdx;
-			SPtr<TransientMeshCore> mesh;
-		};
-
-		/**
-		 * @brief	Data about a GPU query.
-		 */
-		struct QueryData
-		{
-			EventQueryPtr query;
-			UINT32 queryId;
-		};
-
-	public:
-		~MeshHeapCore();
-
-	private:
-		friend class MeshHeap;
-		friend class TransientMesh;
-		friend class TransientMeshCore;
-
-		MeshHeapCore(UINT32 numVertices, UINT32 numIndices, 
-			const VertexDataDescPtr& vertexDesc, IndexType indexType = IT_32BIT);
-
-		/**
-		 * @copydoc CoreObjectCore::initialize()
-		 */
-		virtual void initialize() override;
-
-		/**
-		 * @brief	Allocates a new mesh in the heap, expanding the heap if needed. 
-		 *
-		 * @param	meshId		Mesh for which we are allocating the data.
-		 * @param	meshData	Data to initialize the new mesh with.
-		 */
-		void alloc(SPtr<TransientMeshCore> mesh, const MeshDataPtr& meshData);
-
-		/**
-		 * @brief	Deallocates the provided mesh Freed memory
-		 *			will be re-used as soon as the GPU is done with the mesh
-		 */
-		void dealloc(SPtr<TransientMeshCore> mesh);
-
-		/**
-		 * @brief	Resizes the vertex buffers so they max contain the provided
-		 *			number of vertices.
-		 */
-		void growVertexBuffer(UINT32 numVertices);
-
-		/**
-		 * @brief	Resizes the index buffer so they max contain the provided
-		 *			number of indices.
-		 */
-		void growIndexBuffer(UINT32 numIndices);
-
-		/**
-		 * @brief	Creates a new event query or returns an existing one from the pool
-		 *			if available. Returned value is an index into mEventQueries array.
-		 */
-		UINT32 createEventQuery();
-
-		/**
-		 * @brief	Frees the event query with the specified index and returns it to the
-		 *			pool so it may be reused later.
-		 */
-		void freeEventQuery(UINT32 idx);
-
-		/**
-		 * @brief	Gets internal vertex data for all the meshes.
-		 */
-		SPtr<VertexData> getVertexData() const;
-
-		/**
-		 * @brief	Gets internal index data for all the meshes.
-		 */
-		SPtr<IndexBufferCore> getIndexBuffer() const;
-
-		/**
-		 * @brief	Returns a structure that describes how are the vertices stored in the mesh's vertex buffer.
-		 */
-		SPtr<VertexDataDesc> getVertexDesc() const;
-
-		/**
-		 * @brief	Returns the offset in vertices from the start of the buffer
-		 *			to the first vertex of the mesh with the provided ID.
-		 */
-		UINT32 getVertexOffset(UINT32 meshId) const;
-
-		/**
-		 * @brief	Returns the offset in indices from the start of the buffer
-		 *			to the first index of the mesh with the provided ID.
-		 */
-		UINT32 getIndexOffset(UINT32 meshId) const;
-
-		/**
-		 * @brief	Called by the render system when a mesh gets queued to the GPU.
-		 */
-		void notifyUsedOnGPU(UINT32 meshId);
-
-		/**
-		 * @brief	Called by an GPU event query when GPU processes the query. Normally
-		 *			signals the heap that the GPU is done with the mesh.
-		 */
-		static void queryTriggered(SPtr<MeshHeapCore> thisPtr, UINT32 meshId, UINT32 queryId);
-
-		/**
-		 * @brief	Attempts to reorganize the vertex and index buffer chunks in order to 
-		 *			in order to make free memory contigous.
-		 *
-		 * @note	This will not actually copy any data from index/vertex buffers, and will only
-		 *			modify the chunk descriptors.
-		 */
-		void mergeWithNearbyChunks(UINT32 chunkVertIdx, UINT32 chunkIdxIdx);
-
-	private:
-		UINT32 mNumVertices;
-		UINT32 mNumIndices;
-
-		Vector<UINT8*> mCPUVertexData;
-		UINT8* mCPUIndexData;
-
-		SPtr<VertexData> mVertexData;
-		SPtr<IndexBufferCore> mIndexBuffer;
-
-		Map<UINT32, AllocatedData> mMeshAllocData;
-
-		VertexDataDescPtr mVertexDesc;
-		IndexType mIndexType;
-
-		Vector<ChunkData> mVertChunks;
-		Vector<ChunkData> mIdxChunks;
-
-		Stack<UINT32> mEmptyVertChunks;
-		Stack<UINT32> mEmptyIdxChunks;
-
-		List<UINT32> mFreeVertChunks;
-		List<UINT32> mFreeIdxChunks;
-
-		Vector<QueryData> mEventQueries; 
-		Stack<UINT32> mFreeEventQueries;
-
-		UINT32 mNextQueryId;
-
-		static const float GrowPercent;
-	};
-
-	/**
-	 * @brief	Mesh heap allows you to quickly allocate and deallocate a large amounts of temporary 
-	 *			meshes without the large overhead of normal Mesh creation.
-	 * 			Only requirement is that meshes share the same vertex description and index type.
-	 * 			
-	 * @note	This class should be considered as a replacement for a normal Mesh if you are constantly 
-	 * 			updating the mesh (e.g. every frame) and you are not able to discard entire mesh contents 
-	 * 			on each update. Not using discard flag on normal meshes may introduce GPU-CPU sync points
-	 * 			which may severely limit performance. Primary purpose of this class is to avoid
-	 * 			those sync points by not forcing you to discard contents.
-	 * 			
-	 *			Downside is that this class may allocate 2-3x (or more) memory than it is actually needed
-	 *			for your data.
-	 *			
-	 *			Sim thread only
-	 */
-	class BS_CORE_EXPORT MeshHeap : public CoreObject
-	{
-	public:
-		/**
-		 * @brief	Allocates a new mesh in the heap, expanding the heap if needed. Mesh will be initialized
-		 *			with the provided meshData. You may use the returned transient mesh for drawing.
-		 *
-		 * @note	Offsets provided by MeshData are ignored. MeshHeap will determine
-		 * 			where the data will be written internally.
-		 */
-		TransientMeshPtr alloc(const MeshDataPtr& meshData, DrawOperationType drawOp = DOT_TRIANGLE_LIST);
-
-		/**
-		 * @brief	Deallocates the provided mesh and makes that room on the heap re-usable as soon as the GPU
-		 *			is also done with the mesh.
-		 */
-		void dealloc(const TransientMeshPtr& mesh);
-
-		/**
-		 * @brief	Retrieves a core implementation of a mesh heap usable only from the
-		 *			core thread.
-		 */
-		SPtr<MeshHeapCore> getCore() const;
-
-		/**
-		 * @brief	Creates a new mesh heap.
-		 *
-		 * @param	numVertices	Initial number of vertices the heap may store. This will grow automatically if needed.
-		 * @param	numIndices	Initial number of indices the heap may store. This will grow automatically if needed.
-		 * @param	vertexDesc	Description of the stored vertices.
-		 * @param	indexType	Type of the stored indices.
-		 */
-		static MeshHeapPtr create(UINT32 numVertices, UINT32 numIndices, 
-			const VertexDataDescPtr& vertexDesc, IndexType indexType = IT_32BIT);
-
-	private:
-		/**
-		 * @copydoc	create
-		 */
-		MeshHeap(UINT32 numVertices, UINT32 numIndices, 
-			const VertexDataDescPtr& vertexDesc, IndexType indexType = IT_32BIT);
-
-		/**
-		 * @copydoc	CoreObject::createCore
-		 */
-		SPtr<CoreObjectCore> createCore() const override;
-
-	private:
-		UINT32 mNumVertices;
-		UINT32 mNumIndices;
-
-		VertexDataDescPtr mVertexDesc;
-		IndexType mIndexType;
-
-		Map<UINT32, TransientMeshPtr> mMeshes;
-		UINT32 mNextFreeId;
-	};
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsCoreObject.h"
+#include "BsDrawOps.h"
+#include "BsIndexBuffer.h"
+
+namespace BansheeEngine
+{
+	/** @cond INTERNAL */
+	/** @addtogroup Resources
+	 *  @{
+	 */
+
+	/**
+	 * Core thread version of MeshHeap.
+	 *
+	 * @note	Core thread only.
+	 */
+	class BS_CORE_EXPORT MeshHeapCore : public CoreObjectCore
+	{
+		/**	Signifies how is a data chunk used. */
+		enum class UseFlags
+		{
+			Used, /**< Data chunk is used by both CPU and GPU. */
+			CPUFree, /**< Data chunk was released by CPU but not GPU. */
+			GPUFree, /**< Data chunk was released by GPU but not CPU. */
+			Free /**< Data chunk was released by both CPU and GPU. */
+		};
+
+		/**	Represents a continuous chunk of memory. */
+		struct ChunkData
+		{
+			UINT32 start, size;
+		};
+
+		/**	Represents an allocated piece of data representing a mesh. */
+		struct AllocatedData
+		{
+			UINT32 vertChunkIdx;
+			UINT32 idxChunkIdx;
+
+			UseFlags useFlags;
+			UINT32 eventQueryIdx;
+			SPtr<TransientMeshCore> mesh;
+		};
+
+		/**	Data about a GPU query. */
+		struct QueryData
+		{
+			EventQueryPtr query;
+			UINT32 queryId;
+		};
+
+	public:
+		~MeshHeapCore();
+
+	private:
+		friend class MeshHeap;
+		friend class TransientMesh;
+		friend class TransientMeshCore;
+
+		MeshHeapCore(UINT32 numVertices, UINT32 numIndices, 
+			const VertexDataDescPtr& vertexDesc, IndexType indexType = IT_32BIT);
+
+		/** @copydoc CoreObjectCore::initialize() */
+		virtual void initialize() override;
+
+		/**
+		 * Allocates a new mesh in the heap, expanding the heap if needed. 
+		 *
+		 * @param[in]	meshId		Mesh for which we are allocating the data.
+		 * @param[in]	meshData	Data to initialize the new mesh with.
+		 */
+		void alloc(SPtr<TransientMeshCore> mesh, const MeshDataPtr& meshData);
+
+		/** Deallocates the provided mesh. Freed memory will be re-used as soon as the GPU is done with the mesh. */
+		void dealloc(SPtr<TransientMeshCore> mesh);
+
+		/** Resizes the vertex buffers so they max contain the provided number of vertices. */
+		void growVertexBuffer(UINT32 numVertices);
+
+		/** Resizes the index buffer so they max contain the provided number of indices. */
+		void growIndexBuffer(UINT32 numIndices);
+
+		/**
+		 * Creates a new event query or returns an existing one from the pool if available. Returned value is an index 
+		 * into event query array.
+		 */
+		UINT32 createEventQuery();
+
+		/** Frees the event query with the specified index and returns it to the pool so it may be reused later. */
+		void freeEventQuery(UINT32 idx);
+
+		/**	Gets internal vertex data for all the meshes. */
+		SPtr<VertexData> getVertexData() const;
+
+		/**	Gets internal index data for all the meshes. */
+		SPtr<IndexBufferCore> getIndexBuffer() const;
+
+		/** Returns a structure that describes how are the vertices stored in the mesh's vertex buffer. */
+		SPtr<VertexDataDesc> getVertexDesc() const;
+
+		/**
+		 * Returns the offset in vertices from the start of the buffer to the first vertex of the mesh with the provided ID.
+		 */
+		UINT32 getVertexOffset(UINT32 meshId) const;
+
+		/**
+		 * Returns the offset in indices from the start of the buffer to the first index of the mesh with the provided ID.
+		 */
+		UINT32 getIndexOffset(UINT32 meshId) const;
+
+		/** Called by the render system when a mesh gets queued to the GPU. */
+		void notifyUsedOnGPU(UINT32 meshId);
+
+		/**
+		 * Called by an GPU event query when GPU processes the query. Normally signals the heap that the GPU is done with 
+		 * the mesh.
+		 */
+		static void queryTriggered(SPtr<MeshHeapCore> thisPtr, UINT32 meshId, UINT32 queryId);
+
+		/**
+		 * Attempts to reorganize the vertex and index buffer chunks in order to in order to make free memory contigous.
+		 *
+		 * @note	
+		 * This will not actually copy any data from index/vertex buffers, and will only modify the chunk descriptors.
+		 */
+		void mergeWithNearbyChunks(UINT32 chunkVertIdx, UINT32 chunkIdxIdx);
+
+	private:
+		UINT32 mNumVertices;
+		UINT32 mNumIndices;
+
+		Vector<UINT8*> mCPUVertexData;
+		UINT8* mCPUIndexData;
+
+		SPtr<VertexData> mVertexData;
+		SPtr<IndexBufferCore> mIndexBuffer;
+
+		Map<UINT32, AllocatedData> mMeshAllocData;
+
+		VertexDataDescPtr mVertexDesc;
+		IndexType mIndexType;
+
+		Vector<ChunkData> mVertChunks;
+		Vector<ChunkData> mIdxChunks;
+
+		Stack<UINT32> mEmptyVertChunks;
+		Stack<UINT32> mEmptyIdxChunks;
+
+		List<UINT32> mFreeVertChunks;
+		List<UINT32> mFreeIdxChunks;
+
+		Vector<QueryData> mEventQueries; 
+		Stack<UINT32> mFreeEventQueries;
+
+		UINT32 mNextQueryId;
+
+		static const float GrowPercent;
+	};
+
+	/** @endcond */
+
+	/**
+	 * Mesh heap allows you to quickly allocate and deallocate a large amounts of temporary meshes without the large 
+	 * overhead of normal Mesh creation. Only requirement is that meshes share the same vertex description and index type.
+	 * 			
+	 * @note	
+	 * This class should be considered as a replacement for a normal Mesh if you are constantly updating the mesh (e.g. 
+	 * every frame) and you are not able to discard entire mesh contents on each update. Not using discard flag on normal 
+	 * meshes may introduce GPU-CPU sync points which may severely limit performance. Primary purpose of this class is to 
+	 * avoid those sync points by not forcing you to discard contents.
+	 * Downside is that this class may allocate 2-3x (or more) memory than it is actually needed for your data.
+	 * @note
+	 * Sim thread only
+	 */
+	class BS_CORE_EXPORT MeshHeap : public CoreObject
+	{
+	public:
+		/**
+		 * Allocates a new mesh in the heap, expanding the heap if needed. Mesh will be initialized with the provided 
+		 * @p meshData. You may use the returned transient mesh for drawing.
+		 *
+		 * @note	
+		 * Offsets provided by MeshData are ignored. MeshHeap will determine where the data will be written internally.
+		 */
+		TransientMeshPtr alloc(const MeshDataPtr& meshData, DrawOperationType drawOp = DOT_TRIANGLE_LIST);
+
+		/**
+		 * Deallocates the provided mesh and makes that room on the heap re-usable as soon as the GPU is also done with the 
+		 * mesh.
+		 */
+		void dealloc(const TransientMeshPtr& mesh);
+
+		/** Retrieves a core implementation of a mesh heap usable only from the core thread. */
+		SPtr<MeshHeapCore> getCore() const;
+
+		/**
+		 * Creates a new mesh heap.
+		 *
+		 * @param[in]	numVertices	Initial number of vertices the heap may store. This will grow automatically if needed.
+		 * @param[in]	numIndices	Initial number of indices the heap may store. This will grow automatically if needed.
+		 * @param[in]	vertexDesc	Description of the stored vertices.
+		 * @param[in]	indexType	Type of the stored indices.
+		 */
+		static MeshHeapPtr create(UINT32 numVertices, UINT32 numIndices, 
+			const VertexDataDescPtr& vertexDesc, IndexType indexType = IT_32BIT);
+
+	private:
+		/** @copydoc create */
+		MeshHeap(UINT32 numVertices, UINT32 numIndices, 
+			const VertexDataDescPtr& vertexDesc, IndexType indexType = IT_32BIT);
+
+		/** @copydoc CoreObject::createCore */
+		SPtr<CoreObjectCore> createCore() const override;
+
+	private:
+		UINT32 mNumVertices;
+		UINT32 mNumIndices;
+
+		VertexDataDescPtr mVertexDesc;
+		IndexType mIndexType;
+
+		Map<UINT32, TransientMeshPtr> mMeshes;
+		UINT32 mNextFreeId;
+	};
+
+	/** @} */
 }
 }

+ 378 - 384
BansheeCore/Include/BsPixelData.h

@@ -1,385 +1,379 @@
-#pragma once
-
-#include "BsCorePrerequisites.h"
-#include "BsPixelVolume.h"
-#include "BsGpuResourceData.h"
-#include "BsIReflectable.h"
-
-namespace BansheeEngine
-{
-	/**
-	 * @brief	Pixel formats usable by images, textures and render surfaces.
-	 */
-    enum PixelFormat
-    {
-        // Unknown pixel format.
-        PF_UNKNOWN = 0,
-        // 8-bit pixel format, all bits red.
-        PF_R8 = 1,
-		// 2 byte pixel format, 1 byte red, 1 byte green.
-		PF_R8G8 = 2,
-        // 24-bit pixel format, 8 bits for red, green and blue.
-        PF_R8G8B8 = 3,
-        // 24-bit pixel format, 8 bits for blue, green and red.
-        PF_B8G8R8 = 4,
-        // 32-bit pixel format, 8 bits for alpha, red, green and blue.
-        PF_A8R8G8B8 = 5,
-        // 32-bit pixel format, 8 bits for blue, green, red and alpha.
-        PF_A8B8G8R8 = 6,
-        // 32-bit pixel format, 8 bits for blue, green, red and alpha.
-        PF_B8G8R8A8 = 7,
-		// 32-bit pixel format, 8 bits for red, green, blue and alpha.
-		PF_R8G8B8A8 = 8,
-        // 32-bit pixel format, 8 bits for red, 8 bits for green, 8 bits for blue.
-        // Like PF_A8R8G8B8, but alpha will get discarded
-        PF_X8R8G8B8 = 9,
-        // 32-bit pixel format, 8 bits for blue, 8 bits for green, 8 bits for red.
-        // Like PF_A8B8G8R8, but alpha will get discarded.
-        PF_X8B8G8R8 = 10,
-		// 32-bit pixel format, 8 bits for red, 8 bits for green, 8 bits for blue.
-		// Like PF_R8G8B8A8, but alpha will get discarded.
-		PF_R8G8B8X8 = 11,
-		// 32-bit pixel format, 8 bits for blue, 8 bits for green, 8 bits for red.
-		// Like PF_B8G8R8A8, but alpha will get discarded.
-		PF_B8G8R8X8 = 12,
-		// 24-bit pixel format, 8 bits for red, green and blue.
-		PF_BYTE_RGB = PF_R8G8B8,
-		// 24-bit pixel format, 8 bits for blue, green and red.
-		PF_BYTE_BGR = PF_B8G8R8,
-		// 32-bit pixel format, 8 bits for blue, green, red and alpha.
-		PF_BYTE_BGRA = PF_B8G8R8A8,
-		// 32-bit pixel format, 8 bits for red, green, blue and alpha.
-		PF_BYTE_RGBA = PF_R8G8B8A8,      
-        // DXT1/BC1 format containing opaque RGB or 1-bit alpha RGB. 4 bits per pixel.
-        PF_BC1 = 13,
-		// DXT3/BC2 format containing RGB with premultiplied alpha. 4 bits per pixel.
-		PF_BC1a = 14,
-        // DXT3/BC2 format containing RGB with explicit alpha. 8 bits per pixel.
-        PF_BC2 = 15,
-        // DXT5/BC2 format containing RGB with explicit alpha. 8 bits per pixel. Better alpha gradients than BC2.
-        PF_BC3 = 16,
-		// One channel compressed format. 4 bits per pixel.
-		PF_BC4 = 17,
-		// Two channel compressed format. 8 bits per pixel.
-		PF_BC5 = 18,
-		// Format storing RGB in half (16-bit) floating point format usable for HDR. 8 bits per pixel.
-		PF_BC6H = 19,
-		// Format storing RGB with optional alpha channel. Similar to BC1/BC2/BC3 formats but with higher quality and higher decompress overhead. 8 bits per pixel.
-		PF_BC7 = 20,
-		// 16-bit pixel format, 16 bits (float) for red.
-        PF_FLOAT16_R = 21,
-		// 32-bit, 2-channel s10e5 floating point pixel format, 16-bit red, 16-bit green.
-		PF_FLOAT16_RG = 22,
-        // 48-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue.
-        PF_FLOAT16_RGB = 23,
-        // 64-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue, 16 bits (float) for alpha.
-        PF_FLOAT16_RGBA = 24,
-		// 32-bit pixel format, 32 bits (float) for red.
-        PF_FLOAT32_R = 25,
-		// 64-bit, 2-channel floating point pixel format, 32-bit red, 32-bit green.
-		PF_FLOAT32_RG = 26,
-        // 96-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue.
-        PF_FLOAT32_RGB = 27,
-        // 128-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue, 32 bits (float) for alpha.
-        PF_FLOAT32_RGBA = 28,
-		// Depth stencil format, 32bit depth, 8bit stencil + 24 unused.
-		PF_D32_S8X24 = 29,
-		// Depth stencil fomrat, 24bit depth + 8bit stencil.
-		PF_D24S8 = 30,
-		// Depth format, 32bits.
-		PF_D32 = 31,
-		// Depth format, 16bits.
-		PF_D16 = 32,
-		// 32-bit float format, 11 bits (float) for red, 11 bits (float) for green, 10 bits (float) for blue. Framebuffer only format, not for CPU use.
-		PF_FLOAT_R11G11B10 = 33,
-		// 32-bit unsigned normalized format, 10 bits (float) for red, 10 bits (float) for green, 10 bits (float) for blue, and two bits for alpha. Framebuffer only format, not for CPU use.
-		PF_UNORM_R10G10B10A2 = 34,
-		// Number of pixel formats currently defined.
-        PF_COUNT = 35
-    };
-	typedef Vector<PixelFormat> PixelFormatList;
-
-	/**
-	 * @brief	Flags defining some properties of pixel formats.
-	 */
-    enum PixelFormatFlags {
-        // This format has an alpha channel
-        PFF_HASALPHA = 0x00000001,      
-        // This format is compressed. This invalidates the values in elemBytes,
-        // elemBits and the bit counts as these might not be fixed in a compressed format.
-        PFF_COMPRESSED = 0x00000002,
-        // This is a floating point format
-        PFF_FLOAT = 0x00000004,         
-        // This is a depth format (for depth textures)
-        PFF_DEPTH = 0x00000008,
-        // Format is in native endian. Generally true for the 16, 24 and 32 bits
-        // formats which can be represented as machine integers.
-        PFF_NATIVEENDIAN = 0x00000010
-    };
-    
-	/**
-	 * @brief	Types of pixel components
-	 */
-    enum PixelComponentType
-    {
-        PCT_BYTE = 0,    /**< Byte per component */
-        PCT_SHORT = 1,   /**< Short per component */
-        PCT_FLOAT16 = 2, /**< 16 bit float per component */
-        PCT_FLOAT32 = 3, /**< 32 bit float per component */
-		PCT_PACKED_R11G11B10 = 4, /**< 11 bits for first two components, 10 for third component. */
-		PCT_PACKED_R10G10B10A2 = 5, /**< 10 bits for first three components, 2 bits for last component */
-        PCT_COUNT = 4    /**< Number of pixel types */
-    };
-    
-	/**
-	 * @brief	A buffer describing a volume (3D), image (2D) or line (1D) of pixels in memory.
-	 *			Pixels are stored as a succession of "depth" slices, each containing "height" rows of
-	 *			"width" pixels.
-	 *
-	 *			As any GpuResourceData this is used primarily for reading and writing from/to a GPU resource,
-	 *			and is normally constructed by the resource itself. However you may still construct it manually
-	 *			and use it for other purposes if needed.
-	 *
-	 * @note	You must call allocateInternalBuffer or set the buffer in some other way before reading/writing
-	 *			from this object.
-	 *
-	 * @see		GpuResourceData
-	 */
-    class BS_CORE_EXPORT PixelData : public GpuResourceData
-	{
-    public:
-    	PixelData() {}
-		~PixelData() {}
-
-		/**
-		 * @brief	Constructs a new object with an internal buffer capable of holding "extents" volume of pixels, 
-		 *			where each pixel is of the specified pixel format. Extent offsets are also stored, but are not used
-		 *			internally.
-		 */
-		PixelData(const PixelVolume& extents, PixelFormat pixelFormat)
-			:mExtents(extents), mFormat(pixelFormat)
-		{
-			setConsecutive();
-		}
-
-		/**
-		 * @brief	Constructs a new object with an internal buffer capable of holding volume of pixels described by
-		 *			provided width, height and depth, where each pixel is of the specified pixel format.
-		 */
-    	PixelData(UINT32 width, UINT32 height, UINT32 depth, PixelFormat pixelFormat)
-			: mExtents(0, 0, 0, width, height, depth), mFormat(pixelFormat)
-    	{
-    		setConsecutive();
-    	}
-
-		PixelData(const PixelData& copy);
-		PixelData& operator=(const PixelData& rhs);
-
-		/**
-		 * @brief	Returns the number of pixels that offsets one row from another. This can be
-		 *			"width", but doesn't have to be as some buffers require padding.
-		 */
-		UINT32 getRowPitch() const { return mRowPitch; }
-
-		/**
-		 * @brief	Returns the number of pixels that offsets one depth slice from another. This can be
-		 *			"width * height", but doesn't have to be as some buffers require padding.
-		 */
-		UINT32 getSlicePitch() const { return mSlicePitch; }
-
-		/**
-		 * @brief	Sets the pitch (in pixels) that determines offset between rows of the pixel buffer.
-		 *			Call this before allocating the buffer.
-		 */
-		void setRowPitch(UINT32 rowPitch) { mRowPitch = rowPitch; }
-
-		/**
-		 * @brief	Sets the pitch (in pixels) that determines offset between depth slices of the pixel buffer.
-		 *			Call this before allocating the buffer.
-		 */
-        void setSlicePitch(UINT32 slicePitch) { mSlicePitch = slicePitch; }
-
-		/**
-		 * @brief	Returns the number of extra pixels in a row (non-zero only if rows are not
-		 *			consecutive (row pitch is larger than width)).
-		 */
-        UINT32 getRowSkip() const { return mRowPitch - getWidth(); }
-
-		/**
-		 * @brief	Returns the number of extra pixels in a depth slice (non-zero only if
-		 *			slices aren't consecutive (slice pitch is larger than width*height).
-		 */
-        UINT32 getSliceSkip() const { return mSlicePitch - (getHeight() * mRowPitch); }
-
-		/**
-		 * @brief	Returns the pixel format used by the internal buffer for storing the pixels.
-		 */
-		PixelFormat getFormat() const { return mFormat; }
-
-		/**
-		 * @brief	Returns width of the buffer in pixels.
-		 */
-		UINT32 getWidth() const { return mExtents.getWidth(); }
-
-		/**
-		 * @brief	Returns height of the buffer in pixels.
-		 */
-		UINT32 getHeight() const { return mExtents.getHeight(); }
-
-		/**
-		 * @brief	Returns depth of the buffer in pixels.
-		 */
-		UINT32 getDepth() const { return mExtents.getDepth(); }
-
-		/**
-		 * @brief	Returns left-most start of the pixel volume. This value is not used internally in any way.
-		 *			It is just passed through from the constructor.
-		 */
-		UINT32 getLeft() const { return mExtents.left; }
-
-		/**
-		 * @brief	Returns right-most end of the pixel volume. This value is not used internally in any way.
-		 *			It is just passed through from the constructor.
-		 */
-		UINT32 getRight() const { return mExtents.right; }
-
-		/**
-		 * @brief	Returns top-most start of the pixel volume. This value is not used internally in any way.
-		 *			It is just passed through from the constructor.
-		 */
-		UINT32 getTop() const { return mExtents.top; }
-
-		/**
-		 * @brief	Returns bottom-most end of the pixel volume. This value is not used internally in any way.
-		 *			It is just passed through from the constructor.
-		 */
-		UINT32 getBottom() const { return mExtents.bottom; }
-
-		/**
-		 * @brief	Returns front-most start of the pixel volume. This value is not used internally in any way.
-		 *			It is just passed through from the constructor.
-		 */
-		UINT32 getFront() const { return mExtents.front; }
-
-		/**
-		 * @brief	Returns back-most end of the pixel volume. This value is not used internally in any way.
-		 *			It is just passed through from the constructor.
-		 */
-		UINT32 getBack() const { return mExtents.back; }
-
-		/**
-		 * @brief	Returns extents of the pixel volume this object is capable of holding.
-		 */
-		PixelVolume getExtents() const { return mExtents; }
-
-		/**
-		 * @brief	Return whether this buffer is laid out consecutive in memory 
-		 *			(i.e. the pitches are equal to the dimensions).
-		 */
-        bool isConsecutive() const 
-		{ 
-			return mRowPitch == getWidth() && mSlicePitch == getWidth()*getHeight(); 
-		}
-
-		/**
-		 * @brief	Return the size (in bytes) this image would take if it was
-		 *			laid out consecutive in memory.
-		 */
-      	UINT32 getConsecutiveSize() const;
-
-		/**
-		 * @brief	Return the size (in bytes) of the buffer this image requires.
-		 */
-      	UINT32 getSize() const;
-
-		/**
-		 * @brief	Returns pixel data containing a sub-volume of this object. Returned
-		 *			data will not have its own buffer, but will instead point to this one.
-		 *			It is up to the caller to ensure this object outlives any sub-volume objects.
-		 */
-      	PixelData getSubVolume(const PixelVolume &def) const;
-        
-		/**
-		 * @brief	Returns pixel color at the specified coordinates.
-		 */
-		Color getColorAt(UINT32 x, UINT32 y, UINT32 z = 0) const;
-
-		/**
-		 * @brief	Sets the pixel color at the specified coordinates.
-		 */
-        void setColorAt(Color const &cv, UINT32 x, UINT32 y, UINT32 z = 0);
-
-		/**
-		 * @brief	Converts all the internal data into an array of colors. 
-		 *			Array is mapped as such: arrayIdx = x + y * width + z * width * height.
-		 */
-		Vector<Color> getColors() const;
-
-		/**
-		 * @brief	Initializes the internal buffer with the provided set of colors.
-		 *			The array should be of width * height * depth size and mapped
-		 *			as such: arrayIdx = x + y * width + z * width * height.
-		 */
-		void setColors(const Vector<Color>& colors);
-
-		/**
-		 * @brief	Initializes the internal buffer with the provided set of colors.
-		 *			The array should be of width * height * depth size and mapped
-		 *			as such: arrayIdx = x + y * width + z * width * height.
-		 */
-		void setColors(Color* colors, UINT32 numElements);
-
-		/**
-		 * @brief	Constructs a new object with an internal buffer capable of holding "extents" volume of pixels, 
-		 *			where each pixel is of the specified pixel format. Extent offsets are also stored, but are not used
-		 *			internally.
-		 */
-		static PixelDataPtr create(const PixelVolume &extents, PixelFormat pixelFormat);
-
-		/**
-		 * @brief	Constructs a new object with an internal buffer capable of holding volume of pixels described by
-		 *			provided width, height and depth, where each pixel is of the specified pixel format.
-		 */
-		static PixelDataPtr create(UINT32 width, UINT32 height, UINT32 depth, PixelFormat pixelFormat);
-
-	private:
-		/**
-		 * @brief	Set the rowPitch and slicePitch so that the buffer is laid out consecutive
-		 *			in memory. Does not actually modify the buffer itself.
-		 */
-		void setConsecutive()
-		{
-			mRowPitch = getWidth();
-			mSlicePitch = getWidth()*getHeight();
-		}
-
-		/**
-		 * @brief	Initializes the internal buffer with the provided set of colors.
-		 *			The array should be of width * height * depth size and mapped
-		 *			as such: arrayIdx = x + y * width + z * width * height.
-		 *
-		 * @note	A generic method that is reused in other more specific "setColors" calls.
-		 */
-		template<class T>
-		void setColorsInternal(const T& colors, UINT32 numElements);
-
-		/**
-		 * @brief	Returns the needed size of the internal buffer, in bytes.
-		 */
-		UINT32 getInternalBufferSize() const override;
-
-	private:
-		PixelVolume mExtents;
-        PixelFormat mFormat;
-        UINT32 mRowPitch;
-        UINT32 mSlicePitch;
-
-		/************************************************************************/
-		/* 								SERIALIZATION                      		*/
-		/************************************************************************/
-	public:
-		friend class PixelDataRTTI;
-		static RTTITypeBase* getRTTIStatic();
-		virtual RTTITypeBase* getRTTI() const override;
-    };
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsPixelVolume.h"
+#include "BsGpuResourceData.h"
+#include "BsIReflectable.h"
+
+namespace BansheeEngine
+{
+	/** @addtogroup Resources
+	 *  @{
+	 */
+
+	/** Pixel formats usable by images, textures and render surfaces. */
+    enum PixelFormat
+    {
+        /** Unknown pixel format. */
+        PF_UNKNOWN = 0,
+        /** 8-bit pixel format, all bits red. */
+        PF_R8 = 1,
+		/** 2 byte pixel format, 1 byte red, 1 byte green. */
+		PF_R8G8 = 2,
+        /** 24-bit pixel format, 8 bits for red, green and blue. */
+        PF_R8G8B8 = 3,
+        /** 24-bit pixel format, 8 bits for blue, green and red. */
+        PF_B8G8R8 = 4,
+        /** 32-bit pixel format, 8 bits for alpha, red, green and blue. */
+        PF_A8R8G8B8 = 5,
+        /** 32-bit pixel format, 8 bits for blue, green, red and alpha. */
+        PF_A8B8G8R8 = 6,
+        /** 32-bit pixel format, 8 bits for blue, green, red and alpha. */
+        PF_B8G8R8A8 = 7,
+		/** 32-bit pixel format, 8 bits for red, green, blue and alpha. */
+		PF_R8G8B8A8 = 8,
+        /** 
+		 * 32-bit pixel format, 8 bits for red, 8 bits for green, 8 bits for blue. Like PF_A8R8G8B8, but alpha will get 
+		 * discarded.
+		 */
+        PF_X8R8G8B8 = 9,
+        /** 
+		 * 32-bit pixel format, 8 bits for blue, 8 bits for green, 8 bits for red. Like PF_A8B8G8R8, but alpha will get 
+		 * discarded.
+		 */
+        PF_X8B8G8R8 = 10,
+		/** 
+		 * 32-bit pixel format, 8 bits for red, 8 bits for green, 8 bits for blue. Like PF_R8G8B8A8, but alpha will get 
+		 * discarded. 
+		 */
+		PF_R8G8B8X8 = 11,
+		/** 32-bit pixel format, 8 bits for blue, 8 bits for green, 8 bits for red. */
+		/** Like PF_B8G8R8A8, but alpha will get discarded. */
+		PF_B8G8R8X8 = 12,
+		/** 24-bit pixel format, 8 bits for red, green and blue. */
+		PF_BYTE_RGB = PF_R8G8B8,
+		/** 24-bit pixel format, 8 bits for blue, green and red. */
+		PF_BYTE_BGR = PF_B8G8R8,
+		/** 32-bit pixel format, 8 bits for blue, green, red and alpha. */
+		PF_BYTE_BGRA = PF_B8G8R8A8,
+		/** 32-bit pixel format, 8 bits for red, green, blue and alpha. */
+		PF_BYTE_RGBA = PF_R8G8B8A8,      
+        /** DXT1/BC1 format containing opaque RGB or 1-bit alpha RGB. 4 bits per pixel. */
+        PF_BC1 = 13,
+		/** DXT3/BC2 format containing RGB with premultiplied alpha. 4 bits per pixel. */
+		PF_BC1a = 14,
+        /** DXT3/BC2 format containing RGB with explicit alpha. 8 bits per pixel. */
+        PF_BC2 = 15,
+        /** DXT5/BC2 format containing RGB with explicit alpha. 8 bits per pixel. Better alpha gradients than BC2. */
+        PF_BC3 = 16,
+		/** One channel compressed format. 4 bits per pixel. */
+		PF_BC4 = 17,
+		/** Two channel compressed format. 8 bits per pixel. */
+		PF_BC5 = 18,
+		/** Format storing RGB in half (16-bit) floating point format usable for HDR. 8 bits per pixel. */
+		PF_BC6H = 19,
+		/** 
+		 * Format storing RGB with optional alpha channel. Similar to BC1/BC2/BC3 formats but with higher quality and 
+		 * higher decompress overhead. 8 bits per pixel. 
+		 */
+		PF_BC7 = 20,
+		/** 16-bit pixel format, 16 bits (float) for red. */
+        PF_FLOAT16_R = 21,
+		/** 32-bit, 2-channel s10e5 floating point pixel format, 16-bit red, 16-bit green. */
+		PF_FLOAT16_RG = 22,
+        /** 48-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue. */
+        PF_FLOAT16_RGB = 23,
+        /** 
+		 * 64-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue, 16 bits 
+		 * (float) for alpha. 
+		 */
+        PF_FLOAT16_RGBA = 24,
+		/** 32-bit pixel format, 32 bits (float) for red. */
+        PF_FLOAT32_R = 25,
+		/** 64-bit, 2-channel floating point pixel format, 32-bit red, 32-bit green. */
+		PF_FLOAT32_RG = 26,
+        /** 96-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue. */
+        PF_FLOAT32_RGB = 27,
+        /** 
+		 * 128-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue, 32 bits 
+		 * (float) for alpha. 
+		 */
+        PF_FLOAT32_RGBA = 28,
+		/** Depth stencil format, 32bit depth, 8bit stencil + 24 unused. */
+		PF_D32_S8X24 = 29,
+		/** Depth stencil fomrat, 24bit depth + 8bit stencil. */
+		PF_D24S8 = 30,
+		/** Depth format, 32bits. */
+		PF_D32 = 31,
+		/** Depth format, 16bits. */
+		PF_D16 = 32,
+		/** 
+		 * 32-bit float format, 11 bits (float) for red, 11 bits (float) for green, 10 bits (float) for blue. Framebuffer 
+		 * only format, not for CPU use. 
+		 */
+		PF_FLOAT_R11G11B10 = 33,
+		/** 
+		 * 32-bit unsigned normalized format, 10 bits (float) for red, 10 bits (float) for green, 10 bits (float) for blue, 
+		 * and two bits for alpha. Framebuffer only format, not for CPU use.
+		 */
+		PF_UNORM_R10G10B10A2 = 34,
+		/** Number of pixel formats currently defined. */
+        PF_COUNT = 35
+    };
+	typedef Vector<PixelFormat> PixelFormatList;
+
+	/**	Flags defining some properties of pixel formats. */
+    enum PixelFormatFlags {
+        /** This format has an alpha channel. */
+        PFF_HASALPHA = 0x00000001,      
+        /**
+		 * This format is compressed. This invalidates the values in elemBytes, elemBits and the bit counts as these might
+		 * not be fixed in a compressed format.
+		 */
+        PFF_COMPRESSED = 0x00000002,
+        /** This is a floating point format. */
+        PFF_FLOAT = 0x00000004,         
+        /** This is a depth format (for depth textures). */
+        PFF_DEPTH = 0x00000008,
+        /** 
+		 * Format is in native endian. Generally true for the 16, 24 and 32 bits formats which can be represented as 
+		 * machine integers.
+		 */
+        PFF_NATIVEENDIAN = 0x00000010
+    };
+    
+	/**	Types used for individual components of a pixel. */
+    enum PixelComponentType
+    {
+        PCT_BYTE = 0,    /**< Byte per component */
+        PCT_SHORT = 1,   /**< Short per component */
+        PCT_FLOAT16 = 2, /**< 16 bit float per component */
+        PCT_FLOAT32 = 3, /**< 32 bit float per component */
+		PCT_PACKED_R11G11B10 = 4, /**< 11 bits for first two components, 10 for third component. */
+		PCT_PACKED_R10G10B10A2 = 5, /**< 10 bits for first three components, 2 bits for last component */
+        PCT_COUNT = 4    /**< Number of pixel types */
+    };
+    
+	/**
+	 * A buffer describing a volume (3D), image (2D) or line (1D) of pixels in memory. Pixels are stored as a succession 
+	 * of "depth" slices, each containing "height" rows of "width" pixels.
+	 *
+	 * As any GpuResourceData this is used primarily for reading and writing from/to a GPU resource, and is normally 
+	 * constructed by the resource itself. However you may still construct it manually and use it for other purposes if 
+	 * needed.
+	 *
+	 * @note	
+	 * You must call allocateInternalBuffer or set the buffer in some other way before reading/writing from this object.
+	 *
+	 * @see		GpuResourceData
+	 */
+    class BS_CORE_EXPORT PixelData : public GpuResourceData
+	{
+    public:
+    	PixelData() {}
+		~PixelData() {}
+
+		/**
+		 * Constructs a new object with an internal buffer capable of holding "extents" volume of pixels, where each pixel 
+		 * is of the specified pixel format. Extent offsets are also stored, but are not used internally.
+		 */
+		PixelData(const PixelVolume& extents, PixelFormat pixelFormat)
+			:mExtents(extents), mFormat(pixelFormat)
+		{
+			setConsecutive();
+		}
+
+		/**
+		 * Constructs a new object with an internal buffer capable of holding volume of pixels described by	provided width, 
+		 * height and depth, where each pixel is of the specified pixel format.
+		 */
+    	PixelData(UINT32 width, UINT32 height, UINT32 depth, PixelFormat pixelFormat)
+			: mExtents(0, 0, 0, width, height, depth), mFormat(pixelFormat)
+    	{
+    		setConsecutive();
+    	}
+
+		PixelData(const PixelData& copy);
+		PixelData& operator=(const PixelData& rhs);
+
+		/**
+		 * Returns the number of pixels that offsets one row from another. This can be "width", but doesn't have to be as
+		 * some buffers require padding.
+		 */
+		UINT32 getRowPitch() const { return mRowPitch; }
+
+		/**
+		 * Returns the number of pixels that offsets one depth slice from another. This can be "width * height", but 
+		 * doesn't have to be as some buffers require padding.
+		 */
+		UINT32 getSlicePitch() const { return mSlicePitch; }
+
+		/**
+		 * Sets the pitch (in pixels) that determines offset between rows of the pixel buffer. Call this before allocating
+		 * the buffer.
+		 */
+		void setRowPitch(UINT32 rowPitch) { mRowPitch = rowPitch; }
+
+		/**
+		 * Sets the pitch (in pixels) that determines offset between depth slices of the pixel buffer. Call this before 
+		 * allocating the buffer.
+		 */
+        void setSlicePitch(UINT32 slicePitch) { mSlicePitch = slicePitch; }
+
+		/**
+		 * Returns the number of extra pixels in a row (non-zero only if rows are not consecutive (row pitch is larger 
+		 * than width)).
+		 */
+        UINT32 getRowSkip() const { return mRowPitch - getWidth(); }
+
+		/**
+		 * Returns the number of extra pixels in a depth slice (non-zero only if slices aren't consecutive (slice pitch is 
+		 * larger than width*height).
+		 */
+        UINT32 getSliceSkip() const { return mSlicePitch - (getHeight() * mRowPitch); }
+
+		/** Returns the pixel format used by the internal buffer for storing the pixels. */
+		PixelFormat getFormat() const { return mFormat; }
+
+		/**	Returns width of the buffer in pixels. */
+		UINT32 getWidth() const { return mExtents.getWidth(); }
+
+		/**	Returns height of the buffer in pixels. */
+		UINT32 getHeight() const { return mExtents.getHeight(); }
+
+		/**	Returns depth of the buffer in pixels. */
+		UINT32 getDepth() const { return mExtents.getDepth(); }
+
+		/**
+		 * Returns left-most start of the pixel volume. This value is not used internally in any way. It is just passed 
+		 * through from the constructor.
+		 */
+		UINT32 getLeft() const { return mExtents.left; }
+
+		/**
+		 * Returns right-most end of the pixel volume. This value is not used internally in any way. It is just passed 
+		 * through from the constructor.
+		 */
+		UINT32 getRight() const { return mExtents.right; }
+
+		/**
+		 * Returns top-most start of the pixel volume. This value is not used internally in any way. It is just passed 
+		 * through from the constructor.
+		 */
+		UINT32 getTop() const { return mExtents.top; }
+
+		/**
+		 * Returns bottom-most end of the pixel volume. This value is not used internally in any way. It is just passed 
+		 * through from the constructor.
+		 */
+		UINT32 getBottom() const { return mExtents.bottom; }
+
+		/**
+		 * Returns front-most start of the pixel volume. This value is not used internally in any way. It is just passed 
+		 * through from the constructor.
+		 */
+		UINT32 getFront() const { return mExtents.front; }
+
+		/**
+		 * Returns back-most end of the pixel volume. This value is not used internally in any way. It is just passed 
+		 * through from the constructor.
+		 */
+		UINT32 getBack() const { return mExtents.back; }
+
+		/** Returns extents of the pixel volume this object is capable of holding. */
+		PixelVolume getExtents() const { return mExtents; }
+
+		/** Return whether this buffer is laid out consecutive in memory (i.e. the pitches are equal to the dimensions). */
+        bool isConsecutive() const 
+		{ 
+			return mRowPitch == getWidth() && mSlicePitch == getWidth()*getHeight(); 
+		}
+
+		/** Return the size (in bytes) this image would take if it was laid out consecutive in memory. */
+      	UINT32 getConsecutiveSize() const;
+
+		/**	Return the size (in bytes) of the buffer this image requires. */
+      	UINT32 getSize() const;
+
+		/**
+		 * Returns pixel data containing a sub-volume of this object. Returned data will not have its own buffer, but will
+		 * instead point to this one. It is up to the caller to ensure this object outlives any sub-volume objects.
+		 */
+      	PixelData getSubVolume(const PixelVolume &def) const;
+        
+		/**	Returns pixel color at the specified coordinates. */
+		Color getColorAt(UINT32 x, UINT32 y, UINT32 z = 0) const;
+
+		/**	Sets the pixel color at the specified coordinates. */
+        void setColorAt(Color const &cv, UINT32 x, UINT32 y, UINT32 z = 0);
+
+		/**
+		 * Converts all the internal data into an array of colors. Array is mapped as such: 
+		 * arrayIdx = x + y * width + z * width * height.
+		 */
+		Vector<Color> getColors() const;
+
+		/**
+		 * Initializes the internal buffer with the provided set of colors. The array should be of width * height * depth 
+		 * size and mapped as such: arrayIdx = x + y * width + z * width * height.
+		 */
+		void setColors(const Vector<Color>& colors);
+
+		/**
+		 * Initializes the internal buffer with the provided set of colors. The array should be of 
+		 * width * height * depth size and mapped as such: arrayIdx = x + y * width + z * width * height.
+		 */
+		void setColors(Color* colors, UINT32 numElements);
+
+		/**
+		 * Constructs a new object with an internal buffer capable of holding "extents" volume of pixels, where each pixel
+		 * is of the specified pixel format. Extent offsets are also stored, but are not used internally.
+		 */
+		static PixelDataPtr create(const PixelVolume &extents, PixelFormat pixelFormat);
+
+		/**
+		 * Constructs a new object with an internal buffer capable of holding volume of pixels described by provided width,
+		 * height and depth, where each pixel is of the specified pixel format.
+		 */
+		static PixelDataPtr create(UINT32 width, UINT32 height, UINT32 depth, PixelFormat pixelFormat);
+
+	private:
+		/**
+		 * Set the rowPitch and slicePitch so that the buffer is laid out consecutive in memory. Does not actually modify
+		 * the buffer itself.
+		 */
+		void setConsecutive()
+		{
+			mRowPitch = getWidth();
+			mSlicePitch = getWidth()*getHeight();
+		}
+
+		/**
+		 * Initializes the internal buffer with the provided set of colors. The array should be of width * height * depth 
+		 * size and mapped as such: arrayIdx = x + y * width + z * width * height.
+		 *
+		 * @note	A generic method that is reused in other more specific setColors() calls.
+		 */
+		template<class T>
+		void setColorsInternal(const T& colors, UINT32 numElements);
+
+		/**	Returns the needed size of the internal buffer, in bytes. */
+		UINT32 getInternalBufferSize() const override;
+
+	private:
+		PixelVolume mExtents;
+        PixelFormat mFormat;
+        UINT32 mRowPitch;
+        UINT32 mSlicePitch;
+
+		/************************************************************************/
+		/* 								SERIALIZATION                      		*/
+		/************************************************************************/
+	public:
+		friend class PixelDataRTTI;
+		static RTTITypeBase* getRTTIStatic();
+		virtual RTTITypeBase* getRTTI() const override;
+    };
+
+	/** @} */
 }
 }

+ 54 - 62
BansheeCore/Include/BsResource.h

@@ -1,63 +1,55 @@
-#pragma once
-
-#include "BsCorePrerequisites.h"
-#include "BsIReflectable.h"
-#include "BsCoreObject.h"
-
-namespace BansheeEngine
-{
-	/**
-	 * @brief	Base class for all resources.
-	 */
-	class BS_CORE_EXPORT Resource : public IReflectable, public CoreObject
-	{
-	public:
-		Resource(bool requiresGpuInitialization = true);
-		virtual ~Resource() {};
-
-		/**
-		 * @brief	Returns the name of the resource.
-		 */
-		const WString& getName() const;
-
-		/**
-		 * @brief	Sets the name of the resource. 
-		 */
-		void setName(const WString& name);
-
-		/**
-		 * @brief	Retrieves meta-data containing various information describing a resource.
-		 */
-		ResourceMetaDataPtr getMetaData() const { return mMetaData; }
-
-		/**
-		 * @brief	Returns whether or not this resource is allowed to be asynchronously loaded.
-		 */
-		virtual bool allowAsyncLoading() const { return true; }
-
-	protected:
-		friend class Resources;
-		friend class ResourceHandleBase;
-
-		/**
-		 * @brief	Retrieves a list of all resources that this resource depends on.
-		 */
-		virtual void getResourceDependencies(FrameVector<HResource>& dependencies) const { }
-
-		/**
-		 * @brief	Checks if all the resources this object is dependent on are fully loaded.
-		 */
-		bool areDependenciesLoaded() const;
-
-		UINT32 mSize;
-		ResourceMetaDataPtr mMetaData;
-
-	/************************************************************************/
-	/* 								SERIALIZATION                      		*/
-	/************************************************************************/
-	public:
-		friend class ResourceRTTI;
-		static RTTITypeBase* getRTTIStatic();
-		virtual RTTITypeBase* getRTTI() const override;
-	};
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsIReflectable.h"
+#include "BsCoreObject.h"
+
+namespace BansheeEngine
+{
+	/** @addtogroup Resources
+	 *  @{
+	 */
+
+	/**	Base class for all resources. */
+	class BS_CORE_EXPORT Resource : public IReflectable, public CoreObject
+	{
+	public:
+		Resource(bool requiresGpuInitialization = true);
+		virtual ~Resource() {};
+
+		/**	Returns the name of the resource. */
+		const WString& getName() const;
+
+		/**	Sets the name of the resource.  */
+		void setName(const WString& name);
+
+		/**	Retrieves meta-data containing various information describing a resource. */
+		ResourceMetaDataPtr getMetaData() const { return mMetaData; }
+
+		/**	Returns whether or not this resource is allowed to be asynchronously loaded. */
+		virtual bool allowAsyncLoading() const { return true; }
+
+	protected:
+		friend class Resources;
+		friend class ResourceHandleBase;
+
+		/**	Retrieves a list of all resources that this resource depends on. */
+		virtual void getResourceDependencies(FrameVector<HResource>& dependencies) const { }
+
+		/**	Checks if all the resources this object is dependent on are fully loaded. */
+		bool areDependenciesLoaded() const;
+
+		UINT32 mSize;
+		ResourceMetaDataPtr mMetaData;
+
+	/************************************************************************/
+	/* 								SERIALIZATION                      		*/
+	/************************************************************************/
+	public:
+		friend class ResourceRTTI;
+		static RTTITypeBase* getRTTIStatic();
+		virtual RTTITypeBase* getRTTI() const override;
+	};
+
+	/** @} */
 }
 }

+ 396 - 415
BansheeCore/Include/BsResourceHandle.h

@@ -1,416 +1,397 @@
-#pragma once
-
-#include "BsIReflectable.h"
-
-namespace BansheeEngine
-{
-	/**
-	 * @brief	Data that is shared between all resource handles.
-	 */
-	struct BS_CORE_EXPORT ResourceHandleData
-	{
-		ResourceHandleData()
-			:mIsCreated(false), mRefCount(0)
-		{ }
-
-		SPtr<Resource> mPtr;
-		String mUUID;
-		bool mIsCreated;	
-		UINT32 mRefCount;
-	};
-
-	/**
-	 * @brief	Base class containing common functionality for resource handles.
-	 */
-	class BS_CORE_EXPORT ResourceHandleBase : public IReflectable
-	{
-	public:
-		virtual ~ResourceHandleBase();
-
-		/**
-		 * @brief	Checks if the resource is loaded. Until resource is loaded this handle
-		 *			is invalid and you may not get the internal resource from it.
-		 *
-		 * @param	checkDependencies	If true, and if resource has any dependencies, this method will
-		 *								also check if they are loaded.
-		 */
-		bool isLoaded(bool checkDependencies = true) const;
-
-		/**
-		 * @brief	Blocks the current thread until the resource is fully loaded.
-		 * 			
-		 * @note	Careful not to call this on the thread that does the loading.
-		 */
-		void blockUntilLoaded(bool waitForDependencies = true) const;
-
-		/**
-		 * @brief	Releases an internal reference to this resource held by the resources system, if there is one.
-		 * 			
-		 * @see		Resources::release(ResourceHandleBase&)
-		 */
-		void release();
-
-		/**
-		 * @brief	Returns the UUID of the resource the handle is referring to.
-		 */
-		const String& getUUID() const { return mData != nullptr ? mData->mUUID : StringUtil::BLANK; }
-
-		/**
-		 * @brief	Gets the handle data. For internal use only.
-		 */
-		const SPtr<ResourceHandleData>& getHandleData() const { return mData; }
-
-	protected:
-		ResourceHandleBase();
-
-		/**
-		 * @brief	Destroys the resource the handle is pointing to.
-		 */
-		void destroy();
-
-		/**
-		 * @brief	Sets the created flag to true and assigns the resource pointer. Called
-		 * 			by the constructors, or if you constructed just using a UUID, then you need to
-		 * 			call this manually before you can access the resource from this handle.
-		 * 			
-		 * @note	This is needed because two part construction is required due to 
-		 *			multithreaded nature of resource loading.
-		 *			Internal method.
-		 */
-		void setHandleData(const SPtr<Resource>& ptr, const String& uuid);
-
-		/**
-		 * @brief	Increments the reference count of the handle. Only to be used by ::Resources for keeping
-		 * 			internal references.
-		 */
-		void addInternalRef();
-
-		/**
-		 * @brief	Decrements the reference count of the handle. Only to be used by ::Resources for keeping
-		 * 			internal references.
-		 */
-		void removeInternalRef();
-
-		/** @note	All handles to the same source must share this same handle data. Otherwise things
-		 *			like counting number of references or replacing pointed to resource become impossible
-		 *			without additional logic. */
-		SPtr<ResourceHandleData> mData;
-
-	private:
-		friend class Resources;
-
-		BS_STATIC_THREAD_SYNCHRONISER(mResourceCreatedCondition)
-		BS_STATIC_MUTEX(mResourceCreatedMutex)
-
-	protected:
-		inline void throwIfNotLoaded() const;
-	};
-
-	/**
-	 * @copydoc	ResourceHandleBase
-	 *
-	 * Handles differences in reference counting depending if the handle is normal or weak.
-	 */
-	template <bool WeakHandle>
-	class BS_CORE_EXPORT TResourceHandleBase : public ResourceHandleBase { };
-
-	/**
-	 * @brief	Specialization of TResourceHandleBase for weak handles. Weak handles do no reference counting.
-	 */
-	template<>
-	class BS_CORE_EXPORT TResourceHandleBase<true> : public ResourceHandleBase
-	{
-	public:
-		virtual ~TResourceHandleBase() { }
-
-	protected:
-		void addRef() { };
-		void releaseRef() { };
-
-		/************************************************************************/
-		/* 								RTTI		                     		*/
-		/************************************************************************/
-	public:
-		friend class WeakResourceHandleRTTI;
-		static RTTITypeBase* getRTTIStatic();
-		virtual RTTITypeBase* getRTTI() const override;
-	};
-
-	/**
-	 * @brief	Specialization of TResourceHandleBase for normal (non-weak) handles.
-	 */
-	template<>
-	class BS_CORE_EXPORT TResourceHandleBase<false> : public ResourceHandleBase
-	{
-	public:
-		virtual ~TResourceHandleBase() { }
-
-	protected:
-		void addRef() { if (mData) mData->mRefCount++; };
-		void releaseRef() 
-		{ 
-			if (mData)
-			{
-				mData->mRefCount--;
-
-				if (mData->mRefCount == 0)
-					destroy();
-			}
-		};
-
-		/************************************************************************/
-		/* 								RTTI		                     		*/
-		/************************************************************************/
-	public:
-		friend class WeakResourceHandleRTTI;
-		friend class ResourceHandleRTTI;
-		static RTTITypeBase* getRTTIStatic();
-		virtual RTTITypeBase* getRTTI() const override;
-	};
-
-	/**
-	 * @brief	Represents a handle to a resource. Handles are similar to a smart pointers, but they have two advantages:
-	 *				- When loading a resource asynchronously you can be immediately returned the handle
-	 *				  that you may use throughout the engine. The handle will be made valid as soon as
-	 *				  the resource is loaded.
-	 *				- Handles can be serialized and deserialized, therefore saving/restoring references
-	 *				  to their original resource.
-	 */
-	template <typename T, bool WeakHandle>
-	class TResourceHandle : public TResourceHandleBase<WeakHandle>
-	{
-	public:
-		TResourceHandle()
-			:TResourceHandleBase()
-		{ }
-
-		/**
-		 * @brief	Copy constructor.
-		 */
-		TResourceHandle(const TResourceHandle<T, WeakHandle>& ptr)
-			:TResourceHandleBase()
-		{
-			mData = ptr.getHandleData();
-
-			addRef();
-		}
-
-		virtual ~TResourceHandle()
-		{
-			releaseRef();
-		}
-
-		/**
-		 * @brief	Converts a specific handle to generic Resource handle.
-		 */
-		operator TResourceHandle<Resource, WeakHandle>() const
-		{
-			TResourceHandle<Resource, WeakHandle> handle;
-			handle.setHandleData(getHandleData());
-
-			return handle;
-		}
-
-		/**
-		 * @brief	Returns internal resource pointer.
-		 *
-		 * @note	Throws exception if handle is invalid.
-		 */
-		T* operator->() const { return get(); }
-
-		/**
-		 * @brief	Returns internal resource pointer and dereferences it.
-		 *
-		 * @note	Throws exception if handle is invalid.
-		 */
-		T& operator*() const { return *get(); }
-
-		/**
-		 * @brief	Clears the handle making it invalid and releases any references
-		 *			held to the resource.
-		 */
-		TResourceHandle<T, WeakHandle>& operator=(std::nullptr_t ptr)
-		{ 	
-			releaseRef();
-
-			mData = nullptr;
-			return *this;
-		}
-
-		/**
-		 * @brief	Normal assignment operator.
-		 */
-		TResourceHandle<T, WeakHandle>& operator=(const TResourceHandle<T, WeakHandle>& rhs)
-		{ 	
-			setHandleData(rhs.getHandleData());
-			return *this;
-		}
-
-		template<class _Ty>
-		struct Bool_struct
-		{
-			int _Member;
-		};
-
-		/**
-		 * @brief	Allows direct conversion of handle to bool.
-		 *
-		 * @note	This is needed because we can't directly convert to bool 
-		 *			since then we can assign pointer to bool and that's weird.
-		 */
-		operator int Bool_struct<T>::*() const
-		{
-			return ((mData != nullptr && !mData->mUUID.empty()) ? &Bool_struct<T>::_Member : 0);
-		}
-
-		/**
-		 * @brief	Returns internal resource pointer and dereferences it.
-		 *
-		 * @note	Throws exception if handle is invalid.
-		 */
-		T* get() const 
-		{ 
-			throwIfNotLoaded();
-
-			return reinterpret_cast<T*>(mData->mPtr.get()); 
-		}
-
-		/**
-		 * @brief	Returns the internal shared pointer to the resource.
-		 *
-		 * @note	Throws exception if handle is invalid.
-		 */
-		SPtr<T> getInternalPtr() const
-		{ 
-			throwIfNotLoaded();
-
-			return std::static_pointer_cast<T>(mData->mPtr); 
-		}
-
-		/**
-		 * @brief	Converts a handle into a weak handle.
-		 */
-		TResourceHandle<T, true> getWeak() const
-		{
-			TResourceHandle<T, true> handle;
-			handle.setHandleData(getHandleData());
-
-			return handle;
-		}
-
-	protected:
-		friend Resources;
-		template<class _T, bool _Weak>
-		friend class TResourceHandle;
-		template<class _Ty1, class _Ty2, bool Weak>
-		friend TResourceHandle<_Ty1, Weak> static_resource_cast(const TResourceHandle<_Ty2, Weak>& other);
-
-		/**
-		 * @brief	Constructs a new valid handle for the provided resource with the provided UUID.
-		 *			
-		 * @note	Handle will take ownership of the provided resource pointer, so make sure you don't
-		 *			delete it elsewhere.
-		 */
-		explicit TResourceHandle(T* ptr, const String& uuid)
-			:TResourceHandleBase()
-		{
-			mData = bs_shared_ptr_new<ResourceHandleData>();
-			addRef();
-
-			setHandleData(std::shared_ptr<Resource>(ptr, uuid));
-		}
-
-		/**
-		 * @brief	Constructs an invalid handle with the specified UUID. You must call setHandleData
-		 *			with the actual resource pointer to make the handle valid.
-		 */
-		TResourceHandle(const String& uuid)
-			:TResourceHandleBase()
-		{
-			mData = bs_shared_ptr_new<ResourceHandleData>();
-			mData->mUUID = uuid;
-
-			addRef();
-		}
-
-		/**
-		 * @brief	Constructs a new valid handle for the provided resource with the provided UUID.
-		 */
-		TResourceHandle(const SPtr<T> ptr, const String& uuid)
-			:TResourceHandleBase()
-		{
-			mData = bs_shared_ptr_new<ResourceHandleData>();
-			addRef();
-
-			setHandleData(ptr, uuid);
-		}
-
-		/**
-		 * @brief	Replaces the internal handle data pointer, effectively transforming the handle into a different handle.
-		 */
-		void setHandleData(const SPtr<ResourceHandleData>& data)
-		{
-			releaseRef();
-			mData = data;
-			addRef();
-		}
-
-		/**
-		 * @brief	Converts a weak handle into a normal handle.
-		 */
-		TResourceHandle<T, false> lock() const
-		{
-			TResourceHandle<Resource, false> handle;
-			handle.setHandleData(getHandleData());
-
-			return handle;
-		}
-
-		using TResourceHandleBase::setHandleData;
-	};
-
-	template <typename T>
-	using ResourceHandle = TResourceHandle<T, false>;
-
-	template <typename T>
-	using WeakResourceHandle = TResourceHandle<T, true>;
-	
-	/**
-	 * @brief	Casts one resource handle to another.
-	 */
-	template<class _Ty1, class _Ty2, bool Weak>
-	TResourceHandle<_Ty1, Weak> static_resource_cast(const TResourceHandle<_Ty2, Weak>& other)
-	{	
-		TResourceHandle<_Ty1, Weak> handle;
-		handle.setHandleData(other.getHandleData());
-
-		return handle;
-	}
-
-	/**
-	 * @brief	Checks if two handles point to the same resource.
-	 */
-	template<class _Ty1, bool _Weak1, class _Ty2, bool _Weak2>
-	bool operator==(const TResourceHandle<_Ty1, _Weak1>& _Left, const TResourceHandle<_Ty2, _Weak2>& _Right)
-	{	
-		if(_Left.getHandleData() != nullptr && _Right.getHandleData() != nullptr)
-			return _Left.getHandleData()->mPtr == _Right.getHandleData()->mPtr;
-
-		return _Left.getHandleData() == _Right.getHandleData();
-	}
-
-	/**
-	 * @brief	Checks if a handle is null.
-	 */
-	template<class _Ty1, bool _Weak1, class _Ty2, bool _Weak2>
-	bool operator==(const TResourceHandle<_Ty1, _Weak1>& _Left, std::nullptr_t  _Right)
-	{	
-		return _Left.getHandleData() == nullptr || _Left.getHandleData()->mUUID.empty();
-	}
-
-	template<class _Ty1, bool _Weak1, class _Ty2, bool _Weak2>
-	bool operator!=(const TResourceHandle<_Ty1, _Weak1>& _Left, const TResourceHandle<_Ty2, _Weak2>& _Right)
-	{	
-		return (!(_Left == _Right));
-	}
+#pragma once
+
+#include "BsIReflectable.h"
+
+namespace BansheeEngine
+{
+	/** @addtogroup Implementation
+	 *  @{
+	 */
+
+	/** @cond INTERNAL */
+
+	/**	Data that is shared between all resource handles. */
+	struct BS_CORE_EXPORT ResourceHandleData
+	{
+		ResourceHandleData()
+			:mIsCreated(false), mRefCount(0)
+		{ }
+
+		SPtr<Resource> mPtr;
+		String mUUID;
+		bool mIsCreated;	
+		UINT32 mRefCount;
+	};
+
+	/** @endcond */
+
+	/**
+	 * Represents a handle to a resource. Handles are similar to a smart pointers, but they have two advantages:
+	 *	- When loading a resource asynchronously you can be immediately returned the handle that you may use throughout
+	 *    the engine. The handle will be made valid as soon as the resource is loaded.
+	 *	- Handles can be serialized and deserialized, therefore saving/restoring references to their original resource.
+	 */
+	class BS_CORE_EXPORT ResourceHandleBase : public IReflectable
+	{
+	public:
+		virtual ~ResourceHandleBase();
+
+		/**
+		 * Checks if the resource is loaded. Until resource is loaded this handle is invalid and you may not get the 
+		 * internal resource from it.
+		 *
+		 * @param[in]	checkDependencies	If true, and if resource has any dependencies, this method will also check if 
+		 *									they are loaded.
+		 */
+		bool isLoaded(bool checkDependencies = true) const;
+
+		/**
+		 * Blocks the current thread until the resource is fully loaded.
+		 * 			
+		 * @note	Careful not to call this on the thread that does the loading.
+		 */
+		void blockUntilLoaded(bool waitForDependencies = true) const;
+
+		/**
+		 * Releases an internal reference to this resource held by the resources system, if there is one.
+		 * 			
+		 * @see		Resources::release(ResourceHandleBase&)
+		 */
+		void release();
+
+		/** Returns the UUID of the resource the handle is referring to. */
+		const String& getUUID() const { return mData != nullptr ? mData->mUUID : StringUtil::BLANK; }
+
+		/** @cond INTERNAL */
+
+		/**	Gets the handle data. For internal use only. */
+		const SPtr<ResourceHandleData>& getHandleData() const { return mData; }
+
+		/** @endcond */
+	protected:
+		ResourceHandleBase();
+
+		/**	Destroys the resource the handle is pointing to. */
+		void destroy();
+
+		/**
+		 * Sets the created flag to true and assigns the resource pointer. Called by the constructors, or if you 
+		 * constructed just using a UUID, then you need to call this manually before you can access the resource from 
+		 * this handle.
+		 * 			
+		 * @note	
+		 * This is needed because two part construction is required due to  multithreaded nature of resource loading.
+		 * @note
+		 * Internal method.
+		 */
+		void setHandleData(const SPtr<Resource>& ptr, const String& uuid);
+
+		/** Increments the reference count of the handle. Only to be used by Resources for keeping internal references. */
+		void addInternalRef();
+
+		/** Decrements the reference count of the handle. Only to be used by ::Resources for keeping internal references. */
+		void removeInternalRef();
+
+		/** 
+		 * @note	
+		 * All handles to the same source must share this same handle data. Otherwise things like counting number of 
+		 * references or replacing pointed to resource become impossible without additional logic. */
+		SPtr<ResourceHandleData> mData;
+
+	private:
+		friend class Resources;
+
+		BS_STATIC_THREAD_SYNCHRONISER(mResourceCreatedCondition)
+		BS_STATIC_MUTEX(mResourceCreatedMutex)
+
+	protected:
+		inline void throwIfNotLoaded() const;
+	};
+
+	/**
+	 * @copydoc	ResourceHandleBase
+	 *
+	 * Handles differences in reference counting depending if the handle is normal or weak.
+	 */
+	template <bool WeakHandle>
+	class BS_CORE_EXPORT TResourceHandleBase : public ResourceHandleBase { };
+
+	/**	Specialization of TResourceHandleBase for weak handles. Weak handles do no reference counting. */
+	template<>
+	class BS_CORE_EXPORT TResourceHandleBase<true> : public ResourceHandleBase
+	{
+	public:
+		virtual ~TResourceHandleBase() { }
+
+	protected:
+		void addRef() { };
+		void releaseRef() { };
+
+		/************************************************************************/
+		/* 								RTTI		                     		*/
+		/************************************************************************/
+	public:
+		friend class WeakResourceHandleRTTI;
+		static RTTITypeBase* getRTTIStatic();
+		virtual RTTITypeBase* getRTTI() const override;
+	};
+
+	/**	Specialization of TResourceHandleBase for normal (non-weak) handles. */
+	template<>
+	class BS_CORE_EXPORT TResourceHandleBase<false> : public ResourceHandleBase
+	{
+	public:
+		virtual ~TResourceHandleBase() { }
+
+	protected:
+		void addRef() { if (mData) mData->mRefCount++; };
+		void releaseRef() 
+		{ 
+			if (mData)
+			{
+				mData->mRefCount--;
+
+				if (mData->mRefCount == 0)
+					destroy();
+			}
+		};
+
+		/************************************************************************/
+		/* 								RTTI		                     		*/
+		/************************************************************************/
+	public:
+		friend class WeakResourceHandleRTTI;
+		friend class ResourceHandleRTTI;
+		static RTTITypeBase* getRTTIStatic();
+		virtual RTTITypeBase* getRTTI() const override;
+	};
+
+	/** @copydoc ResourceHandleBase */
+	template <typename T, bool WeakHandle>
+	class TResourceHandle : public TResourceHandleBase<WeakHandle>
+	{
+	public:
+		TResourceHandle()
+			:TResourceHandleBase()
+		{ }
+
+		/**	Copy constructor. */
+		TResourceHandle(const TResourceHandle<T, WeakHandle>& ptr)
+			:TResourceHandleBase()
+		{
+			mData = ptr.getHandleData();
+
+			addRef();
+		}
+
+		virtual ~TResourceHandle()
+		{
+			releaseRef();
+		}
+
+		/**	Converts a specific handle to generic Resource handle. */
+		operator TResourceHandle<Resource, WeakHandle>() const
+		{
+			TResourceHandle<Resource, WeakHandle> handle;
+			handle.setHandleData(getHandleData());
+
+			return handle;
+		}
+
+		/**
+		 * Returns internal resource pointer.
+		 *
+		 * @note	Throws exception if handle is invalid.
+		 */
+		T* operator->() const { return get(); }
+
+		/**
+		 * Returns internal resource pointer and dereferences it.
+		 *
+		 * @note	Throws exception if handle is invalid.
+		 */
+		T& operator*() const { return *get(); }
+
+		/** Clears the handle making it invalid and releases any references held to the resource. */
+		TResourceHandle<T, WeakHandle>& operator=(std::nullptr_t ptr)
+		{ 	
+			releaseRef();
+
+			mData = nullptr;
+			return *this;
+		}
+
+		/**	Normal assignment operator. */
+		TResourceHandle<T, WeakHandle>& operator=(const TResourceHandle<T, WeakHandle>& rhs)
+		{ 	
+			setHandleData(rhs.getHandleData());
+			return *this;
+		}
+
+		template<class _Ty>
+		struct Bool_struct
+		{
+			int _Member;
+		};
+
+		/**
+		 * Allows direct conversion of handle to bool.
+		 *
+		 * @note	This is needed because we can't directly convert to bool since then we can assign pointer to bool and 
+		 *			that's weird.
+		 */
+		operator int Bool_struct<T>::*() const
+		{
+			return ((mData != nullptr && !mData->mUUID.empty()) ? &Bool_struct<T>::_Member : 0);
+		}
+
+		/**
+		 * Returns internal resource pointer and dereferences it.
+		 *
+		 * @note	Throws exception if handle is invalid.
+		 */
+		T* get() const 
+		{ 
+			throwIfNotLoaded();
+
+			return reinterpret_cast<T*>(mData->mPtr.get()); 
+		}
+
+		/**
+		 * Returns the internal shared pointer to the resource.
+		 *
+		 * @note	Throws exception if handle is invalid.
+		 */
+		SPtr<T> getInternalPtr() const
+		{ 
+			throwIfNotLoaded();
+
+			return std::static_pointer_cast<T>(mData->mPtr); 
+		}
+
+		/** Converts a handle into a weak handle. */
+		TResourceHandle<T, true> getWeak() const
+		{
+			TResourceHandle<T, true> handle;
+			handle.setHandleData(getHandleData());
+
+			return handle;
+		}
+
+	protected:
+		friend Resources;
+		template<class _T, bool _Weak>
+		friend class TResourceHandle;
+		template<class _Ty1, class _Ty2, bool Weak>
+		friend TResourceHandle<_Ty1, Weak> static_resource_cast(const TResourceHandle<_Ty2, Weak>& other);
+
+		/**
+		 * Constructs a new valid handle for the provided resource with the provided UUID.
+		 *			
+		 * @note	Handle will take ownership of the provided resource pointer, so make sure you don't delete it elsewhere.
+		 */
+		explicit TResourceHandle(T* ptr, const String& uuid)
+			:TResourceHandleBase()
+		{
+			mData = bs_shared_ptr_new<ResourceHandleData>();
+			addRef();
+
+			setHandleData(std::shared_ptr<Resource>(ptr, uuid));
+		}
+
+		/**
+		 * Constructs an invalid handle with the specified UUID. You must call setHandleData() with the actual resource 
+		 * pointer to make the handle valid.
+		 */
+		TResourceHandle(const String& uuid)
+			:TResourceHandleBase()
+		{
+			mData = bs_shared_ptr_new<ResourceHandleData>();
+			mData->mUUID = uuid;
+
+			addRef();
+		}
+
+		/**	Constructs a new valid handle for the provided resource with the provided UUID. */
+		TResourceHandle(const SPtr<T> ptr, const String& uuid)
+			:TResourceHandleBase()
+		{
+			mData = bs_shared_ptr_new<ResourceHandleData>();
+			addRef();
+
+			setHandleData(ptr, uuid);
+		}
+
+		/**	Replaces the internal handle data pointer, effectively transforming the handle into a different handle. */
+		void setHandleData(const SPtr<ResourceHandleData>& data)
+		{
+			releaseRef();
+			mData = data;
+			addRef();
+		}
+
+		/**	Converts a weak handle into a normal handle. */
+		TResourceHandle<T, false> lock() const
+		{
+			TResourceHandle<Resource, false> handle;
+			handle.setHandleData(getHandleData());
+
+			return handle;
+		}
+
+		using TResourceHandleBase::setHandleData;
+	};
+
+	/**	Checks if two handles point to the same resource. */
+	template<class _Ty1, bool _Weak1, class _Ty2, bool _Weak2>
+	bool operator==(const TResourceHandle<_Ty1, _Weak1>& _Left, const TResourceHandle<_Ty2, _Weak2>& _Right)
+	{	
+		if(_Left.getHandleData() != nullptr && _Right.getHandleData() != nullptr)
+			return _Left.getHandleData()->mPtr == _Right.getHandleData()->mPtr;
+
+		return _Left.getHandleData() == _Right.getHandleData();
+	}
+
+	/**	Checks if a handle is null. */
+	template<class _Ty1, bool _Weak1, class _Ty2, bool _Weak2>
+	bool operator==(const TResourceHandle<_Ty1, _Weak1>& _Left, std::nullptr_t  _Right)
+	{	
+		return _Left.getHandleData() == nullptr || _Left.getHandleData()->mUUID.empty();
+	}
+
+	template<class _Ty1, bool _Weak1, class _Ty2, bool _Weak2>
+	bool operator!=(const TResourceHandle<_Ty1, _Weak1>& _Left, const TResourceHandle<_Ty2, _Weak2>& _Right)
+	{	
+		return (!(_Left == _Right));
+	}
+
+	/** @} */
+
+	/** @addtogroup Resources
+	 *  @{
+	 */
+
+	 /** @copydoc ResourceHandleBase */
+	template <typename T>
+	using ResourceHandle = TResourceHandle<T, false>;
+
+	/** 
+	 * @copydoc ResourceHandleBase 
+	 *
+	 * Weak handles don't prevent the resource from being unloaded.
+	 */
+	template <typename T>
+	using WeakResourceHandle = TResourceHandle<T, true>;
+
+	/**	Casts one resource handle to another. */
+	template<class _Ty1, class _Ty2, bool Weak>
+	TResourceHandle<_Ty1, Weak> static_resource_cast(const TResourceHandle<_Ty2, Weak>& other)
+	{
+		TResourceHandle<_Ty1, Weak> handle;
+		handle.setHandleData(other.getHandleData());
+
+		return handle;
+	}
+
+	/** @} */
 }
 }

+ 85 - 95
BansheeCore/Include/BsResourceListenerManager.h

@@ -1,96 +1,86 @@
-#pragma once
-
-#include "BsCorePrerequisites.h"
-#include "BsModule.h"
-
-namespace BansheeEngine
-{
-	/**
-	 * @brief	Handles all active implementations of IResourceListener interface
-	 *			and notifies them when events they're listening to occur.
-	 *
-	 * @see		IResourceListener
-	 */
-	class BS_CORE_EXPORT ResourceListenerManager : public Module<ResourceListenerManager>
-	{
-	public:
-		ResourceListenerManager();
-		~ResourceListenerManager();
-
-		/**
-		 * @brief	Register a new listener to notify for events.
-		 */
-		void registerListener(IResourceListener* listener);
-
-		/**
-		 * @brief	Unregister a listener so it will no longer receive notifications.
-		 */
-		void unregisterListener(IResourceListener* listener);
-
-		/**
-		 * @brief	Marks the listener as dirty which forces the manager to updates
-		 *			its internal list of resources for the listener.
-		 */
-		void markListenerDirty(IResourceListener* listener);
-
-		/**
-		 * @brief	Refreshes the resource maps based on dirty listeners and sends out the necessary events.
-		 */
-		void update();
-
-		/**
-		 * @brief	Forces the listener to send out events about the specified resource immediately, instead
-		 *			of waiting for the next "update()" call.
-		 */
-		void notifyListeners(const String& resourceUUID);
-
-	private:
-		/**
-		 * @brief	Triggered by the resources system when a resource has finished loading.
-		 */
-		void onResourceLoaded(const HResource& resource);
-
-		/**
-		 * @brief	Triggered by the resources system after a resource handle is modified (i.e. points to a new resource).
-		 */
-		void onResourceModified(const HResource& resource);
-
-		/**
-		 * @brief	Sends resource loaded event to all listeners referencing this resource.
-		 */
-		void sendResourceLoaded(const HResource& resource);
-
-		/**
-		 * @brief	Sends resource modified event to all listeners referencing this resource.
-		 */
-		void sendResourceModified(const HResource& resource);
-
-		/**
-		 * @brief	Clears all the stored dependencies for the listener.
-		 */
-		void clearDependencies(IResourceListener* listener);
-
-		/**
-		 * @brief	Registers all the resource dependencies for the listener.
-		 */
-		void addDependencies(IResourceListener* listener);
-
-		HEvent mResourceLoadedConn;
-		HEvent mResourceModifiedConn;
-		
-		Set<IResourceListener*> mDirtyListeners;
-		Map<UINT64, Vector<IResourceListener*>> mResourceToListenerMap;
-		Map<IResourceListener*, Vector<UINT64>> mListenerToResourceMap;
-
-		Map<String, HResource> mLoadedResources;
-		Map<String, HResource> mModifiedResources;
-
-		Vector<HResource> mTempResourceBuffer;
-
-		BS_RECURSIVE_MUTEX(mMutex);
-
-#if BS_DEBUG_MODE
-		Set<IResourceListener*> mActiveListeners;
-#endif
-	};
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsModule.h"
+
+namespace BansheeEngine
+{
+	/** @cond INTERNAL */
+	/** @addtogroup Resources
+	 *  @{
+	 */
+
+	/**
+	 * Handles all active implementations of IResourceListener interface and notifies them when events they're listening 
+	 * to occur.
+	 *
+	 * @see		IResourceListener
+	 */
+	class BS_CORE_EXPORT ResourceListenerManager : public Module<ResourceListenerManager>
+	{
+	public:
+		ResourceListenerManager();
+		~ResourceListenerManager();
+
+		/**	Register a new listener to notify for events. */
+		void registerListener(IResourceListener* listener);
+
+		/**	Unregister a listener so it will no longer receive notifications. */
+		void unregisterListener(IResourceListener* listener);
+
+		/**
+		 * Marks the listener as dirty which forces the manager to updates its internal list of resources for the 
+		 * listener.
+		 */
+		void markListenerDirty(IResourceListener* listener);
+
+		/**	Refreshes the resource maps based on dirty listeners and sends out the necessary events. */
+		void update();
+
+		/**
+		 * Forces the listener to send out events about the specified resource immediately, instead of waiting for the 
+		 * next update() call.
+		 */
+		void notifyListeners(const String& resourceUUID);
+
+	private:
+		/**	Triggered by the resources system when a resource has finished loading. */
+		void onResourceLoaded(const HResource& resource);
+
+		/**	Triggered by the resources system after a resource handle is modified (i.e. points to a new resource). */
+		void onResourceModified(const HResource& resource);
+
+		/**	Sends resource loaded event to all listeners referencing this resource. */
+		void sendResourceLoaded(const HResource& resource);
+
+		/**	Sends resource modified event to all listeners referencing this resource. */
+		void sendResourceModified(const HResource& resource);
+
+		/**	Clears all the stored dependencies for the listener. */
+		void clearDependencies(IResourceListener* listener);
+
+		/**	Registers all the resource dependencies for the listener. */
+		void addDependencies(IResourceListener* listener);
+
+		HEvent mResourceLoadedConn;
+		HEvent mResourceModifiedConn;
+		
+		Set<IResourceListener*> mDirtyListeners;
+		Map<UINT64, Vector<IResourceListener*>> mResourceToListenerMap;
+		Map<IResourceListener*, Vector<UINT64>> mListenerToResourceMap;
+
+		Map<String, HResource> mLoadedResources;
+		Map<String, HResource> mModifiedResources;
+
+		Vector<HResource> mTempResourceBuffer;
+
+		BS_RECURSIVE_MUTEX(mMutex);
+
+#if BS_DEBUG_MODE
+		Set<IResourceListener*> mActiveListeners;
+#endif
+	};
+
+	/** @} */
+	/** @endcond */
 }
 }

+ 97 - 105
BansheeCore/Include/BsResourceManifest.h

@@ -1,106 +1,98 @@
-#pragma once
-
-#include "BsCorePrerequisites.h"
-#include "BsIReflectable.h"
-
-namespace BansheeEngine
-{
-	/**
-	 * @brief	Serializable class that contains UUID <-> file path mapping for resources.
-	 * 			
-	 * @note	This class allows you to reference resources between sessions. At the end of a session
-	 * 			save the resource manifest, and then restore it at the start of a new session. This way
-	 * 			ensures that resource UUIDs stay consistent and anything referencing them can find the
-	 * 			resources.
-	 *
-	 *			Thread safe.
-	 */
-	class BS_CORE_EXPORT ResourceManifest : public IReflectable
-	{
-		struct ConstructPrivately {};
-	public:
-		explicit ResourceManifest(const ConstructPrivately& dummy);
-		ResourceManifest(const String& name);
-
-		/**
-		 * @brief	Returns an unique name of the resource manifest.
-		 */
-		const String& getName() const { return mName; }
-
-		/**
-		 * @brief	Registers a new resource in the manifest.
-		 */
-		void registerResource(const String& uuid, const Path& filePath);
-
-		/**
-		 * @brief	Removes a resource from the manifest.
-		 */
-		void unregisterResource(const String& uuid);
-
-		/**
-		 * @brief	Attempts to find a resource with the provided UUID and outputs the path
-		 *			to the resource if found. Returns true if UUID was found, false otherwise.
-		 */
-		bool uuidToFilePath(const String& uuid, Path& filePath) const;
-
-		/**
-		 * @brief	Attempts to find a resource with the provided path and outputs the UUID
-		 *			to the resource if found. Returns true if path was found, false otherwise.
-		 */
-		bool filePathToUUID(const Path& filePath, String& outUUID) const;
-
-		/**
-		 * @brief	Checks if provided UUID exists in the manifest.
-		 */
-		bool uuidExists(const String& uuid) const;
-
-		/**
-		 * @brief	Checks if the provided path exists in the manifest.
-		 */
-		bool filePathExists(const Path& filePath) const;
-
-		/**
-		 * @brief	Saves the resource manifest to the specified location.
-		 *
-		 * @param	manifest		Manifest to save.
-		 * @param	path			Full pathname of the file to save the manifest in.
-		 * @param	relativePath	If not empty, all pathnames in the manifest will be stored
-		 * 							as if relative to this path.
-		 */
-		static void save(const ResourceManifestPtr& manifest, const Path& path, const Path& relativePath);
-
-		/**
-		 * @brief	Loads the resource manifest from the specified location.
-		 *
-		 * @param	path			Full pathname of the file to load the manifest from.
-		 * @param	relativePath	If not empty, all loaded pathnames will have this
-		 * 							path prepended.
-		 */
-		static ResourceManifestPtr load(const Path& path, const Path& relativePath);
-
-		/**
-		 * @brief	Creates a new empty resource manifest. Provided name should be unique
-		 *			among manifests.
-		 */
-		static ResourceManifestPtr create(const String& name);
-
-	private:
-		String mName;
-		UnorderedMap<String, Path> mUUIDToFilePath;
-		UnorderedMap<Path, String> mFilePathToUUID;
-
-		/************************************************************************/
-		/* 								RTTI		                     		*/
-		/************************************************************************/
-
-		/**
-		 * @brief	Creates a new empty resource manifest.
-		 */
-		static ResourceManifestPtr createEmpty();
-
-	public:
-		friend class ResourceManifestRTTI;
-		static RTTITypeBase* getRTTIStatic();
-		virtual RTTITypeBase* getRTTI() const override;
-	};
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsIReflectable.h"
+
+namespace BansheeEngine
+{
+	/** @cond INTERNAL */
+	/** @addtogroup Resources
+	 *  @{
+	 */
+
+	/**
+	 * Serializable class that contains UUID <-> file path mapping for resources.
+	 * 			
+	 * @note	
+	 * This class allows you to reference resources between sessions. At the end of a session save the resource manifest, 
+	 * and then restore it at the start of a new session. This way ensures that resource UUIDs stay consistent and anything 
+	 * referencing them can find the resources.
+	 * @note
+	 * Thread safe.
+	 */
+	class BS_CORE_EXPORT ResourceManifest : public IReflectable
+	{
+		struct ConstructPrivately {};
+	public:
+		explicit ResourceManifest(const ConstructPrivately& dummy);
+		ResourceManifest(const String& name);
+
+		/**	Returns an unique name of the resource manifest. */
+		const String& getName() const { return mName; }
+
+		/**	Registers a new resource in the manifest. */
+		void registerResource(const String& uuid, const Path& filePath);
+
+		/**	Removes a resource from the manifest. */
+		void unregisterResource(const String& uuid);
+
+		/**
+		 * Attempts to find a resource with the provided UUID and outputs the path to the resource if found. Returns true
+		 * if UUID was found, false otherwise.
+		 */
+		bool uuidToFilePath(const String& uuid, Path& filePath) const;
+
+		/**
+		 * Attempts to find a resource with the provided path and outputs the UUID to the resource if found. Returns true
+		 * if path was found, false otherwise.
+		 */
+		bool filePathToUUID(const Path& filePath, String& outUUID) const;
+
+		/**	Checks if provided UUID exists in the manifest. */
+		bool uuidExists(const String& uuid) const;
+
+		/**	Checks if the provided path exists in the manifest. */
+		bool filePathExists(const Path& filePath) const;
+
+		/**
+		 * Saves the resource manifest to the specified location.
+		 *
+		 * @param[in]	manifest		Manifest to save.
+		 * @param[in]	path			Full pathname of the file to save the manifest in.
+		 * @param[in]	relativePath	If not empty, all pathnames in the manifest will be stored as if relative to this 
+		 *								path.
+		 */
+		static void save(const ResourceManifestPtr& manifest, const Path& path, const Path& relativePath);
+
+		/**
+		 * Loads the resource manifest from the specified location.
+		 *
+		 * @param[in]	path			Full pathname of the file to load the manifest from.
+		 * @param[in]	relativePath	If not empty, all loaded pathnames will have this path prepended.
+		 */
+		static ResourceManifestPtr load(const Path& path, const Path& relativePath);
+
+		/** Creates a new empty resource manifest. Provided name should be unique among manifests. */
+		static ResourceManifestPtr create(const String& name);
+
+	private:
+		String mName;
+		UnorderedMap<String, Path> mUUIDToFilePath;
+		UnorderedMap<Path, String> mFilePathToUUID;
+
+		/************************************************************************/
+		/* 								RTTI		                     		*/
+		/************************************************************************/
+
+		/**	Creates a new empty resource manifest. */
+		static ResourceManifestPtr createEmpty();
+
+	public:
+		friend class ResourceManifestRTTI;
+		static RTTITypeBase* getRTTIStatic();
+		virtual RTTITypeBase* getRTTI() const override;
+	};
+
+	/** @} */
+	/** @endcond */
 }
 }

+ 28 - 24
BansheeCore/Include/BsResourceMetaData.h

@@ -1,25 +1,29 @@
-#pragma once
-
-#include "BsCorePrerequisites.h"
-#include "BsIReflectable.h"
-#include "BsCoreObject.h"
-
-namespace BansheeEngine
-{
-	/**
-	 * @brief	Class containing meta-information describing a resource.
-	 */
-	class BS_CORE_EXPORT ResourceMetaData : public IReflectable
-	{
-	public:
-		WString displayName;
-
-		/************************************************************************/
-		/* 								SERIALIZATION                      		*/
-		/************************************************************************/
-	public:
-		friend class ResourceMetaDataRTTI;
-		static RTTITypeBase* getRTTIStatic();
-		virtual RTTITypeBase* getRTTI() const;
-	};
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsIReflectable.h"
+#include "BsCoreObject.h"
+
+namespace BansheeEngine
+{
+	/** @addtogroup Resources
+	 *  @{
+	 */
+
+	/**	Class containing meta-information describing a resource. */
+	class BS_CORE_EXPORT ResourceMetaData : public IReflectable
+	{
+	public:
+		WString displayName;
+
+		/************************************************************************/
+		/* 								SERIALIZATION                      		*/
+		/************************************************************************/
+	public:
+		friend class ResourceMetaDataRTTI;
+		static RTTITypeBase* getRTTIStatic();
+		virtual RTTITypeBase* getRTTI() const override;
+	};
+
+	/** @} */
 }
 }

+ 119 - 139
BansheeCore/Include/BsResources.h

@@ -5,12 +5,12 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
+	/** @addtogroup Resources
+	 *  @{
+	 */
+
 	/**
 	/**
-	 * @brief	Manager for dealing with all engine resources. It allows you to save 
-	 *			new resources and load existing ones.
-	 *
-	 *			Used for manually dealing with resources but also for automatic resolving of
-	 *			resource handles.
+	 * Manager for dealing with all engine resources. It allows you to save new resources and load existing ones.
 	 *
 	 *
 	 * @note	Sim thread only.
 	 * @note	Sim thread only.
 	 */
 	 */
@@ -48,29 +48,28 @@ namespace BansheeEngine
 		~Resources();
 		~Resources();
 
 
 		/**
 		/**
-		 * @brief	Loads the resource from a given path. Returns an empty handle if resource can't be loaded.
-		 *			Resource is loaded synchronously.
+		 * Loads the resource from a given path. Returns an empty handle if resource can't be loaded. Resource is loaded 
+		 * synchronously.
 		 *			
 		 *			
-		 *			All loaded resources are reference counted and will be automatically unloaded when all of their references go out
-		 *			of scope. 
+		 * All loaded resources are reference counted and will be automatically unloaded when all of their references go out
+		 * of scope. 
 		 *			
 		 *			
-		 * @param	filePath				File path to the resource to load. This can be absolute or relative to the working folder.
-		 * @param	loadDependencies		If true all resources referenced by the root resource will be loaded as well.
-		 * @param	keepInternalReference	If true the resource system will keep an internal reference to the resource so it
-		 *									doesn't get destroyed with it goes out of scope. You can call release() to release 
-		 *									the internal reference. Each call to load will create a new internal reference and 
-		 *									therefore must be followed by the same number of release calls. 
-		 *									
-		 *									If dependencies are being loaded, they will not have internal references created regardless
-		 *									of this parameter.
+		 * @param[in]	filePath				File path to the resource to load. This can be absolute or relative to 
+		 *										the working folder.
+		 * @param[in]	loadDependencies		If true all resources referenced by the root resource will be loaded as well.
+		 * @param[in]	keepInternalReference	If true the resource system will keep an internal reference to the resource
+		 *										so it doesn't get destroyed with it goes out of scope. You can call 
+		 *										release() to release the internal reference. Each call to load will create
+		 *										a new internal reference and therefore must be followed by the same number
+		 *										of release calls. 
+		 *										If dependencies are being loaded, they will not have internal references 
+		 *										created regardless of this parameter.
 		 *			
 		 *			
 		 * @see		release(ResourceHandleBase&), unloadAllUnused()
 		 * @see		release(ResourceHandleBase&), unloadAllUnused()
 		 */
 		 */
 		HResource load(const Path& filePath, bool loadDependencies = true, bool keepInternalReference = true);
 		HResource load(const Path& filePath, bool loadDependencies = true, bool keepInternalReference = true);
 
 
-		/**
-		 * @copydoc	load(const Path&, bool)
-		 */
+		/** @copydoc load(const Path&, bool) */
 		template <class T>
 		template <class T>
 		ResourceHandle<T> load(const Path& filePath, bool loadDependencies = true, bool keepInternalReference = true)
 		ResourceHandle<T> load(const Path& filePath, bool loadDependencies = true, bool keepInternalReference = true)
 		{
 		{
@@ -78,15 +77,13 @@ namespace BansheeEngine
 		}
 		}
 
 
 		/**
 		/**
-		 * @brief	Loads the resource for the provided weak resource handle, or returns a loaded resource if already loaded.
+		 * Loads the resource for the provided weak resource handle, or returns a loaded resource if already loaded.
 		 * 			
 		 * 			
 		 * @see		load(const Path&, bool)
 		 * @see		load(const Path&, bool)
 		 */
 		 */
 		HResource load(const WeakResourceHandle<Resource>& handle, bool loadDependencies = true, bool keepInternalReference = true);
 		HResource load(const WeakResourceHandle<Resource>& handle, bool loadDependencies = true, bool keepInternalReference = true);
 
 
-		/**
-		 * @copydoc	load(const WeakResourceHandle<T>&, bool)
-		 */
+		/** @copydoc load(const WeakResourceHandle<T>&, bool) */
 		template <class T>
 		template <class T>
 		ResourceHandle<T> load(const WeakResourceHandle<T>& handle, bool loadDependencies = true, bool keepInternalReference = true)
 		ResourceHandle<T> load(const WeakResourceHandle<T>& handle, bool loadDependencies = true, bool keepInternalReference = true)
 		{
 		{
@@ -94,21 +91,20 @@ namespace BansheeEngine
 		}
 		}
 
 
 		/**
 		/**
-		 * @brief	Loads the resource asynchronously. Initially returned resource handle will be invalid
-		 *			until resource loading is done.
+		 * Loads the resource asynchronously. Initially returned resource handle will be invalid until resource loading is 
+		 * done.
 		 *
 		 *
-		 * @param	filePath	Full pathname of the file.
+		 * @param[in]	filePath	Full pathname of the file.
 		 * 						
 		 * 						
-		 * @note	You can use returned invalid handle in many engine systems as the engine will check for handle 
-		 *			validity before using it.
+		 * @note	
+		 * You can use returned invalid handle in many engine systems as the engine will check for handle validity before 
+		 * using it.
 		 *			
 		 *			
 		 * @see		load(const Path&, bool)
 		 * @see		load(const Path&, bool)
 		 */
 		 */
 		HResource loadAsync(const Path& filePath, bool loadDependencies = true, bool keepInternalReference = true);
 		HResource loadAsync(const Path& filePath, bool loadDependencies = true, bool keepInternalReference = true);
 
 
-		/**
-		 * @copydoc	loadAsync
-		 */
+		/** @copydoc loadAsync */
 		template <class T>
 		template <class T>
 		ResourceHandle<T> loadAsync(const Path& filePath, bool loadDependencies = true, bool keepInternalReference = true)
 		ResourceHandle<T> loadAsync(const Path& filePath, bool loadDependencies = true, bool keepInternalReference = true)
 		{
 		{
@@ -116,57 +112,57 @@ namespace BansheeEngine
 		}
 		}
 
 
 		/**
 		/**
-		 * @brief	Loads the resource with the given UUID. Returns an empty handle if resource can't be loaded.
+		 * Loads the resource with the given UUID. Returns an empty handle if resource can't be loaded.
 		 *
 		 *
-		 * @param	uuid					UUID of the resource to load.
-		 * @param	async					If true resource will be loaded asynchronously. Handle to non-loaded
-		 *									resource will be returned immediately while loading will continue in the background.		
-		 * @param	loadDependencies		If true all resources referenced by the root resource will be loaded as well.
-		 * @param	keepInternalReference	If true the resource system will keep an internal reference to the resource so it
-		 *									doesn't get destroyed with it goes out of scope. You can call ::release to release 
-		 *									the internal reference. Each call to load will create a new internal reference and 
-		 *									therefore must be followed by the same number of release calls. 
-		 *									
-		 *									If dependencies are being loaded, they will not have internal references created regardless
-		 *									of this parameter.	
+		 * @param[in]	uuid					UUID of the resource to load.
+		 * @param[in]	async					If true resource will be loaded asynchronously. Handle to non-loaded
+		 *										resource will be returned immediately while loading will continue in the 
+		 *										background.		
+		 * @param[in]	loadDependencies		If true all resources referenced by the root resource will be loaded as well.
+		 * @param[in]	keepInternalReference	If true the resource system will keep an internal reference to the resource 
+		 *										so it doesn't get destroyed with it goes out of scope. You can call 
+		 *										release() to release the internal reference. Each call to load will create 
+		 *										a new internal reference and therefore must be followed by the same number 
+		 *										of release calls. 
+		 *										If dependencies are being loaded, they will not have internal references 
+		 *										created regardless of this parameter.	
 		 *													
 		 *													
 		 * @see		load(const Path&, bool)
 		 * @see		load(const Path&, bool)
 		 */
 		 */
 		HResource loadFromUUID(const String& uuid, bool async = false, bool loadDependencies = true, bool keepInternalReference = true);
 		HResource loadFromUUID(const String& uuid, bool async = false, bool loadDependencies = true, bool keepInternalReference = true);
 
 
 		/**
 		/**
-		 * @brief	Releases an internal reference to the resource held by the resources system. This allows the resource
-		 * 			to be unloaded when it goes out of scope, if the resource was loaded with "keepInternalReference" parameter.
+		 * Releases an internal reference to the resource held by the resources system. This allows the resource to be 
+		 * unloaded when it goes out of scope, if the resource was loaded with @p keepInternalReference parameter.
 		 *
 		 *
-		 *			Alternatively you can also skip manually calling release() and call ::unloadAllUnused which will unload 
-		 *			all resources that do not have any external references, but you lose the fine grained control of what 
-		 *			will be unloaded.
+		 * Alternatively you can also skip manually calling release() and call ::unloadAllUnused which will unload all 
+		 * resources that do not have any external references, but you lose the fine grained control of what will be 
+		 * unloaded.
 		 *			
 		 *			
 		 * @param	resourceHandle	Handle of the resource to release.
 		 * @param	resourceHandle	Handle of the resource to release.
 		 */
 		 */
 		void release(ResourceHandleBase& resource);
 		void release(ResourceHandleBase& resource);
 
 
 		/**
 		/**
-		 * @brief	Finds all resources that aren't being referenced outside of the resources system and unloads them.
+		 * Finds all resources that aren't being referenced outside of the resources system and unloads them.
 		 * 			
 		 * 			
 		 * @see		release(ResourceHandleBase&)
 		 * @see		release(ResourceHandleBase&)
 		 */
 		 */
 		void unloadAllUnused();
 		void unloadAllUnused();
 
 
 		/**
 		/**
-		 * @brief	Saves the resource at the specified location.
-		 *
-		 * @param	resource 	Handle to the resource.
-		 * @param	filePath 	Full pathname of the file to save as.
-		 * @param	overwrite	(optional) If true, any existing resource at the specified location will
-		 * 						be overwritten.
-		 * 						
-		 * @note	If the resource is a GpuResource and you are in some way modifying it from the Core thread, make
-		 * 			sure all those commands are submitted before you call this method. Otherwise an obsolete
-		 * 			version of the resource might get saved.
+		 * Saves the resource at the specified location.
 		 *
 		 *
-		 *			If saving a core thread resource this is a potentially very slow operation as we must wait on the 
-		 *			core thread and the GPU in order to read the resource.
+		 * @param[in]	resource 	Handle to the resource.
+		 * @param[in]	filePath 	Full pathname of the file to save as.
+		 * @param[in]	overwrite	(optional) If true, any existing resource at the specified location will be overwritten.
+		 * 			
+		 * @note
+		 * If the resource is a GpuResource and you are in some way modifying it from the core thread, make sure all those
+		 * commands are submitted before you call this method. Otherwise an obsolete version of the resource might get saved.
+		 * @note
+		 * If saving a core thread resource this is a potentially very slow operation as we must wait on the core thread 
+		 * and the GPU in order to read the resource.
 		 */
 		 */
 		void save(const HResource& resource, const Path& filePath, bool overwrite);
 		void save(const HResource& resource, const Path& filePath, bool overwrite);
 
 
@@ -175,110 +171,103 @@ namespace BansheeEngine
 		 *
 		 *
 		 * @param	resource 	Handle to the resource.
 		 * @param	resource 	Handle to the resource.
 		 *
 		 *
-		 * @note	If the resource is a GpuResource and you are in some way modifying it from the Core thread, make
-		 * 			sure all those commands are submitted before you call this method. Otherwise an obsolete
-		 * 			version of the resource might get saved.
-		 *
-		 *			If saving a core thread resource this is a potentially very slow operation as we must wait on the
-		 *			core thread and the GPU in order to read the resource.
+		 * @note	
+		 * If the resource is a GpuResource and you are in some way modifying it from the Core thread, make sure all those
+		 * commands are submitted before you call this method. Otherwise an obsolete version of the resource might get saved.
+		 * @note
+		 * If saving a core thread resource this is a potentially very slow operation as we must wait on the core thread 
+		 * and the GPU in order to read the resource.
 		 */
 		 */
 		void save(const HResource& resource);
 		void save(const HResource& resource);
 
 
 		/**
 		/**
-		 * @brief	Updates an existing resource handle with a new resource. Caller must ensure that
-		 * 			new resource type matches the original resource type.
+		 * Updates an existing resource handle with a new resource. Caller must ensure that new resource type matches the 
+		 * original resource type.
 		 */
 		 */
 		void update(HResource& handle, const ResourcePtr& resource);
 		void update(HResource& handle, const ResourcePtr& resource);
 
 
 		/**
 		/**
-		 * @brief	Returns a list of dependencies from the resources at the specified path. Resource will not be loaded
-		 *			or parsed, but instead the saved list of dependencies will be read from the file and returned.
-		 *
-		 * @param	filePath	Full path to the resource to get dependencies for.
+		 * Returns a list of dependencies from the resources at the specified path. Resource will not be loaded or parsed, 
+		 * but instead the saved list of dependencies will be read from the file and returned.
 		 *
 		 *
-		 * @returns	List of dependencies represented as UUIDs.
+		 * @param[in]	filePath	Full path to the resource to get dependencies for.
+		 * @return					List of dependencies represented as UUIDs.
 		 */
 		 */
 		Vector<String> getDependencies(const Path& filePath);
 		Vector<String> getDependencies(const Path& filePath);
 
 
 		/**
 		/**
-		 * @brief	Checks is the resource with the specified UUID loaded.
+		 * Checks is the resource with the specified UUID loaded.
 		 *
 		 *
-		 * @param	uuid			UUID of the resource to check.
-		 * @param	checkInProgress	Should this method also check resources that are in progress of being asynchronously loaded.
-		 * 							
-		 * @return	True if loaded or loading in progress, false otherwise.
+		 * @param[in]	uuid			UUID of the resource to check.
+		 * @param[in]	checkInProgress	Should this method also check resources that are in progress of being 
+		 *								asynchronously loaded.					
+		 * @return						True if loaded or loading in progress, false otherwise.
 		 */
 		 */
 		bool isLoaded(const String& uuid, bool checkInProgress = true);
 		bool isLoaded(const String& uuid, bool checkInProgress = true);
 
 
 		/**
 		/**
-		 * @brief	Creates a new resource handle from a resource pointer. 
+		 *Allows you to set a resource manifest containing UUID <-> file path mapping that is used when resolving 
+		 * resource references.
 		 *
 		 *
-		 * @note	Internal method used primarily be resource factory methods.
-		 */
-		HResource _createResourceHandle(const ResourcePtr& obj);
-
-		/**
-		 * @brief	Returns an existing handle for the specified UUID if one exists, or creates a new one.
-		 */
-		HResource _getResourceHandle(const String& uuid);
-
-		/**
-		 * @brief	Allows you to set a resource manifest containing UUID <-> file path mapping that is
-		 * 			used when resolving resource references.
-		 *
-		 * @note	If you want objects that reference resources (using ResourceHandles) to be able to
-		 * 			find that resource even after application restart, then you must save the resource
-		 * 			manifest before closing the application and restore it upon startup.
-		 * 			Otherwise resources will be assigned brand new UUIDs and references will be broken.
+		 * @note	
+		 * If you want objects that reference resources (using ResourceHandles) to be able to find that resource even after
+		 * application restart, then you must save the resource manifest before closing the application and restore it 
+		 * upon startup. Otherwise resources will be assigned brand new UUIDs and references will be broken.
 		 */
 		 */
 		void registerResourceManifest(const ResourceManifestPtr& manifest);
 		void registerResourceManifest(const ResourceManifestPtr& manifest);
 
 
-		/**
-		 * @brief	Unregisters a resource manifest previously registered with ::registerResourceManifest.
-		 */
+		/**	Unregisters a resource manifest previously registered with registerResourceManifest(). */
 		void unregisterResourceManifest(const ResourceManifestPtr& manifest);
 		void unregisterResourceManifest(const ResourceManifestPtr& manifest);
 
 
 		/**
 		/**
-		 * @brief	Allows you to retrieve resource manifest containing UUID <-> file path mapping that is
-		 * 			used when resolving resource references.
+		 * Allows you to retrieve resource manifest containing UUID <-> file path mapping that is used when resolving 
+		 * resource references.
 		 * 			
 		 * 			
-		 * @note	Resources module internally holds a "Default" manifest that it automatically updated whenever
-		 * 			a resource is saved.
+		 * @note	
+		 * Resources module internally holds a "Default" manifest that it automatically updated whenever a resource is saved.
 		 *
 		 *
 		 * @see		registerResourceManifest
 		 * @see		registerResourceManifest
 		 */
 		 */
 		ResourceManifestPtr getResourceManifest(const String& name) const;
 		ResourceManifestPtr getResourceManifest(const String& name) const;
 
 
-		/**
-		 * @brief	Attempts to retrieve file path from the provided UUID. Returns true
-		 *			if successful, false otherwise.
-		 */
+		/** Attempts to retrieve file path from the provided UUID. Returns true if successful, false otherwise. */
 		bool getFilePathFromUUID(const String& uuid, Path& filePath) const;
 		bool getFilePathFromUUID(const String& uuid, Path& filePath) const;
 
 
+		/** Attempts to retrieve UUID from the provided file path. Returns true if successful, false otherwise. */
+		bool getUUIDFromFilePath(const Path& path, String& uuid) const;
+
+		/** @cond INTERNAL */
+
 		/**
 		/**
-		 * @brief	Attempts to retrieve UUID from the provided file path. Returns true
-		 *			if successful, false otherwise.
+		 * Creates a new resource handle from a resource pointer. 
+		 *
+		 * @note	Internal method used primarily be resource factory methods.
 		 */
 		 */
-		bool getUUIDFromFilePath(const Path& path, String& uuid) const;
+		HResource _createResourceHandle(const ResourcePtr& obj);
+
+		/** Returns an existing handle for the specified UUID if one exists, or creates a new one. */
+		HResource _getResourceHandle(const String& uuid);
+
+		/** @endcond */
 
 
 		/**
 		/**
-		 * @brief	Called when the resource has been successfully loaded. 
+		 * Called when the resource has been successfully loaded. 
 		 *
 		 *
-		 * @note	It is undefined from which thread this will get called from.
-		 *			Most definitely not the sim thread if resource was being loaded
-		 *			asynchronously.
+		 * @note	
+		 * It is undefined from which thread this will get called from. Most definitely not the sim thread if resource was
+		 * being loaded asynchronously.
 		 */
 		 */
 		Event<void(const HResource&)> onResourceLoaded;
 		Event<void(const HResource&)> onResourceLoaded;
 
 
 		/**
 		/**
-		 * @brief	Called when the resource has been destroyed. Provides UUID of the destroyed resource.
+		 * Called when the resource has been destroyed. Provides UUID of the destroyed resource.
 		 *
 		 *
 		 * @note	It is undefined from which thread this will get called from.
 		 * @note	It is undefined from which thread this will get called from.
 		 */
 		 */
 		Event<void(const String&)> onResourceDestroyed;
 		Event<void(const String&)> onResourceDestroyed;
 
 
 		/**
 		/**
-		 * @brief	Called when the internal resource the handle is pointing to has changed.
+		 * Called when the internal resource the handle is pointing to has changed.
 		 *
 		 *
 		 * @note	It is undefined from which thread this will get called from.
 		 * @note	It is undefined from which thread this will get called from.
 		 */
 		 */
@@ -287,33 +276,24 @@ namespace BansheeEngine
 		friend class ResourceHandleBase;
 		friend class ResourceHandleBase;
 
 
 		/**
 		/**
-		 * @brief	Starts resource loading or returns an already loaded resource. Both UUID and filePath must match the
-		 * 			same resource, although you may provide an empty path in which case the resource will be retrieved
-		 * 			from memory if its currently loaded.
+		 * Starts resource loading or returns an already loaded resource. Both UUID and filePath must match the	same 
+		 * resource, although you may provide an empty path in which case the resource will be retrieved from memory if its
+		 * currently loaded.
 		 * 			
 		 * 			
-		 * @param	incrementRef	Determines should the internal reference count be incremented.
+		 * @param[in]	incrementRef	Determines should the internal reference count be incremented.
 		 */
 		 */
 		HResource loadInternal(const String& UUID, const Path& filePath, bool synchronous, bool loadDependencies, bool incrementRef);
 		HResource loadInternal(const String& UUID, const Path& filePath, bool synchronous, bool loadDependencies, bool incrementRef);
 
 
-		/**
-		 * @brief	Performs actually reading and deserializing of the resource file. 
-		 *			Called from various worker threads.
-		 */
+		/** Performs actually reading and deserializing of the resource file. Called from various worker threads. */
 		ResourcePtr loadFromDiskAndDeserialize(const Path& filePath);
 		ResourcePtr loadFromDiskAndDeserialize(const Path& filePath);
 
 
-		/**
-		 * @brief	Triggered when individual resource has finished loading.
-		 */
+		/**	Triggered when individual resource has finished loading. */
 		void loadComplete(HResource& resource);
 		void loadComplete(HResource& resource);
 
 
-		/**
-		 * @brief	Callback triggered when the task manager is ready to process the loading task.
-		 */
+		/**	Callback triggered when the task manager is ready to process the loading task. */
 		void loadCallback(const Path& filePath, HResource& resource);
 		void loadCallback(const Path& filePath, HResource& resource);
 
 
-		/**
-		 * @brief	Destroys a resource, freeing its memory.
-		 */
+		/**	Destroys a resource, freeing its memory. */
 		void destroy(ResourceHandleBase& resource);
 		void destroy(ResourceHandleBase& resource);
 
 
 	private:
 	private:
@@ -329,8 +309,8 @@ namespace BansheeEngine
 		UnorderedMap<String, Vector<ResourceLoadData*>> mDependantLoads; // Allows dependency to be notified when a dependant is loaded
 		UnorderedMap<String, Vector<ResourceLoadData*>> mDependantLoads; // Allows dependency to be notified when a dependant is loaded
 	};
 	};
 
 
-	/**
-	 * @brief	Provides global access to the resource manager.
-	 */
+	/** Provides easier access to Resources manager. */
 	BS_CORE_EXPORT Resources& gResources();
 	BS_CORE_EXPORT Resources& gResources();
+
+	/** @} */
 }
 }

+ 44 - 41
BansheeCore/Include/BsSavedResourceData.h

@@ -1,42 +1,45 @@
-#pragma once
-
-#include "BsCorePrerequisites.h"
-#include "BsIReflectable.h"
-
-namespace BansheeEngine
-{
-	/**
-	 * @brief	Contains information about a resource saved to the disk.
-	 *
-	 * @note	Purpose of this class is primarily to be a wrapper around a list of objects
-	 *			to make serialization easier.
-	 */
-	class BS_CORE_EXPORT SavedResourceData : public IReflectable
-	{
-	public:
-		SavedResourceData();
-		SavedResourceData(const Vector<String>& dependencies, bool allowAsync);
-
-		/**
-		 * @brief	Returns a list of all resource dependencies.
-		 */
-		const Vector<String>& getDependencies() const { return mDependencies; }
-
-		/**
-		 * @brief	Returns true if this resource is allow to be asynchronously loaded.
-		 */
-		bool allowAsyncLoading() const { return mAllowAsync; }
-
-	private:
-		Vector<String> mDependencies;
-		bool mAllowAsync;
-
-	/************************************************************************/
-	/* 								SERIALIZATION                      		*/
-	/************************************************************************/
-	public:
-		friend class SavedResourceDataRTTI;
-		static RTTITypeBase* getRTTIStatic();
-		virtual RTTITypeBase* getRTTI() const;
-	};
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsIReflectable.h"
+
+namespace BansheeEngine
+{
+	/** @cond INTERNAL */
+	/** @addtogroup Resources
+	 *  @{
+	 */
+
+	/**
+	 * Contains information about a resource saved to the disk.
+	 *
+	 * @note Purpose of this class is primarily to be a wrapper around a list of objects to make serialization easier.
+	 */
+	class BS_CORE_EXPORT SavedResourceData : public IReflectable
+	{
+	public:
+		SavedResourceData();
+		SavedResourceData(const Vector<String>& dependencies, bool allowAsync);
+
+		/**	Returns a list of all resource dependencies. */
+		const Vector<String>& getDependencies() const { return mDependencies; }
+
+		/**	Returns true if this resource is allow to be asynchronously loaded. */
+		bool allowAsyncLoading() const { return mAllowAsync; }
+
+	private:
+		Vector<String> mDependencies;
+		bool mAllowAsync;
+
+	/************************************************************************/
+	/* 								SERIALIZATION                      		*/
+	/************************************************************************/
+	public:
+		friend class SavedResourceDataRTTI;
+		static RTTITypeBase* getRTTIStatic();
+		virtual RTTITypeBase* getRTTI() const override;
+	};
+
+	/** @} */
+	/** @endcond */
 }
 }

+ 46 - 42
BansheeCore/Include/BsShaderInclude.h

@@ -1,43 +1,47 @@
-#pragma once
-
-#include "BsCorePrerequisites.h"
-#include "BsResource.h"
-
-namespace BansheeEngine
-{
-	/**
-	 * @brief	Raw text resource that serves as an include file for shaders.
-	 */
-	class BS_CORE_EXPORT ShaderInclude : public Resource
-	{
-	public:
-		/**
-		 * @brief	Text of the include file.
-		 */
-		const String& getString() const { return mString; }
-
-		/**
-		 * @brief	Creates a new include file resource with the specified include string.
-		 */
-		static HShaderInclude create(const String& includeString);
-
-		/**
-		 * @brief	Creates an include file resource with the specified include string.
-		 *
-		 * @note	Internal method. Use "create" for normal use.
-		 */
-		static ShaderIncludePtr _createPtr(const String& includeString);
-	private:
-		ShaderInclude(const String& includeString);
-
-		String mString;
-
-		/************************************************************************/
-		/* 								SERIALIZATION                      		*/
-		/************************************************************************/
-	public:
-		friend class ShaderIncludeRTTI;
-		static RTTITypeBase* getRTTIStatic();
-		virtual RTTITypeBase* getRTTI() const override;
-	};
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsResource.h"
+
+namespace BansheeEngine
+{
+	/** @addtogroup Resources
+	 *  @{
+	 */
+
+	/**	Raw text resource that serves as an include file for shaders. */
+	class BS_CORE_EXPORT ShaderInclude : public Resource
+	{
+	public:
+		/**	Text of the include file. */
+		const String& getString() const { return mString; }
+
+		/**	Creates a new include file resource with the specified include string. */
+		static HShaderInclude create(const String& includeString);
+
+		/** @cond INTERNAL */
+
+		/**
+		 * Creates an include file resource with the specified include string.
+		 *
+		 * @note	Internal method. Use create() for normal use.
+		 */
+		static ShaderIncludePtr _createPtr(const String& includeString);
+
+		/** @endcond */
+	private:
+		ShaderInclude(const String& includeString);
+
+		String mString;
+
+		/************************************************************************/
+		/* 								SERIALIZATION                      		*/
+		/************************************************************************/
+	public:
+		friend class ShaderIncludeRTTI;
+		static RTTITypeBase* getRTTIStatic();
+		virtual RTTITypeBase* getRTTI() const override;
+	};
+
+	/** @} */
 }
 }

+ 461 - 511
BansheeCore/Include/BsTexture.h

@@ -1,512 +1,462 @@
-#pragma once
-
-#include "BsCorePrerequisites.h"
-#include "BsResource.h"
-#include "BsHardwareBuffer.h"
-#include "BsPixelUtil.h"
-#include "BsTextureView.h"
-
-namespace BansheeEngine 
-{
-	/**
-	 * @brief	Flags that describe how is a texture used.
-	 */
-    enum TextureUsage
-    {
-		TU_STATIC = GBU_STATIC, /**< A regular texture that is not often or ever updated from the CPU. */
-		TU_DYNAMIC = GBU_DYNAMIC, /**< A regular texture that is often updated by the CPU. */
-		TU_RENDERTARGET = 0x200, /**< Texture that can be rendered to by the GPU. */
-		TU_DEPTHSTENCIL = 0x400, /**< Texture used as a depth/stencil buffer by the GPU. */
-		TU_LOADSTORE = 0x800, /**< Texture that allows load/store operations from the GPU program. */
-		TU_CPUCACHED = 0x1000, /**< Ensures all texture data will also be cached in system memory. */
-		TU_DEFAULT = TU_STATIC
-    };
-
-	/**
-	 * @brief	Different texture types.
-	 */
-    enum TextureType
-    {
-		TEX_TYPE_1D = 1, /**< One dimensional texture. Just a row of pixels. */
-		TEX_TYPE_2D = 2, /**< Two dimensional texture. */
-		TEX_TYPE_3D = 3, /**< Three dimensional texture. */
-		TEX_TYPE_CUBE_MAP = 4 /**< Texture consisting out of six 2D textures describing an inside of a cube. Allows special sampling. */
-    };
-
-	/**
-	 * @brief	Mipmap options.
-	 */
-	enum TextureMipmap
-	{
-		MIP_UNLIMITED = 0x7FFFFFFF /**< Create all mip maps down to 1x1. */
-	};
-
-	/**
-	 * @brief	Contains various information about a texture
-	 */
-	class BS_CORE_EXPORT TextureProperties
-	{
-	public:
-		TextureProperties();
-		TextureProperties(TextureType textureType, UINT32 width, UINT32 height, UINT32 depth, UINT32 numMipmaps,
-			PixelFormat format, int usage, bool hwGamma, UINT32 multisampleCount);
-
-		/**
-         * @brief	Gets the type of texture.
-         */
-        TextureType getTextureType() const { return mTextureType; }
-
-        /**
-		 * @brief	Gets the number of mipmaps to be used for this texture. This number excludes the top level  
-		 *			map (which is always assumed to be present).
-         */
-        UINT32 getNumMipmaps() const {return mNumMipmaps;}
-
-		/**
-		 * @brief	Gets whether this texture will be set up so that on sampling it,
-		 *			hardware gamma correction is applied.
-		 */
-		bool isHardwareGammaEnabled() const { return mHwGamma; }
-
-		/**
-		 * @brief	Gets the number of samples used for multisampling.
-		 *			(0 if multisampling is not used).
-		 */
-		UINT32 getMultisampleCount() const { return mMultisampleCount; }
-
-        /**
-         * @brief	Returns the height of the texture.
-         */
-        UINT32 getHeight() const { return mHeight; }
-
-        /**
-         * @brief	Returns the width of the texture.
-         */
-        UINT32 getWidth() const { return mWidth; }
-
-        /**
-         * @brief	Returns the depth of the texture (only applicable for 3D textures).
-         */
-        UINT32 getDepth() const { return mDepth; }
-
-        /**
-         * @brief	Returns texture usage (TextureUsage) of this texture.
-         */
-        int getUsage() const { return mUsage; }
-
-		/**
-		 * @brief	Returns the pixel format for the texture surface.
-		 */
-		PixelFormat getFormat() const { return mFormat; }
-
-        /**
-         * @brief	Returns true if the texture has an alpha layer.
-         */
-        bool hasAlpha() const;
-
-        /**
-         * @brief	Return the number of faces this texture has.
-         */
-        UINT32 getNumFaces() const;
-
-		/**
-		 * @brief	Maps a sub-resource index to an exact face and mip level. Sub-resource indexes
-		 * 			are used when reading or writing to the resource.
-		 * 			
-		 * @note	Sub-resource index is only valid for the instance it was created on. You cannot use a sub-resource
-		 * 			index from a different texture and expect to get valid result. Modifying the resource so the number
-		 * 			of sub-resources changes invalidates all sub-resource indexes.
-		 */
-		void mapFromSubresourceIdx(UINT32 subresourceIdx, UINT32& face, UINT32& mip) const;
-
-		/**
-		 * @brief	Map a face and a mip level to a sub-resource index you can use for updating or reading
-		 * 			a specific sub-resource.
-		 * 			
-		 * @note	Generated sub-resource index is only valid for the instance it was created on. Modifying the resource so the number
-		 * 			of sub-resources changes, invalidates all sub-resource indexes.
-		 */
-		UINT32 mapToSubresourceIdx(UINT32 face, UINT32 mip) const;
-
-		/**
-		 * @brief	Allocates a buffer you may use for storage when reading or writing a sub-resource. You
-		 * 			need to allocate such a buffer if you are calling "readSubresource".
-		 *
-		 *			You can retrieve a sub-resource index by calling "mapToSubresourceIdx".
-		 * 			
-		 * @note	Thread safe.
-		 */
-		PixelDataPtr allocateSubresourceBuffer(UINT32 subresourceIdx) const;
-
-	protected:
-		friend class TextureRTTI;
-
-		UINT32 mHeight;
-		UINT32 mWidth;
-		UINT32 mDepth;
-
-		UINT32 mNumMipmaps;
-		bool mHwGamma;
-		UINT32 mMultisampleCount;
-
-		TextureType mTextureType;
-		PixelFormat mFormat;
-		int mUsage;
-	};
-
-	/**
-	 * @brief	Core thread version of a Texture.
-	 *
-	 * @see		Texture
-	 *
-	 * @note	Core thread.
-	 */
-	class BS_CORE_EXPORT TextureCore : public CoreObjectCore
-	{
-	public:
-		TextureCore(TextureType textureType, UINT32 width, UINT32 height, UINT32 depth, UINT32 numMipmaps,
-			PixelFormat format, int usage, bool hwGamma, UINT32 multisampleCount, const PixelDataPtr& initData);
-		virtual ~TextureCore() {}
-
-
-		/**
-		 * @copydoc	CoreObjectCore::initialize
-		 */
-		virtual void initialize() override;
-
-		/**
-		 * @brief	Updates a part of the texture with the provided data.
-		 *
-		 * @param	subresourceIdx		Index of the subresource to update, if the texture has more than one.
-		 * @param	data				Data to update the texture with.
-		 * @param	discardEntireBuffer When true the existing contents of the resource you are updating will be discarded. This can make the
-		 * 								operation faster. Resources with certain buffer types might require this flag to be in a specific state
-		 * 								otherwise the operation will fail.
-		 */
-		virtual void writeSubresource(UINT32 subresourceIdx, const PixelData& data, bool discardEntireBuffer);
-
-		/**
-		 * @brief	Reads a part of the current resource into the provided "data" parameter.
-		 * 			Data buffer needs to be pre-allocated.
-		 *
-		 * @param	subresourceIdx		Index of the subresource to update, if the texture has more than one.
-		 * @param	data				Buffer that will receive the data. Should be allocated with "allocateSubresourceBuffer"
-		 *								to ensure it is of valid type and size.
-		 */
-		virtual void readSubresource(UINT32 subresourceIdx, PixelData& data);
-
-		/**
-		 * @brief	Locks the buffer for reading or writing.
-		 *
-		 * @param	options 	Options for controlling what you may do with the locked data.
-		 * @param	mipLevel	(optional) Mipmap level to lock.
-		 * @param	face		(optional) Texture face to lock.
-		 * 						
-		 * @return	Pointer to the buffer data. Only valid until you call unlock.
-		 * 			
-		 * @note	If you are just reading or writing one block of data use
-		 * 			readData/writeData methods as they can be much faster in certain situations.
-		 */
-		PixelData lock(GpuLockOptions options, UINT32 mipLevel = 0, UINT32 face = 0);
-
-		/**
-		 * @brief	Unlocks a previously locked buffer. After the buffer is unlocked,
-		 * 			any data returned by lock becomes invalid.
-		 */
-		void unlock();
-
-		/**
-		 * @brief	Copies the contents a subresource in this texture to another texture. 
-		 *			Texture format and size of the subresource must match.
-		 *
-		 *			You are allowed to copy from a multisampled to non-multisampled
-		 *			surface, which will resolve the multisampled surface before copying.
-		 *
-		 * @param	srcSubresourceIdx	Index of the subresource to copy from.
-		 * @param	destSubresourceIdx	Index of the subresource to copy to.
-		 * @param	target				Texture that contains the destination subresource.
-		 */
-		void copy(UINT32 srcSubresourceIdx, UINT32 destSubresourceIdx, const SPtr<TextureCore>& target);
-
-		/**
-		 * @brief	Reads data from the texture buffer into the provided buffer.
-		 * 		  
-		 * @param	dest	Previously allocated buffer to read data into.
-		 * @param	mipLevel	(optional) Mipmap level to read from.
-		 * @param	face		(optional) Texture face to read from.
-		 */
-		virtual void readData(PixelData& dest, UINT32 mipLevel = 0, UINT32 face = 0) = 0;
-
-		/**
-		 * @brief	Writes data from the provided buffer into the texture buffer.
-		 * 		  
-		 * @param	dest		Buffer to retrieve the data from.
-		 * @param	mipLevel	(optional) Mipmap level to write into.
-		 * @param	face		(optional) Texture face to write into.
-		 * @param	discardWholeBuffer (optional) If true any existing texture data will be discard. This can
-		 *							    improve performance of the write operation.
-		 */
-		virtual void writeData(const PixelData& src, UINT32 mipLevel = 0, UINT32 face = 0, bool discardWholeBuffer = false) = 0;
-
-		/**
-		 * @brief	Returns true if the texture can be bound to a shader.
-		 *
-		 * @note	This is only false for some rare special cases. (e.g. AA render texture in DX9)
-		 *			Internal method.
-		 */
-		virtual bool isBindableAsShaderResource() const { return true; }
-
-		/**
-		 * @brief	Returns properties that contain information about the texture.
-		 */
-		const TextureProperties& getProperties() const { return mProperties; }
-
-		/************************************************************************/
-		/* 								TEXTURE VIEW                      		*/
-		/************************************************************************/
-
-		/**
-		 * @brief	Requests a texture view for the specified mip and array ranges. Returns an existing view of one for
-		 *			the specified ranges already exists, otherwise creates a new one. You must release all views
-		 *			by calling "releaseView" when done.
-		 *
-		 * @note	Core thread only.
-		 */
-		static TextureViewPtr requestView(const SPtr<TextureCore>& texture, UINT32 mostDetailMip, UINT32 numMips,
-			UINT32 firstArraySlice, UINT32 numArraySlices, GpuViewUsage usage);
-
-		/**
-		 * @brief	Releases the view. View won't actually get destroyed until all references to it are released.
-		 *
-		 * @note	Core thread only.
-		 */
-		static void releaseView(const TextureViewPtr& view);
-
-	protected:
-		/**
-		 * @copydoc	lock
-		 */
-		virtual PixelData lockImpl(GpuLockOptions options, UINT32 mipLevel = 0, UINT32 face = 0) = 0;
-
-		/**
-		 * @copydoc	unlock
-		 */
-		virtual void unlockImpl() = 0;
-
-		/**
-		 * @copydoc	copy
-		 */
-		virtual void copyImpl(UINT32 srcFace, UINT32 srcMipLevel, UINT32 destFace, UINT32 destMipLevel, const SPtr<TextureCore>& target) = 0;
-
-		/************************************************************************/
-		/* 								TEXTURE VIEW                      		*/
-		/************************************************************************/
-
-		/**
-		 * @brief	Creates a new empty/undefined texture view.
-		 */
-		virtual TextureViewPtr createView(const SPtr<TextureCore>& texture, const TEXTURE_VIEW_DESC& desc);
-
-		/**
-		 * @brief	Releases all internal texture view references. Views won't get destroyed if there are external references still held.
-		 */
-		void clearBufferViews();
-
-		/**
-		 * @brief	Holds a single texture view with a usage reference count.
-		 */
-		struct TextureViewReference
-		{
-			TextureViewReference(TextureViewPtr _view)
-				:view(_view), refCount(0)
-			{ }
-
-			TextureViewPtr view;
-			UINT32 refCount;
-		};
-
-		UnorderedMap<TEXTURE_VIEW_DESC, TextureViewReference*, TextureView::HashFunction, TextureView::EqualFunction> mTextureViews;
-		TextureProperties mProperties;
-		PixelDataPtr mInitData;
-	};
-
-	/**
-	 * @brief	Abstract class representing a texture. Specific render systems have their
-	 *			own Texture implementations. Internally represented as one or more surfaces
-	 *			with pixels in a certain number of dimensions, backed by a hardware buffer.
-	 *
-	 * @note	Sim thread.
-	 */
-    class BS_CORE_EXPORT Texture : public Resource
-    {
-    public:
-		/**
-		 * @brief	Updates the texture with new data. The actual write will be queued for later execution on the core thread.
-		 *			Provided data buffer will be locked until the operation completes.
-		 *
-		 * @param	accessor			Accessor to queue the operation on.
-		 * 
-		 * @return	Async operation object you can use to track operation completion.
-		 *
-		 * @see		TextureCore::writeSubresource
-		 */
-		AsyncOp writeSubresource(CoreAccessor& accessor, UINT32 subresourceIdx, const PixelDataPtr& data, bool discardEntireBuffer);
-
-		/**
-		 * @brief	Reads internal texture data to the provided previously allocated buffer. The read is queued for execution
-		 *			on the core thread and not executed immediately. Provided data buffer will be locked until the
-		 *			operation completes.
-		 *
-		 * @param	accessor			Accessor to queue the operation on.
-		 *
-		 * @return	Async operation object you can use to track operation completion.
-		 *
-		 * @see		TextureCore::readSubresource
-		 */
-		AsyncOp readSubresource(CoreAccessor& accessor, UINT32 subresourceIdx, const PixelDataPtr& data);
-
-		/**
-		 * @brief	Reads data from the cached system memory texture buffer into the provided buffer. 
-		 * 		  
-		 * @param	dest		Previously allocated buffer to read data into.
-		 * @param	mipLevel	(optional) Mipmap level to read from.
-		 * @param	face		(optional) Texture face to read from.
-		 *
-		 * @note	The data read is the cached texture data. Any data written to the texture from the GPU 
-		 *			or core thread will not be reflected in this data. Use "readSubresource" if you require
-		 *			those changes.
-		 *
-		 *			The texture must have been created with TU_CPUCACHED usage otherwise this method
-		 *			will not return any data.
-		 */
-		void readData(PixelData& dest, UINT32 mipLevel = 0, UINT32 face = 0);
-
-		/**
-		 * @brief	Returns properties that contain information about the texture.
-		 */
-		const TextureProperties& getProperties() const { return mProperties; }
-
-		/**
-		 * @brief	Retrieves a core implementation of a texture usable only from the
-		 *			core thread.
-		 */
-		SPtr<TextureCore> getCore() const;
-
-		/************************************************************************/
-		/* 								STATICS		                     		*/
-		/************************************************************************/
-
-		/**
-		 * @brief	Creates a new empty texture.
-		 *
-		 * @param	texType				Type of the texture.
-		 * @param	width				Width of the texture in pixels.
-		 * @param	height				Height of the texture in pixels.
-		 * @param	depth				Depth of the texture in pixels (Must be 1 for 2D textures).
-		 * @param	numMips				Number of mip-maps the texture has. This number excludes the full resolution map.
-		 * @param	format				Format of the pixels.
-		 * @param	usage				Describes how we plan on using the texture in the pipeline.
-		 * @param	hwGammaCorrection	If true the texture data is assumed to have been gamma corrected and will be
-		 *								converted back to linear space when sampled on GPU.
-		 * @param	multisampleCount	If higher than 1, texture containing multiple samples per pixel is created.
-		 */
-		static HTexture create(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
-			int numMips, PixelFormat format, int usage = TU_DEFAULT,
-			bool hwGammaCorrection = false, UINT32 multisampleCount = 0);
-
-
-		/**
-		 * @brief	Creates a new empty texture.
-		 *
-		 * @param	texType				Type of the texture.
-		 * @param	width				Width of the texture in pixels.
-		 * @param	height				Height of the texture in pixels.
-		 * @param	numMips				Number of mip-maps the texture has. This number excludes the full resolution map.
-		 * @param	format				Format of the pixels.
-		 * @param	usage				Describes planned texture use.
-		 * @param	hwGammaCorrection	If true the texture data is assumed to have been gamma corrected and will be
-		 *								converted back to linear space when sampled on GPU.
-		 * @param	multisampleCount	If higher than 1, texture containing multiple samples per pixel is created.
-		 */
-		static HTexture create(TextureType texType, UINT32 width, UINT32 height, int numMips,
-			PixelFormat format, int usage = TU_DEFAULT,
-			bool hwGammaCorrection = false, UINT32 multisampleCount = 0);
-
-		/**
-		 * @brief	Creates a new 2D or 3D texture initialized using the provided pixel data. Texture will not have any mipmaps.
-		 *
-		 * @param	pixelData			Data to initialize the texture width.
-		 * @param	usage				Describes planned texture use.
-		 * @param	hwGammaCorrection	If true the texture data is assumed to have been gamma corrected and will be
-		 *								converted back to linear space when sampled on GPU.
-		 */
-		static HTexture create(const PixelDataPtr& pixelData, int usage = TU_DEFAULT, bool hwGammaCorrection = false);
-
-		/**
-		 * @copydoc	create(TextureType, UINT32, UINT32, UINT32, int, PixelFormat, int, bool, UINT32)
-		 *
-		 * @note	Internal method. Creates a texture pointer without a handle. Use "create" for normal usage.
-		 */
-		static TexturePtr _createPtr(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
-			int num_mips, PixelFormat format, int usage = TU_DEFAULT,
-			bool hwGammaCorrection = false, UINT32 multisampleCount = 0);
-
-		/**
-		 * @copydoc	create(TextureType, UINT32, UINT32, int, PixelFormat, int, bool, UINT32)
-		 *
-		 * @note	Internal method. Creates a texture pointer without a handle. Use "create" for normal usage.
-		 */
-		static TexturePtr _createPtr(TextureType texType, UINT32 width, UINT32 height, int num_mips,
-			PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false, UINT32 multisampleCount = 0);
-
-    protected:
-		friend class TextureManager;
-
-		Texture(TextureType textureType, UINT32 width, UINT32 height, UINT32 depth, UINT32 numMipmaps,
-			PixelFormat format, int usage, bool hwGamma, UINT32 multisampleCount);
-
-		Texture(const PixelDataPtr& pixelData, int usage, bool hwGamma);
-
-		/**
-		 * @copydoc	Resource::initialize
-		 */
-		void initialize() override;
-
-		/**
-		 * @copydoc	CoreObject::createCore
-		 */
-		SPtr<CoreObjectCore> createCore() const override;
-
-		/**
-		 * @copydoc	Resource::calculateSize
-		 */
-		UINT32 calculateSize() const;
-
-		/**
-		 * @brief	Creates buffers used for caching of CPU texture data.
-		 *
-		 * @note	Make sure to initialize all texture properties before calling this.
-		 */
-		void createCPUBuffers();
-
-		/**
-		 * @brief	Updates the cached CPU buffers with new data.
-		 */
-		void updateCPUBuffers(UINT32 subresourceIdx, const PixelData& data);
-
-	protected:
-		Vector<PixelDataPtr> mCPUSubresourceData;
-		TextureProperties mProperties;
-		mutable PixelDataPtr mInitData;
-
-		/************************************************************************/
-		/* 								SERIALIZATION                      		*/
-		/************************************************************************/
-	public:
-		Texture(); // Serialization only
-
-		friend class TextureRTTI;
-		static RTTITypeBase* getRTTIStatic();
-		virtual RTTITypeBase* getRTTI() const override;
-    };
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsResource.h"
+#include "BsHardwareBuffer.h"
+#include "BsPixelUtil.h"
+#include "BsTextureView.h"
+
+namespace BansheeEngine 
+{
+	/** @addtogroup Resources
+	 *  @{
+	 */
+
+	/**	Flags that describe how is a texture used. */
+    enum TextureUsage
+    {
+		TU_STATIC = GBU_STATIC, /**< A regular texture that is not often or ever updated from the CPU. */
+		TU_DYNAMIC = GBU_DYNAMIC, /**< A regular texture that is often updated by the CPU. */
+		TU_RENDERTARGET = 0x200, /**< Texture that can be rendered to by the GPU. */
+		TU_DEPTHSTENCIL = 0x400, /**< Texture used as a depth/stencil buffer by the GPU. */
+		TU_LOADSTORE = 0x800, /**< Texture that allows load/store operations from the GPU program. */
+		TU_CPUCACHED = 0x1000, /**< Ensures all texture data will also be cached in system memory. */
+		TU_DEFAULT = TU_STATIC
+    };
+
+	/**	Available texture types. */
+    enum TextureType
+    {
+		TEX_TYPE_1D = 1, /**< One dimensional texture. Just a row of pixels. */
+		TEX_TYPE_2D = 2, /**< Two dimensional texture. */
+		TEX_TYPE_3D = 3, /**< Three dimensional texture. */
+		TEX_TYPE_CUBE_MAP = 4 /**< Texture consisting out of six 2D textures describing an inside of a cube. Allows special sampling. */
+    };
+
+	/**	Texture mipmap options. */
+	enum TextureMipmap
+	{
+		MIP_UNLIMITED = 0x7FFFFFFF /**< Create all mip maps down to 1x1. */
+	};
+
+	/** Properties of a Texture. Shared between sim and core thread versions of a Texture. */
+	class BS_CORE_EXPORT TextureProperties
+	{
+	public:
+		TextureProperties();
+		TextureProperties(TextureType textureType, UINT32 width, UINT32 height, UINT32 depth, UINT32 numMipmaps,
+			PixelFormat format, int usage, bool hwGamma, UINT32 multisampleCount);
+
+		/**	Gets the type of texture. */
+        TextureType getTextureType() const { return mTextureType; }
+
+        /**
+		 * Gets the number of mipmaps to be used for this texture. This number excludes the top level map (which is always
+		 * assumed to be present).
+         */
+        UINT32 getNumMipmaps() const {return mNumMipmaps;}
+
+		/** Gets whether this texture will be set up so that on sampling it, hardware gamma correction is applied. */
+		bool isHardwareGammaEnabled() const { return mHwGamma; }
+
+		/**	Gets the number of samples used for multisampling (0 if multisampling is not used). */
+		UINT32 getMultisampleCount() const { return mMultisampleCount; }
+
+        /**	Returns the height of the texture.  */
+        UINT32 getHeight() const { return mHeight; }
+
+        /**	Returns the width of the texture. */
+        UINT32 getWidth() const { return mWidth; }
+
+        /**	Returns the depth of the texture (only applicable for 3D textures). */
+        UINT32 getDepth() const { return mDepth; }
+
+        /**	Returns texture usage (TextureUsage) of this texture. */
+        int getUsage() const { return mUsage; }
+
+		/**	Returns the pixel format for the texture surface. */
+		PixelFormat getFormat() const { return mFormat; }
+
+        /**	Returns true if the texture has an alpha layer. */
+        bool hasAlpha() const;
+
+        /**	Return the number of faces this texture has. */
+        UINT32 getNumFaces() const;
+
+		/**
+		 * Maps a sub-resource index to an exact face and mip level. Sub-resource indexes are used when reading or writing
+		 * to the resource.
+		 * 			
+		 * @note	
+		 * Sub-resource index is only valid for the instance it was created on. You cannot use a sub-resource index from a
+		 * different texture and expect to get valid result. Modifying the resource so the number of sub-resources changes
+		 * invalidates all sub-resource indexes.
+		 */
+		void mapFromSubresourceIdx(UINT32 subresourceIdx, UINT32& face, UINT32& mip) const;
+
+		/**
+		 * Map a face and a mip level to a sub-resource index you can use for updating or reading a specific sub-resource.
+		 * 			
+		 * @note	
+		 * Generated sub-resource index is only valid for the instance it was created on. Modifying the resource so the 
+		 * number of sub-resources changes, invalidates all sub-resource indexes.
+		 */
+		UINT32 mapToSubresourceIdx(UINT32 face, UINT32 mip) const;
+
+		/**
+		 * Allocates a buffer you may use for storage when reading or writing a sub-resource. You need to allocate such a 
+		 * buffer if you are calling readSubresource().
+		 *
+		 * You can retrieve a sub-resource index by calling mapToSubresourceIdx().
+		 * 			
+		 * @note	Thread safe.
+		 */
+		PixelDataPtr allocateSubresourceBuffer(UINT32 subresourceIdx) const;
+
+	protected:
+		friend class TextureRTTI;
+
+		UINT32 mHeight;
+		UINT32 mWidth;
+		UINT32 mDepth;
+
+		UINT32 mNumMipmaps;
+		bool mHwGamma;
+		UINT32 mMultisampleCount;
+
+		TextureType mTextureType;
+		PixelFormat mFormat;
+		int mUsage;
+	};
+
+	/** @cond INTERNAL */
+
+	/**
+	 * Core thread version of a Texture.
+	 *
+	 * @note	Core thread.
+	 */
+	class BS_CORE_EXPORT TextureCore : public CoreObjectCore
+	{
+	public:
+		TextureCore(TextureType textureType, UINT32 width, UINT32 height, UINT32 depth, UINT32 numMipmaps,
+			PixelFormat format, int usage, bool hwGamma, UINT32 multisampleCount, const PixelDataPtr& initData);
+		virtual ~TextureCore() {}
+
+
+		/** @copydoc CoreObjectCore::initialize */
+		virtual void initialize() override;
+
+		/**
+		 * Updates a part of the texture with the provided data.
+		 *
+		 * @param[in]	subresourceIdx		Index of the subresource to update, if the texture has more than one.
+		 * @param[in]	data				Data to update the texture with.
+		 * @param[in]	discardEntireBuffer When true the existing contents of the resource you are updating will be 
+		 *									discarded. This can make the operation faster. Resources with certain buffer 
+		 *									types might require this flag to be in a specific state otherwise the operation 
+		 *									will fail.
+		 */
+		virtual void writeSubresource(UINT32 subresourceIdx, const PixelData& data, bool discardEntireBuffer);
+
+		/**
+		 * Reads a part of the current resource into the provided @p data parameter.
+		 * 			Data buffer needs to be pre-allocated.
+		 *
+		 * @param[in]	subresourceIdx		Index of the subresource to update, if the texture has more than one.
+		 * @param[out]	data				Buffer that will receive the data. Should be allocated with 
+		 *									allocateSubresourceBuffer() to ensure it is of valid type and size.
+		 */
+		virtual void readSubresource(UINT32 subresourceIdx, PixelData& data);
+
+		/**
+		 * Locks the buffer for reading or writing.
+		 *
+		 * @param[in]	options 	Options for controlling what you may do with the locked data.
+		 * @param[in]	mipLevel	(optional) Mipmap level to lock.
+		 * @param[in]	face		(optional) Texture face to lock.					
+		 * @return					Pointer to the buffer data. Only valid until you call unlock().
+		 * 			
+		 * @note	
+		 * If you are just reading or writing one block of data use readData()/writeData() methods as they can be much faster
+		 * in certain situations.
+		 */
+		PixelData lock(GpuLockOptions options, UINT32 mipLevel = 0, UINT32 face = 0);
+
+		/** 
+		 * Unlocks a previously locked buffer. After the buffer is unlocked, any data returned by lock becomes invalid. 
+		 *
+		 * @see	lock()
+		 */
+		void unlock();
+
+		/**
+		 * Copies the contents a subresource in this texture to another texture. Texture format and size of the subresource
+		 * must match.
+		 *
+		 * You are allowed to copy from a multisampled to non-multisampled surface, which will resolve the multisampled
+		 * surface before copying.
+		 *
+		 * @param[in]	srcSubresourceIdx	Index of the subresource to copy from.
+		 * @param[in]	destSubresourceIdx	Index of the subresource to copy to.
+		 * @param[in]	target				Texture that contains the destination subresource.
+		 */
+		void copy(UINT32 srcSubresourceIdx, UINT32 destSubresourceIdx, const SPtr<TextureCore>& target);
+
+		/**
+		 * Reads data from the texture buffer into the provided buffer.
+		 * 		  
+		 * @param[out]	dest		Previously allocated buffer to read data into.
+		 * @param[in]	mipLevel	(optional) Mipmap level to read from.
+		 * @param[in]	face		(optional) Texture face to read from.
+		 */
+		virtual void readData(PixelData& dest, UINT32 mipLevel = 0, UINT32 face = 0) = 0;
+
+		/**
+		 * Writes data from the provided buffer into the texture buffer.
+		 * 		  
+		 * @param[in]	dest				Buffer to retrieve the data from.
+		 * @param[in]	mipLevel			(optional) Mipmap level to write into.
+		 * @param[in]	face				(optional) Texture face to write into.
+		 * @param[in]	discardWholeBuffer	(optional) If true any existing texture data will be discard. This can improve 
+		 *									performance of the write operation.
+		 */
+		virtual void writeData(const PixelData& src, UINT32 mipLevel = 0, UINT32 face = 0, bool discardWholeBuffer = false) = 0;
+
+		/**
+		 * Returns true if the texture can be bound to a shader.
+		 *
+		 * @note	This is only false for some rare special cases (e.g. AA render texture in DX9). Internal method.
+		 */
+		virtual bool isBindableAsShaderResource() const { return true; }
+
+		/**	Returns properties that contain information about the texture. */
+		const TextureProperties& getProperties() const { return mProperties; }
+
+		/************************************************************************/
+		/* 								TEXTURE VIEW                      		*/
+		/************************************************************************/
+
+		/**
+		 * Requests a texture view for the specified mip and array ranges. Returns an existing view of one for the specified
+		 * ranges already exists, otherwise creates a new one. You must release all views by calling releaseView() when done.
+		 *
+		 * @note	Core thread only.
+		 */
+		static TextureViewPtr requestView(const SPtr<TextureCore>& texture, UINT32 mostDetailMip, UINT32 numMips,
+			UINT32 firstArraySlice, UINT32 numArraySlices, GpuViewUsage usage);
+
+		/**
+		 * Releases the view. View won't actually get destroyed until all references to it are released.
+		 *
+		 * @note	Core thread only.
+		 */
+		static void releaseView(const TextureViewPtr& view);
+
+	protected:
+		/** @copydoc lock */
+		virtual PixelData lockImpl(GpuLockOptions options, UINT32 mipLevel = 0, UINT32 face = 0) = 0;
+
+		/** @copydoc unlock */
+		virtual void unlockImpl() = 0;
+
+		/** @copydoc copy */
+		virtual void copyImpl(UINT32 srcFace, UINT32 srcMipLevel, UINT32 destFace, UINT32 destMipLevel, 
+			const SPtr<TextureCore>& target) = 0;
+
+		/************************************************************************/
+		/* 								TEXTURE VIEW                      		*/
+		/************************************************************************/
+
+		/**	Creates a new empty/undefined texture view. */
+		virtual TextureViewPtr createView(const SPtr<TextureCore>& texture, const TEXTURE_VIEW_DESC& desc);
+
+		/**
+		 * Releases all internal texture view references. Views won't get destroyed if there are external references still 
+		 * held.
+		 */
+		void clearBufferViews();
+
+		/** Holds a single texture view with a usage reference count. */
+		struct TextureViewReference
+		{
+			TextureViewReference(TextureViewPtr _view)
+				:view(_view), refCount(0)
+			{ }
+
+			TextureViewPtr view;
+			UINT32 refCount;
+		};
+
+		UnorderedMap<TEXTURE_VIEW_DESC, TextureViewReference*, TextureView::HashFunction, TextureView::EqualFunction> mTextureViews;
+		TextureProperties mProperties;
+		PixelDataPtr mInitData;
+	};
+
+	/** @endcond */
+
+	/**
+	 * Abstract class representing a texture. Specific render systems have their own Texture implementations. Internally
+	 * represented as one or more surfaces with pixels in a certain number of dimensions, backed by a hardware buffer.
+	 *
+	 * @note	Sim thread.
+	 */
+    class BS_CORE_EXPORT Texture : public Resource
+    {
+    public:
+		/**
+		 * Updates the texture with new data. The actual write will be queued for later execution on the core thread. 
+		 * Provided data buffer will be locked until the operation completes.
+		 *
+		 * @param[in]	accessor	Accessor to queue the operation on.
+		 * @return					Async operation object you can use to track operation completion.
+		 *
+		 * @see		TextureCore::writeSubresource
+		 */
+		AsyncOp writeSubresource(CoreAccessor& accessor, UINT32 subresourceIdx, const PixelDataPtr& data, 
+			bool discardEntireBuffer);
+
+		/**
+		 * Reads internal texture data to the provided previously allocated buffer. The read is queued for execution on the
+		 * core thread and not executed immediately. Provided data buffer will be locked until the operation completes.
+		 *
+		 * @param[in]	accessor	Accessor to queue the operation on.
+		 * @return					Async operation object you can use to track operation completion.
+		 *
+		 * @see		TextureCore::readSubresource
+		 */
+		AsyncOp readSubresource(CoreAccessor& accessor, UINT32 subresourceIdx, const PixelDataPtr& data);
+
+		/**
+		 * Reads data from the cached system memory texture buffer into the provided buffer. 
+		 * 		  
+		 * @param[out]	dest		Previously allocated buffer to read data into.
+		 * @param[in]	mipLevel	(optional) Mipmap level to read from.
+		 * @param[in]	face		(optional) Texture face to read from.
+		 *
+		 * @note	
+		 * The data read is the cached texture data. Any data written to the texture from the GPU or core thread will not 
+		 * be reflected in this data. Use readSubresource() if you require those changes.
+		 * @note
+		 * The texture must have been created with TU_CPUCACHED usage otherwise this method will not return any data.
+		 */
+		void readData(PixelData& dest, UINT32 mipLevel = 0, UINT32 face = 0);
+
+		/**	Returns properties that contain information about the texture. */
+		const TextureProperties& getProperties() const { return mProperties; }
+
+		/**	Retrieves a core implementation of a texture usable only from the core thread. */
+		SPtr<TextureCore> getCore() const;
+
+		/************************************************************************/
+		/* 								STATICS		                     		*/
+		/************************************************************************/
+
+		/**
+		 * Creates a new empty texture.
+		 *
+		 * @param[in]	texType				Type of the texture.
+		 * @param[in]	width				Width of the texture in pixels.
+		 * @param[in]	height				Height of the texture in pixels.
+		 * @param[in]	depth				Depth of the texture in pixels (Must be 1 for 2D textures).
+		 * @param[in]	numMips				Number of mip-maps the texture has. This number excludes the full resolution map.
+		 * @param[in]	format				Format of the pixels.
+		 * @param[in]	usage				Describes how we plan on using the texture in the pipeline.
+		 * @param[in]	hwGammaCorrection	If true the texture data is assumed to have been gamma corrected and will be
+		 *									converted back to linear space when sampled on GPU.
+		 * @param[in]	multisampleCount	If higher than 1, texture containing multiple samples per pixel is created.
+		 */
+		static HTexture create(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
+			int numMips, PixelFormat format, int usage = TU_DEFAULT,
+			bool hwGammaCorrection = false, UINT32 multisampleCount = 0);
+
+
+		/**
+		 * Creates a new empty texture.
+		 *
+		 * @param[in]	texType				Type of the texture.
+		 * @param[in]	width				Width of the texture in pixels.
+		 * @param[in]	height				Height of the texture in pixels.
+		 * @param[in]	numMips				Number of mip-maps the texture has. This number excludes the full resolution map.
+		 * @param[in]	format				Format of the pixels.
+		 * @param[in]	usage				Describes planned texture use.
+		 * @param[in]	hwGammaCorrection	If true the texture data is assumed to have been gamma corrected and will be
+		 *									converted back to linear space when sampled on GPU.
+		 * @param[in]	multisampleCount	If higher than 1, texture containing multiple samples per pixel is created.
+		 */
+		static HTexture create(TextureType texType, UINT32 width, UINT32 height, int numMips,
+			PixelFormat format, int usage = TU_DEFAULT,
+			bool hwGammaCorrection = false, UINT32 multisampleCount = 0);
+
+		/**
+		 * Creates a new 2D or 3D texture initialized using the provided pixel data. Texture will not have any mipmaps.
+		 *
+		 * @param[in]	pixelData			Data to initialize the texture width.
+		 * @param[in]	usage				Describes planned texture use.
+		 * @param[in]	hwGammaCorrection	If true the texture data is assumed to have been gamma corrected and will be
+		 *									converted back to linear space when sampled on GPU.
+		 */
+		static HTexture create(const PixelDataPtr& pixelData, int usage = TU_DEFAULT, bool hwGammaCorrection = false);
+
+		/**
+		 * @copydoc	create(TextureType, UINT32, UINT32, UINT32, int, PixelFormat, int, bool, UINT32)
+		 *
+		 * @note	Internal method. Creates a texture pointer without a handle. Use create() for normal usage.
+		 */
+		static TexturePtr _createPtr(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
+			int num_mips, PixelFormat format, int usage = TU_DEFAULT,
+			bool hwGammaCorrection = false, UINT32 multisampleCount = 0);
+
+		/**
+		 * @copydoc	create(TextureType, UINT32, UINT32, int, PixelFormat, int, bool, UINT32)
+		 *
+		 * @note	Internal method. Creates a texture pointer without a handle. Use create() for normal usage.
+		 */
+		static TexturePtr _createPtr(TextureType texType, UINT32 width, UINT32 height, int num_mips,
+			PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false, UINT32 multisampleCount = 0);
+
+    protected:
+		friend class TextureManager;
+
+		Texture(TextureType textureType, UINT32 width, UINT32 height, UINT32 depth, UINT32 numMipmaps,
+			PixelFormat format, int usage, bool hwGamma, UINT32 multisampleCount);
+
+		Texture(const PixelDataPtr& pixelData, int usage, bool hwGamma);
+
+		/** @copydoc Resource::initialize */
+		void initialize() override;
+
+		/** @copydoc CoreObject::createCore */
+		SPtr<CoreObjectCore> createCore() const override;
+
+		/** @copydoc Resource::calculateSize */
+		UINT32 calculateSize() const;
+
+		/**
+		 * Creates buffers used for caching of CPU texture data.
+		 *
+		 * @note	Make sure to initialize all texture properties before calling this.
+		 */
+		void createCPUBuffers();
+
+		/**	Updates the cached CPU buffers with new data. */
+		void updateCPUBuffers(UINT32 subresourceIdx, const PixelData& data);
+
+	protected:
+		Vector<PixelDataPtr> mCPUSubresourceData;
+		TextureProperties mProperties;
+		mutable PixelDataPtr mInitData;
+
+		/************************************************************************/
+		/* 								SERIALIZATION                      		*/
+		/************************************************************************/
+	public:
+		Texture(); // Serialization only
+
+		friend class TextureRTTI;
+		static RTTITypeBase* getRTTIStatic();
+		virtual RTTITypeBase* getRTTI() const override;
+    };
+
+	/** @} */
 }
 }

+ 146 - 158
BansheeCore/Include/BsTextureManager.h

@@ -1,159 +1,147 @@
-#pragma once
-
-#include "BsCorePrerequisites.h"
-
-#include "BsTexture.h"
-#include "BsRenderTexture.h"
-#include "BsMultiRenderTexture.h"
-#include "BsModule.h"
-
-namespace BansheeEngine 
-{
-    /**
-     * @brief	Defines interface for creation of textures. Render systems
-	 *			provide their own implementations.
-	 *
-	 * @note	Sim thread only.
-     */
-    class BS_CORE_EXPORT TextureManager : public Module<TextureManager>
-    {
-    public:
-		virtual ~TextureManager() { }
-
-		/**
-		 * @copydoc	Texture::create(TextureType, UINT32, UINT32, UINT32, int, PixelFormat, int, bool, UINT32)
-		 */
-        TexturePtr createTexture(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, 
-			int numMips, PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false, 
-			UINT32 multisampleCount = 0);
-			
-		/**
-		 * @copydoc	Texture::create(TextureType, UINT32, UINT32, int, PixelFormat, int, bool, UINT32)
-		 */
-		TexturePtr createTexture(TextureType texType, UINT32 width, UINT32 height, int numMips,
-			PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false, UINT32 multisampleCount = 0)
-		{
-			return createTexture(texType, width, height, 1, 
-				numMips, format, usage, hwGammaCorrection, multisampleCount);
-		}
-
-		/**
-		 * @copydoc	Texture::create(const PixelDataPtr&, int, bool)
-		 */
-		TexturePtr createTexture(const PixelDataPtr& pixelData, int usage = TU_DEFAULT, bool hwGammaCorrection = false);
-
-		/**
-		 * @brief	Creates a completely empty and uninitialized Texture.
-		 *
-		 * @note	Internal method. Should only be used for very specific purposes, like deserialization,
-		 * 			as it requires additional manual initialization that is not required normally.
-		 */
-		TexturePtr _createEmpty();
-
-		/**
-		 * @brief	Creates a new RenderTexture and automatically generates a color surface
-		 * 			and (optionally) a depth/stencil surface.
-		 *
-		 * @param	texType				Type of the texture.
-		 * @param	width				Width of the texture in pixels.
-		 * @param	height				Height of the texture in pixels.
-		 * @param	format				Format of the pixels.
-		 * @param	hwGamma				If true, any color data will be gamma corrected before being written
-		 *								into the texture.
-		 * @param	multisampleCount	If higher than 1, texture containing multiple samples per pixel is created.
-		 * @param	multisampleHint		Hint about what kind of multisampling to use. Render system specific.
-		 * @param	createDepth			Determines will a depth/stencil buffer of the same size as the color buffer be created
-		 *								for the render texture.
-		 * @param	depthStencilFormat	Format of the depth/stencil buffer if enabled.
-		 */
-		virtual RenderTexturePtr createRenderTexture(TextureType textureType, UINT32 width, UINT32 height, 
-			PixelFormat format = PF_R8G8B8A8, bool hwGamma = false, UINT32 multisampleCount = 0, 
-			bool createDepth = true, PixelFormat depthStencilFormat = PF_D24S8);
-
-		/**
-		 * @brief	Creates a RenderTexture using the description struct.
-		 */
-		virtual RenderTexturePtr createRenderTexture(const RENDER_TEXTURE_DESC& desc);
-
-		/**
-		 * @brief	Creates a new multi render texture. You may use this type of texture
-		 * 			to render to multiple output textures at once.
-		 */
-		virtual MultiRenderTexturePtr createMultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc);
-
-		/**
-		 * @brief	Gets the format which will be natively used for a requested format given the
-		 *			constraints of the current device.
-		 *
-		 * @note	Thread safe.
-		 */
-		virtual PixelFormat getNativeFormat(TextureType ttype, PixelFormat format, int usage, bool hwGamma) = 0;
-
-	protected:
-		/**
-		 * @brief	Creates an empty and uninitialized render texture of a specific type. This 
-		 *			is to be implemented by render systems with their own implementations.
-		 */
-		virtual RenderTexturePtr createRenderTextureImpl(const RENDER_TEXTURE_DESC& desc) = 0;
-
-		/**
-		 * @brief	Creates an empty and uninitialized multi render texture of a specific type. This is 
-		 *			to be implemented by render systems with their own implementations.
-		 */
-		virtual MultiRenderTexturePtr createMultiRenderTextureImpl(const MULTI_RENDER_TEXTURE_DESC& desc) = 0;
-
-		mutable HTexture mDummyTexture;
-    };
-
-/**
-     * @brief	Defines interface for creation of textures. Render systems
-	 *			provide their own implementations.
-	 *
-	 * @note	Core thread only.
-     */
-    class BS_CORE_EXPORT TextureCoreManager : public Module<TextureCoreManager>
-    {
-    public:
-		virtual ~TextureCoreManager() { }
-
-		/**
-		 * @copydoc	TextureManager::createTexture(TextureType, UINT32, UINT32, UINT32, int, PixelFormat, int, bool, UINT32)
-		 */
-		SPtr<TextureCore> createTexture(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
-			int numMips, PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false, 
-			UINT32 multisampleCount = 0);
-
-		/**
-		 * @copydoc	TextureManager::createRenderTexture(const RENDER_TEXTURE_DESC&)
-		 */
-		SPtr<RenderTextureCore> createRenderTexture(const RENDER_TEXTURE_CORE_DESC& desc);
-
-		/**
-		 * @copydoc	TextureManager::createMultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC&)
-		 */
-		SPtr<MultiRenderTextureCore> createMultiRenderTexture(const MULTI_RENDER_TEXTURE_CORE_DESC& desc);
-
-	protected:
-		friend class Texture;
-		friend class RenderTexture;
-		friend class MultiRenderTexture;
-
-		/**
-		 * @brief	Creates an empty and uninitialized texture of a specific type. This is to be implemented
-		 *			by render systems with their own implementations.
-		 */
-		virtual SPtr<TextureCore> createTextureInternal(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
-			int numMips, PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false,
-			UINT32 multisampleCount = 0, const PixelDataPtr& initialData = nullptr) = 0;
-
-		/**
-		 * @copydoc	TextureManager::createRenderTextureImpl
-		 */
-		virtual SPtr<RenderTextureCore> createRenderTextureInternal(const RENDER_TEXTURE_CORE_DESC& desc) = 0;
-
-		/**
-		 * @copydoc	TextureManager::createMultiRenderTextureImpl
-		 */
-		virtual SPtr<MultiRenderTextureCore> createMultiRenderTextureInternal(const MULTI_RENDER_TEXTURE_CORE_DESC& desc) = 0;
-    };
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsTexture.h"
+#include "BsRenderTexture.h"
+#include "BsMultiRenderTexture.h"
+#include "BsModule.h"
+
+namespace BansheeEngine 
+{
+	/** @cond INTERNAL */
+	/** @addtogroup Resources
+	 *  @{
+	 */
+
+    /**
+     * Defines interface for creation of textures. Render systems provide their own implementations.
+	 *
+	 * @note	Sim thread only.
+     */
+    class BS_CORE_EXPORT TextureManager : public Module<TextureManager>
+    {
+    public:
+		virtual ~TextureManager() { }
+
+		/** @copydoc Texture::create(TextureType, UINT32, UINT32, UINT32, int, PixelFormat, int, bool, UINT32) */
+        TexturePtr createTexture(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, 
+			int numMips, PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false, 
+			UINT32 multisampleCount = 0);
+			
+		/** @copydoc Texture::create(TextureType, UINT32, UINT32, int, PixelFormat, int, bool, UINT32) */
+		TexturePtr createTexture(TextureType texType, UINT32 width, UINT32 height, int numMips,
+			PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false, UINT32 multisampleCount = 0)
+		{
+			return createTexture(texType, width, height, 1, 
+				numMips, format, usage, hwGammaCorrection, multisampleCount);
+		}
+
+		/** @copydoc Texture::create(const PixelDataPtr&, int, bool) */
+		TexturePtr createTexture(const PixelDataPtr& pixelData, int usage = TU_DEFAULT, bool hwGammaCorrection = false);
+
+		/**
+		 * Creates a completely empty and uninitialized Texture.
+		 *
+		 * @note	
+		 * Internal method. Should only be used for very specific purposes, like deserialization, as it requires additional
+		 * manual initialization that is not required normally.
+		 */
+		TexturePtr _createEmpty();
+
+		/**
+		 * Creates a new RenderTexture and automatically generates a color surface and (optionally) a depth/stencil surface.
+		 *
+		 * @param[in]	texType				Type of the texture.
+		 * @param[in]	width				Width of the texture in pixels.
+		 * @param[in]	height				Height of the texture in pixels.
+		 * @param[in]	format				Format of the pixels.
+		 * @param[in]	hwGamma				If true, any color data will be gamma corrected before being written into the 
+		 *									texture.
+		 * @param[in]	multisampleCount	If higher than 1, texture containing multiple samples per pixel is created.
+		 * @param[in]	multisampleHint		Hint about what kind of multisampling to use. Render system specific.
+		 * @param[in]	createDepth			Determines will a depth/stencil buffer of the same size as the color buffer be
+		 *									created for the render texture.
+		 * @param[in]	depthStencilFormat	Format of the depth/stencil buffer if enabled.
+		 */
+		virtual RenderTexturePtr createRenderTexture(TextureType textureType, UINT32 width, UINT32 height, 
+			PixelFormat format = PF_R8G8B8A8, bool hwGamma = false, UINT32 multisampleCount = 0, 
+			bool createDepth = true, PixelFormat depthStencilFormat = PF_D24S8);
+
+		/** Creates a RenderTexture using the description struct. */
+		virtual RenderTexturePtr createRenderTexture(const RENDER_TEXTURE_DESC& desc);
+
+		/** 
+		 * Creates a new multi render texture. You may use this type of texture to render to multiple output textures at 
+		 * once.
+		 */
+		virtual MultiRenderTexturePtr createMultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc);
+
+		/**
+		 * Gets the format which will be natively used for a requested format given the constraints of the current device.
+		 *
+		 * @note	Thread safe.
+		 */
+		virtual PixelFormat getNativeFormat(TextureType ttype, PixelFormat format, int usage, bool hwGamma) = 0;
+
+	protected:
+		/**
+		 * Creates an empty and uninitialized render texture of a specific type. This is to be implemented by render 
+		 * systems with their own implementations.
+		 */
+		virtual RenderTexturePtr createRenderTextureImpl(const RENDER_TEXTURE_DESC& desc) = 0;
+
+		/**
+		 * Creates an empty and uninitialized multi render texture of a specific type. This is to be implemented by render
+		 * systems with their own implementations.
+		 */
+		virtual MultiRenderTexturePtr createMultiRenderTextureImpl(const MULTI_RENDER_TEXTURE_DESC& desc) = 0;
+
+		mutable HTexture mDummyTexture;
+    };
+
+	/**
+     * Defines interface for creation of textures. Render systems provide their own implementations.
+	 *
+	 * @note	Core thread only.
+     */
+    class BS_CORE_EXPORT TextureCoreManager : public Module<TextureCoreManager>
+    {
+    public:
+		virtual ~TextureCoreManager() { }
+
+		/**
+		 * @copydoc	TextureManager::createTexture(TextureType, UINT32, UINT32, UINT32, int, PixelFormat, int, bool, UINT32)
+		 */
+		SPtr<TextureCore> createTexture(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
+			int numMips, PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false, 
+			UINT32 multisampleCount = 0);
+
+		/** @copydoc	TextureManager::createRenderTexture(const RENDER_TEXTURE_DESC&) */
+		SPtr<RenderTextureCore> createRenderTexture(const RENDER_TEXTURE_CORE_DESC& desc);
+
+		/** @copydoc	TextureManager::createMultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC&) */
+		SPtr<MultiRenderTextureCore> createMultiRenderTexture(const MULTI_RENDER_TEXTURE_CORE_DESC& desc);
+
+	protected:
+		friend class Texture;
+		friend class RenderTexture;
+		friend class MultiRenderTexture;
+
+		/**
+		 * Creates an empty and uninitialized texture of a specific type. This is to be implemented	by render systems with
+		 * their own implementations.
+		 */
+		virtual SPtr<TextureCore> createTextureInternal(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
+			int numMips, PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false,
+			UINT32 multisampleCount = 0, const PixelDataPtr& initialData = nullptr) = 0;
+
+		/** @copydoc TextureManager::createRenderTextureImpl */
+		virtual SPtr<RenderTextureCore> createRenderTextureInternal(const RENDER_TEXTURE_CORE_DESC& desc) = 0;
+
+		/** @copydoc TextureManager::createMultiRenderTextureImpl */
+		virtual SPtr<MultiRenderTextureCore> createMultiRenderTextureInternal(const MULTI_RENDER_TEXTURE_CORE_DESC& desc) = 0;
+    };
+
+	/** @} */
+	/** @endcond */
 }
 }

+ 94 - 111
BansheeCore/Include/BsTransientMesh.h

@@ -1,112 +1,95 @@
-#pragma once
-
-#include "BsCorePrerequisites.h"
-#include "BsMeshBase.h"
-
-namespace BansheeEngine
-{
-	/**
-	 * @brief	Core thread portion of a transient mesh.
-	 *
-	 * @see		Transient mesh
-	 *
-	 * @note	Core thread.
-	 */
-	class BS_CORE_EXPORT TransientMeshCore : public MeshCoreBase
-	{
-	public:
-		TransientMeshCore(const SPtr<MeshHeapCore>& parentHeap, UINT32 id, UINT32 numVertices,
-			UINT32 numIndices, const Vector<SubMesh>& subMeshes);
-
-		/**
-		 * @copydoc MeshCoreBase::getVertexData
-		 */
-		SPtr<VertexData> getVertexData() const override;
-
-		 /**
-		  * @copydoc MeshCoreBase::getIndexData
-		  */
-		SPtr<IndexBufferCore> getIndexBuffer() const override;
-
-		/**
-		 * @copydoc MeshCoreBase::getVertexDesc
-		 */
-		SPtr<VertexDataDesc> getVertexDesc() const override;
-
-		/**
-		 * @brief	Returns the ID that uniquely identifies this mesh in the parent heap.
-		 */
-		UINT32 getMeshHeapId() const { return mId; }
-
-		/**
-		 * @copydoc MeshCoreBase::getVertexOffset
-		 */
-		virtual UINT32 getVertexOffset() const override;
-
-		 /**
-		 * @copydoc MeshCoreBase::getIndexOffset
-		 */
-		virtual UINT32 getIndexOffset() const override;
-
-		 /**
-		 * @copydoc MeshCoreBase::notifyUsedOnGPU
-		 */
-		virtual void _notifyUsedOnGPU() override;
-
-	protected:
-		friend class TransientMesh;
-
-		SPtr<MeshHeapCore> mParentHeap;
-		UINT32 mId;
-	};
-
-	/**
-	 * @brief	Represents a single mesh entry in the MeshHeap. This can be used as a normal mesh
-	 *			but due to the nature of the mesh-heap it is not the type of mesh you should use
-	 *			for storing static data.
-	 *
-	 *			Transient meshes don't keep internal index/vertex buffers but instead use the ones
-	 *			provided by their parent mesh heap.
-	 *
-	 * @see		MeshHeap
-	 *
-	 * @note	Sim thread.
-	 */
-	class BS_CORE_EXPORT TransientMesh : public MeshBase
-	{
-	public:
-		virtual ~TransientMesh();
-
-		/**
-		 * @brief	Retrieves a core implementation of a mesh usable only from the
-		 *			core thread.
-		 */
-		SPtr<TransientMeshCore> getCore() const;
-
-	protected:
-		friend class MeshHeap;
-
-		/**
-		 * @brief	Constructs a new transient mesh.
-		 *
-		 * @see		MeshHeap::alloc
-		 */
-		TransientMesh(const MeshHeapPtr& parentHeap, UINT32 id, UINT32 numVertices,
-			UINT32 numIndices, DrawOperationType drawOp = DOT_TRIANGLE_LIST);
-
-		/**
-		 * @brief	Marks the mesh as destroyed so we know that we don't need to destroy it ourselves.
-		 */
-		void markAsDestroyed() { mIsDestroyed = true; }
-
-		/**
-		 * @copydoc	RenderTarget::createCore
-		 */
-		SPtr<CoreObjectCore> createCore() const override;
-
-	protected:
-		bool mIsDestroyed;
-		MeshHeapPtr mParentHeap;
-		UINT32 mId;
-	};
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsMeshBase.h"
+
+namespace BansheeEngine
+{
+	/** @addtogroup Resources
+	 *  @{
+	 */
+
+	/** @cond INTERNAL */
+
+	/**
+	 * Core thread portion of a TransientMesh.
+	 *
+	 * @note	Core thread.
+	 */
+	class BS_CORE_EXPORT TransientMeshCore : public MeshCoreBase
+	{
+	public:
+		TransientMeshCore(const SPtr<MeshHeapCore>& parentHeap, UINT32 id, UINT32 numVertices,
+			UINT32 numIndices, const Vector<SubMesh>& subMeshes);
+
+		/** @copydoc MeshCoreBase::getVertexData */
+		SPtr<VertexData> getVertexData() const override;
+
+		 /** @copydoc MeshCoreBase::getIndexData */
+		SPtr<IndexBufferCore> getIndexBuffer() const override;
+
+		/** @copydoc MeshCoreBase::getVertexDesc */
+		SPtr<VertexDataDesc> getVertexDesc() const override;
+
+		/**	Returns the ID that uniquely identifies this mesh in the parent heap. */
+		UINT32 getMeshHeapId() const { return mId; }
+
+		/** @copydoc MeshCoreBase::getVertexOffset */
+		virtual UINT32 getVertexOffset() const override;
+
+		 /** @copydoc MeshCoreBase::getIndexOffset */
+		virtual UINT32 getIndexOffset() const override;
+
+		 /** @copydoc MeshCoreBase::notifyUsedOnGPU */
+		virtual void _notifyUsedOnGPU() override;
+
+	protected:
+		friend class TransientMesh;
+
+		SPtr<MeshHeapCore> mParentHeap;
+		UINT32 mId;
+	};
+
+	/** @endcond */
+
+	/**
+	 * Represents a single mesh entry in the MeshHeap. This can be used as a normal mesh but due to the nature of the 
+	 * mesh heap it is not the type of mesh you should use for storing static data.
+	 *
+	 * Transient meshes don't keep internal index/vertex buffers but instead use the ones provided by their parent mesh heap.
+	 *
+	 * @note	Sim thread.
+	 */
+	class BS_CORE_EXPORT TransientMesh : public MeshBase
+	{
+	public:
+		virtual ~TransientMesh();
+
+		/** Retrieves a core implementation of a mesh usable only from the core thread. */
+		SPtr<TransientMeshCore> getCore() const;
+
+	protected:
+		friend class MeshHeap;
+
+		/**
+		 * Constructs a new transient mesh.
+		 *
+		 * @see		MeshHeap::alloc
+		 */
+		TransientMesh(const MeshHeapPtr& parentHeap, UINT32 id, UINT32 numVertices,
+			UINT32 numIndices, DrawOperationType drawOp = DOT_TRIANGLE_LIST);
+
+		/** Marks the mesh as destroyed so we know that we don't need to destroy it ourselves. */
+		void markAsDestroyed() { mIsDestroyed = true; }
+
+		/** @copydoc RenderTarget::createCore */
+		SPtr<CoreObjectCore> createCore() const override;
+
+	protected:
+		bool mIsDestroyed;
+		MeshHeapPtr mParentHeap;
+		UINT32 mId;
+	};
+
+	/** @} */
 }
 }

+ 91 - 110
BansheeCore/Include/BsVertexDataDesc.h

@@ -1,111 +1,92 @@
-#pragma once
-
-#include "BsCorePrerequisites.h"
-#include "BsVertexDeclaration.h"
-
-namespace BansheeEngine
-{
-	/**
-	 * @brief	Contains information about layout of vertices in a buffer.
-	 *			This is very similar to VertexDeclaration but unlike VertexDeclaration it has no
-	 *			render API object to back it up and is very lightweight.
-	 */
-	class BS_CORE_EXPORT VertexDataDesc : public IReflectable
-	{
-	public:
-		VertexDataDesc() {}
-
-		/**
-		 * @brief	Informs the internal buffer that it needs to make room for the specified vertex element. If a vertex
-		 * 			with same stream and semantics already exists it will just be updated. 
-		 *
-		 * @param	type	   	Type of the vertex element. Determines size.
-		 * @param	semantic   	Semantic that allows the engine to connect the data to a shader input slot.
-		 * @param	semanticIdx	(optional) If there are multiple semantics with the same name, use different index to differentiate between them.
-		 * @param	streamIdx  	(optional) Zero-based index of the stream. Each stream will internally be represented as a single vertex buffer.
-		 */
-		void addVertElem(VertexElementType type, VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0);
-
-		/**
-		 * @brief	Query if we have vertex data for the specified semantic.
-		 */
-		bool hasElement(VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0) const;
-
-		/**
-		 * @brief	Returns the size in bytes of the vertex element with the specified semantic.
-		 */
-		UINT32 getElementSize(VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0) const;
-
-		/**
-		 * @brief	Returns offset of the vertex from start of the stream in bytes.
-		 */
-		UINT32 getElementOffsetFromStream(VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0) const;
-
-		/**
-		 * @brief	Gets vertex stride in bytes (offset from one vertex to another) in the specified stream.
-		 */
-		UINT32 getVertexStride(UINT32 streamIdx) const;
-
-		/**
-		 * @brief	Gets vertex stride in bytes (offset from one vertex to another) in all the streams.
-		 */
-		UINT32 getVertexStride() const;
-
-		/**
-		 * @brief	Gets offset in bytes from the start of the internal buffer to the start of the specified stream.
-		 */
-		UINT32 getStreamOffset(UINT32 streamIdx) const;
-
-		/**
-		 * @brief	Returns the number of vertex elements.
-		 */
-		UINT32 getNumElements() const { return (UINT32)mVertexElements.size(); }
-
-		/**
-		 * @brief	Returns the vertex element at the specified index.
-		 */
-		const VertexElement& getElement(UINT32 idx) const { return mVertexElements[idx]; }
-
-		/**
-		 * @brief	Creates a list of vertex elements from internal data.
-		 */
-		List<VertexElement> createElements() const;
-
-		/**
-		 * @brief	Creates a new empty vertex data descriptor.
-		 */
-		static VertexDataDescPtr create();
-
-	private:
-		friend class Mesh;
-		friend class MeshCore;
-		friend class MeshHeap;
-		friend class MeshHeapCore;
-
-		/**
-		 * @brief	Returns the largest stream index of all the stored vertex elements.
-		 */
-		UINT32 getMaxStreamIdx() const;
-
-		/**
-		 * @brief	Checks if any of the vertex elements use the specified stream index.
-		 */
-		bool hasStream(UINT32 streamIdx) const;
-
-		/**
-		 * @brief	Removes a vertex element of the specified type and semantics if it exists.
-		 */
-		void clearIfItExists(VertexElementType type, VertexElementSemantic semantic, UINT32 semanticIdx, UINT32 streamIdx);
-
-	private:
-		Vector<VertexElement> mVertexElements;
-
-		/************************************************************************/
-		/* 								SERIALIZATION                      		*/
-		/************************************************************************/
-	public:
-		friend class VertexDataDescRTTI;
-		static RTTITypeBase* getRTTIStatic();
-		virtual RTTITypeBase* getRTTI() const override;
-	};
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsVertexDeclaration.h"
+
+namespace BansheeEngine
+{
+	/** @addtogroup Resources
+	 *  @{
+	 */
+
+	/**
+	 * Contains information about layout of vertices in a buffer. This is very similar to VertexDeclaration but unlike
+	 * VertexDeclaration it has no render API object to back it up and is very lightweight.
+	 */
+	class BS_CORE_EXPORT VertexDataDesc : public IReflectable
+	{
+	public:
+		VertexDataDesc() {}
+
+		/**
+		 * Informs the internal buffer that it needs to make room for the specified vertex element. If a vertex with same 
+		 * stream and semantics already exists it will just be updated. 
+		 *
+		 * @param[in]	type	   	Type of the vertex element. Determines size.
+		 * @param[in]	semantic   	Semantic that allows the engine to connect the data to a shader input slot.
+		 * @param[in]	semanticIdx	(optional) If there are multiple semantics with the same name, use different index to
+		 *							differentiate between them.
+		 * @param[in]	streamIdx  	(optional) Zero-based index of the stream. Each stream will internally be represented 
+		 *							as a single vertex buffer.
+		 */
+		void addVertElem(VertexElementType type, VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0);
+
+		/**	Query if we have vertex data for the specified semantic. */
+		bool hasElement(VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0) const;
+
+		/**	Returns the size in bytes of the vertex element with the specified semantic. */
+		UINT32 getElementSize(VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0) const;
+
+		/**	Returns offset of the vertex from start of the stream in bytes. */
+		UINT32 getElementOffsetFromStream(VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0) const;
+
+		/**	Gets vertex stride in bytes (offset from one vertex to another) in the specified stream. */
+		UINT32 getVertexStride(UINT32 streamIdx) const;
+
+		/**	Gets vertex stride in bytes (offset from one vertex to another) in all the streams. */
+		UINT32 getVertexStride() const;
+
+		/**	Gets offset in bytes from the start of the internal buffer to the start of the specified stream. */
+		UINT32 getStreamOffset(UINT32 streamIdx) const;
+
+		/**	Returns the number of vertex elements. */
+		UINT32 getNumElements() const { return (UINT32)mVertexElements.size(); }
+
+		/**	Returns the vertex element at the specified index. */
+		const VertexElement& getElement(UINT32 idx) const { return mVertexElements[idx]; }
+
+		/**	Creates a list of vertex elements from internal data. */
+		List<VertexElement> createElements() const;
+
+		/**	Creates a new empty vertex data descriptor. */
+		static VertexDataDescPtr create();
+
+	private:
+		friend class Mesh;
+		friend class MeshCore;
+		friend class MeshHeap;
+		friend class MeshHeapCore;
+
+		/**	Returns the largest stream index of all the stored vertex elements. */
+		UINT32 getMaxStreamIdx() const;
+
+		/**	Checks if any of the vertex elements use the specified stream index. */
+		bool hasStream(UINT32 streamIdx) const;
+
+		/**	Removes a vertex element of the specified type and semantics if it exists. */
+		void clearIfItExists(VertexElementType type, VertexElementSemantic semantic, UINT32 semanticIdx, UINT32 streamIdx);
+
+	private:
+		Vector<VertexElement> mVertexElements;
+
+		/************************************************************************/
+		/* 								SERIALIZATION                      		*/
+		/************************************************************************/
+	public:
+		friend class VertexDataDescRTTI;
+		static RTTITypeBase* getRTTIStatic();
+		virtual RTTITypeBase* getRTTI() const override;
+	};
+
+	/** @} */
 }
 }

+ 1 - 3
MBansheeEditor/Inspectors/GUIWidgetInspector.cs

@@ -1,6 +1,4 @@
-using System.Collections;
-using System.Collections.Generic;
-using BansheeEngine;
+using BansheeEngine;
 
 
 namespace BansheeEditor
 namespace BansheeEditor
 {
 {