Browse Source

More documentation

Marko Pintera 11 years ago
parent
commit
bdd14c8080

+ 1 - 1
BansheeEditorExec/BsEditorExec.cpp

@@ -12,7 +12,7 @@ int CALLBACK WinMain(
 	_In_  int nCmdShow
 	_In_  int nCmdShow
 	)
 	)
 {
 {
-	EditorApplication::startUp(RenderSystemPlugin::DX11);
+	EditorApplication::startUp(RenderSystemPlugin::DX9);
 	EditorApplication::instance().runMainLoop();
 	EditorApplication::instance().runMainLoop();
 	EditorApplication::shutDown();
 	EditorApplication::shutDown();
 
 

+ 2 - 2
BansheeEngine/Source/BsSpriteTexture.cpp

@@ -38,7 +38,7 @@ namespace BansheeEngine
 		SpriteTexturePtr texturePtr = cm_core_ptr<SpriteTexture, PoolAlloc>
 		SpriteTexturePtr texturePtr = cm_core_ptr<SpriteTexture, PoolAlloc>
 			(new (cm_alloc<SpriteTexture, PoolAlloc>()) SpriteTexture(Vector2(0.0f, 0.0f), Vector2(1.0f, 1.0f), texture));
 			(new (cm_alloc<SpriteTexture, PoolAlloc>()) SpriteTexture(Vector2(0.0f, 0.0f), Vector2(1.0f, 1.0f), texture));
 
 
-		return static_resource_cast<SpriteTexture>(gResources().createResourceHandle(texturePtr));
+		return static_resource_cast<SpriteTexture>(gResources()._createResourceHandle(texturePtr));
 	}
 	}
 
 
 	HSpriteTexture SpriteTexture::create(const Vector2& uvOffset, const Vector2& uvScale, const HTexture& texture)
 	HSpriteTexture SpriteTexture::create(const Vector2& uvOffset, const Vector2& uvScale, const HTexture& texture)
@@ -46,7 +46,7 @@ namespace BansheeEngine
 		SpriteTexturePtr texturePtr = cm_core_ptr<SpriteTexture, PoolAlloc>
 		SpriteTexturePtr texturePtr = cm_core_ptr<SpriteTexture, PoolAlloc>
 			(new (cm_alloc<SpriteTexture, PoolAlloc>()) SpriteTexture(uvOffset, uvScale, texture));
 			(new (cm_alloc<SpriteTexture, PoolAlloc>()) SpriteTexture(uvOffset, uvScale, texture));
 
 
-		return static_resource_cast<SpriteTexture>(gResources().createResourceHandle(texturePtr));
+		return static_resource_cast<SpriteTexture>(gResources()._createResourceHandle(texturePtr));
 	}
 	}
 
 
 	SpriteTexturePtr SpriteTexture::createEmpty()
 	SpriteTexturePtr SpriteTexture::createEmpty()

+ 177 - 116
CamelotCore/Include/CmPixelData.h

@@ -7,56 +7,58 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	/** The pixel format used for images, textures, and render surfaces */
+	/**
+	 * @brief	The pixel format used for images, textures, and render surfaces
+	 */
     enum PixelFormat
     enum PixelFormat
     {
     {
-        /// Unknown pixel format.
+        // Unknown pixel format.
         PF_UNKNOWN = 0,
         PF_UNKNOWN = 0,
-        /// 8-bit pixel format, all bits red
+        // 8-bit pixel format, all bits red.
         PF_R8 = 1,
         PF_R8 = 1,
-		/// 2 byte pixel format, 1 byte red, 1 byte green
+		// 2 byte pixel format, 1 byte red, 1 byte green.
 		PF_R8G8 = 2,
 		PF_R8G8 = 2,
-        /// 24-bit pixel format, 8 bits for red, green and blue.
+        // 24-bit pixel format, 8 bits for red, green and blue.
         PF_R8G8B8 = 3,
         PF_R8G8B8 = 3,
-        /// 24-bit pixel format, 8 bits for blue, green and red.
+        // 24-bit pixel format, 8 bits for blue, green and red.
         PF_B8G8R8 = 4,
         PF_B8G8R8 = 4,
-        /// 32-bit pixel format, 8 bits for alpha, red, green and blue.
+        // 32-bit pixel format, 8 bits for alpha, red, green and blue.
         PF_A8R8G8B8 = 5,
         PF_A8R8G8B8 = 5,
-        /// 32-bit pixel format, 8 bits for blue, green, red and alpha.
+        // 32-bit pixel format, 8 bits for blue, green, red and alpha.
         PF_A8B8G8R8 = 6,
         PF_A8B8G8R8 = 6,
-        /// 32-bit pixel format, 8 bits for blue, green, red and alpha.
+        // 32-bit pixel format, 8 bits for blue, green, red and alpha.
         PF_B8G8R8A8 = 7,
         PF_B8G8R8A8 = 7,
-		/// 32-bit pixel format, 8 bits for red, green, blue and alpha.
+		// 32-bit pixel format, 8 bits for red, green, blue and alpha.
 		PF_R8G8B8A8 = 8,
 		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
+        // 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,
         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
+        // 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,
         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
+		// 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,
 		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
+		// 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,
 		PF_B8G8R8X8 = 12,
-		/// 3 byte pixel format, 1 byte for red, 1 byte for green, 1 byte for blue
+		// 24-bit pixel format, 8 bits for red, green and blue.
 		PF_BYTE_RGB = PF_R8G8B8,
 		PF_BYTE_RGB = PF_R8G8B8,
-		/// 3 byte pixel format, 1 byte for blue, 1 byte for green, 1 byte for red
+		// 24-bit pixel format, 8 bits for blue, green and red.
 		PF_BYTE_BGR = PF_B8G8R8,
 		PF_BYTE_BGR = PF_B8G8R8,
-		/// 4 byte pixel format, 1 byte for blue, 1 byte for green, 1 byte for red and one byte for alpha
+		// 32-bit pixel format, 8 bits for blue, green, red and alpha.
 		PF_BYTE_BGRA = PF_B8G8R8A8,
 		PF_BYTE_BGRA = PF_B8G8R8A8,
-		/// 4 byte pixel format, 1 byte for red, 1 byte for green, 1 byte for blue, and one byte for alpha
+		// 32-bit pixel format, 8 bits for red, green, blue and alpha.
 		PF_BYTE_RGBA = PF_R8G8B8A8,      
 		PF_BYTE_RGBA = PF_R8G8B8A8,      
-        /// DDS (DirectDraw Surface) DXT1 format
+        // DXT1/BC1 format containing opaque RGB or 1-bit alpha RGB. 4 bits per pixel.
         PF_DXT1 = 13,
         PF_DXT1 = 13,
-        /// DDS (DirectDraw Surface) DXT2 format
+        // DXT2/BC2 format with premultiplied alpha. 6 bits per pixel.
         PF_DXT2 = 14,
         PF_DXT2 = 14,
-        /// DDS (DirectDraw Surface) DXT3 format
+        // DXT3/BC2 format with explicit alpha. 6 bits per pixel.
         PF_DXT3 = 15,
         PF_DXT3 = 15,
-        /// DDS (DirectDraw Surface) DXT4 format
+        // DXT4/BC3 format with premultiplied alpha. 6 bits per pixel. Better alpha gradients than DXT2.
         PF_DXT4 = 16,
         PF_DXT4 = 16,
-        /// DDS (DirectDraw Surface) DXT5 format
+        // DXT5/BC3 format with explicit alpha. 6 bits per pixel. Better alpha gradients than DXT3.
         PF_DXT5 = 17,
         PF_DXT5 = 17,
 		// 16-bit pixel format, 16 bits (float) for red
 		// 16-bit pixel format, 16 bits (float) for red
         PF_FLOAT16_R = 18,
         PF_FLOAT16_R = 18,
@@ -74,22 +76,22 @@ namespace BansheeEngine
         PF_FLOAT32_RGB = 24,
         PF_FLOAT32_RGB = 24,
         // 128-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue, 32 bits (float) for alpha
         // 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 = 25,
         PF_FLOAT32_RGBA = 25,
-		// Depth stencil, 32bit depth, 8bit stencil + 24 unused
+		// Depth stencil format, 32bit depth, 8bit stencil + 24 unused
 		PF_D32_S8X24 = 26,
 		PF_D32_S8X24 = 26,
-		// Depth stencil, 24bit depth + 8bit stencil
+		// Depth stencil fomrat, 24bit depth + 8bit stencil
 		PF_D24S8 = 27,
 		PF_D24S8 = 27,
-		// Depth, 32bits
+		// Depth format, 32bits
 		PF_D32 = 28,
 		PF_D32 = 28,
-		// Depth, 16bits
+		// Depth format, 16bits
 		PF_D16 = 29,
 		PF_D16 = 29,
 		// Number of pixel formats currently defined
 		// Number of pixel formats currently defined
         PF_COUNT = 30
         PF_COUNT = 30
     };
     };
 	typedef Vector<PixelFormat> PixelFormatList;
 	typedef Vector<PixelFormat> PixelFormatList;
 
 
-    /**
-     * Flags defining some on/off properties of pixel formats
-     */
+	/**
+	 * @brief	Flags defining some properties of pixel formats.
+	 */
     enum PixelFormatFlags {
     enum PixelFormatFlags {
         // This format has an alpha channel
         // This format has an alpha channel
         PFF_HASALPHA        = 0x00000001,      
         PFF_HASALPHA        = 0x00000001,      
@@ -105,50 +107,53 @@ namespace BansheeEngine
         PFF_NATIVEENDIAN    = 0x00000010
         PFF_NATIVEENDIAN    = 0x00000010
     };
     };
     
     
-    /** Pixel component format */
+	/**
+	 * @brief	Types of pixel components
+	 */
     enum PixelComponentType
     enum PixelComponentType
     {
     {
-        PCT_BYTE = 0,    /// Byte per component (8 bit fixed 0.0..1.0)
-        PCT_SHORT = 1,   /// Short per component (16 bit fixed 0.0..1.0))
-        PCT_FLOAT16 = 2, /// 16 bit float per component
-        PCT_FLOAT32 = 3, /// 32 bit float per component
-        PCT_COUNT = 4    /// Number of pixel types
+        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_COUNT = 4    /**< Number of pixel types */
     };
     };
     
     
-	/** A primitive describing a volume (3D), image (2D) or line (1D) of pixels in memory.
-     	In case of a rectangle, depth must be 1. 
-     	Pixels are stored as a succession of "depth" slices, each containing "height" rows of 
-     	"width" pixels.
-    */
+	/**
+	 * @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 CM_EXPORT PixelData : public GpuResourceData
     class CM_EXPORT PixelData : public GpuResourceData
 	{
 	{
     public:
     public:
-    	/// Parameter constructor for setting the members manually
     	PixelData() {}
     	PixelData() {}
 		~PixelData() {}
 		~PixelData() {}
 
 
-		/** Constructor providing extents in the form of a Box object. This constructor
-    		assumes the pixel data is laid out consecutively in memory. (this
-    		means row after row, slice after slice, with no space in between)
-    		@param extents	    Extents of the region defined by data
-    		@param pixelFormat	Format of this buffer
-    		@param pixelData	Pointer to the actual data
-    	*/
+		/**
+		 * @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)
 		PixelData(const PixelVolume &extents, PixelFormat pixelFormat)
 			:mExtents(extents), mFormat(pixelFormat)
 			:mExtents(extents), mFormat(pixelFormat)
 		{
 		{
 			setConsecutive();
 			setConsecutive();
 		}
 		}
 
 
-    	/** Constructor providing width, height and depth. This constructor
-    		assumes the pixel data is laid out consecutively in memory. (this
-    		means row after row, slice after slice, with no space in between)
-    		@param width	    Width of the region
-    		@param height	    Height of the region
-    		@param depth	    Depth of the region
-    		@param pixelFormat	Format of this buffer
-    		@param pixelData    Pointer to the actual data
-    	*/
+		/**
+		 * @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)
     	PixelData(UINT32 width, UINT32 height, UINT32 depth, PixelFormat pixelFormat)
 			: mExtents(0, 0, 0, width, height, depth), mFormat(pixelFormat)
 			: mExtents(0, 0, 0, width, height, depth), mFormat(pixelFormat)
     	{
     	{
@@ -158,101 +163,157 @@ namespace BansheeEngine
 		PixelData(const PixelData& copy);
 		PixelData(const PixelData& copy);
 		PixelData& operator=(const PixelData& rhs);
 		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; }
 		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; }
 		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; }
 		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; }
         void setSlicePitch(UINT32 slicePitch) { mSlicePitch = slicePitch; }
 
 
-        /**	Get the number of elements between one past the rightmost pixel of 
-         	one row and the leftmost pixel of the next row. (IE this is zero if rows
-         	are consecutive).
-        */
+		/**
+		 * @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(); }
         UINT32 getRowSkip() const { return mRowPitch - getWidth(); }
-        /** Get the number of elements between one past the right bottom pixel of
-         	one slice and the left top pixel of the next slice. (IE this is zero if slices
-         	are consecutive).
-        */
+
+		/**
+		 * @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); }
         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; }
 		PixelFormat getFormat() const { return mFormat; }
 
 
+		/**
+		 * @brief	Returns width of the buffer in pixels.
+		 */
 		UINT32 getWidth() const { return mExtents.getWidth(); }
 		UINT32 getWidth() const { return mExtents.getWidth(); }
+
+		/**
+		 * @brief	Returns height of the buffer in pixels.
+		 */
 		UINT32 getHeight() const { return mExtents.getHeight(); }
 		UINT32 getHeight() const { return mExtents.getHeight(); }
+
+		/**
+		 * @brief	Returns depth of the buffer in pixels.
+		 */
 		UINT32 getDepth() const { return mExtents.getDepth(); }
 		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; }
 		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; }
 		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; }
 		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; }
 		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; }
 		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; }
 		UINT32 getBack() const { return mExtents.back; }
 
 
+		/**
+		 * @brief	Returns extents of the pixel volume this object is capable of holding.
+		 */
 		PixelVolume getExtents() const { return mExtents; }
 		PixelVolume getExtents() const { return mExtents; }
 
 
-        /** Return whether this buffer is laid out consecutive in memory (ie the pitches
-         	are equal to the dimensions)
-        */        
+		/**
+		 * @brief	Return whether this buffer is laid out consecutive in memory 
+		 *			(i.e. the pitches are equal to the dimensions).
+		 */
         bool isConsecutive() const 
         bool isConsecutive() const 
 		{ 
 		{ 
 			return mRowPitch == getWidth() && mSlicePitch == getWidth()*getHeight(); 
 			return mRowPitch == getWidth() && mSlicePitch == getWidth()*getHeight(); 
 		}
 		}
-        /** Return the size (in bytes) this image would take if it was
-        	laid out consecutive in memory
-      	*/
+
+		/**
+		 * @brief	Return the size (in bytes) this image would take if it was
+		 *			laid out consecutive in memory.
+		 */
       	UINT32 getConsecutiveSize() const;
       	UINT32 getConsecutiveSize() const;
-      	/** Return a subvolume of this PixelBox.
-      		@param def	Defines the bounds of the subregion to return
-      		@returns	A pixel box describing the region and the data in it
-      		@remarks	This function does not copy any data, it just returns
-      			a PixelBox object with a data pointer pointing somewhere inside 
-      			the data of object.
-      		@throws	Exception(ERR_INVALIDPARAMS) if def is not fully contained
-      	*/
+
+		/**
+		 * @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;
       	PixelData getSubVolume(const PixelVolume &def) const;
         
         
-        /**
-         * Get colour value from a certain location in the PixelBox. The z coordinate
-         * is only valid for cubemaps and volume textures. This uses the first (largest)
-         * mipmap.
-         */
+		/**
+		 * @brief	Returns pixel color at the specified coordinates.
+		 */
         Color getColorAt(UINT32 x, UINT32 y, UINT32 z = 0);
         Color getColorAt(UINT32 x, UINT32 y, UINT32 z = 0);
 
 
-        /**
-         * Set colour value at a certain location in the PixelBox. The z coordinate
-         * is only valid for cubemaps and volume textures. This uses the first (largest)
-         * mipmap.
-         */
+		/**
+		 * @brief	Sets the pixel color at the specified coordinates.
+		 */
         void setColorAt(Color const &cv, UINT32 x, UINT32 y, UINT32 z = 0);
         void setColorAt(Color const &cv, UINT32 x, UINT32 y, UINT32 z = 0);
 
 
 	private:
 	private:
-		PixelVolume mExtents;
+		/**
+		 * @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	Returns the needed size of the internal buffer, in bytes.
+		 */
+		UINT32 getInternalBufferSize();
 
 
-        /// The pixel format 
+	private:
+		PixelVolume mExtents;
         PixelFormat mFormat;
         PixelFormat mFormat;
-        /** Number of elements between the leftmost pixel of one row and the left
-         	pixel of the next. This value must always be equal to getWidth() (consecutive) 
-			for compressed formats.
-        */
         UINT32 mRowPitch;
         UINT32 mRowPitch;
-        /** Number of elements between the top left pixel of one (depth) slice and 
-         	the top left pixel of the next. This can be a negative value. Must be a multiple of
-         	rowPitch. This value must always be equal to getWidth()*getHeight() (consecutive) 
-			for compressed formats.
-        */
         UINT32 mSlicePitch;
         UINT32 mSlicePitch;
 
 
-		/** Set the rowPitch and slicePitch so that the buffer is laid out consecutive 
-         	in memory.
-        */        
-        void setConsecutive()
-        {
-            mRowPitch = getWidth();
-            mSlicePitch = getWidth()*getHeight();
-        }
-
-		UINT32 getInternalBufferSize();
-
 		/************************************************************************/
 		/************************************************************************/
 		/* 								SERIALIZATION                      		*/
 		/* 								SERIALIZATION                      		*/
 		/************************************************************************/
 		/************************************************************************/

+ 8 - 1
CamelotCore/Include/CmResource.h

@@ -7,7 +7,7 @@
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
 	/**
 	/**
-	 * @brief	Base class for all resources used in the engine.
+	 * @brief	Base class for all resources.
 	 */
 	 */
 	class CM_EXPORT Resource : public IReflectable, public CoreObject
 	class CM_EXPORT Resource : public IReflectable, public CoreObject
 	{
 	{
@@ -15,7 +15,14 @@ namespace BansheeEngine
 		Resource(bool requiresGpuInitialization = true);
 		Resource(bool requiresGpuInitialization = true);
 		virtual ~Resource() {};
 		virtual ~Resource() {};
 
 
+		/**
+		 * @brief	Returns the name of the resource.
+		 */
 		const String& getName() const { return mName; }
 		const String& getName() const { return mName; }
+
+		/**
+		 * @brief	Sets the name of the resource. 
+		 */
 		void setName(const String& name) { mName = name; }
 		void setName(const String& name) { mName = name; }
 
 
 	protected:
 	protected:

+ 80 - 11
CamelotCore/Include/CmResourceHandle.h

@@ -7,6 +7,9 @@ namespace BansheeEngine
 	template <typename T>
 	template <typename T>
 	class ResourceHandle;
 	class ResourceHandle;
 
 
+	/**
+	 * @brief	Data that is shared between all resource handles.
+	 */
 	struct CM_EXPORT ResourceHandleData
 	struct CM_EXPORT ResourceHandleData
 	{
 	{
 		ResourceHandleData()
 		ResourceHandleData()
@@ -18,18 +21,22 @@ namespace BansheeEngine
 		bool mIsCreated;	
 		bool mIsCreated;	
 	};
 	};
 
 
+	/**
+	 * @brief	Base class containing common functionality for resource handles.
+	 */
 	class CM_EXPORT ResourceHandleBase : public IReflectable
 	class CM_EXPORT ResourceHandleBase : public IReflectable
 	{
 	{
 	public:
 	public:
 		/**
 		/**
-		 * @brief	Checks if the resource is loaded
+		 * @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.
 		 */
 		 */
 		bool isLoaded() const;
 		bool isLoaded() const;
 
 
 		/**
 		/**
-		 * @brief	Blocks the current thread until the resource is fully loaded.
+		 * @brief	Blocks the current thread until the resource is fully loaded AND initialized.
 		 * 			
 		 * 			
-		 * @note	Careful not to call this on the thread that does the loading.
+		 * @note	Careful not to call this on the thread that does the loading or initializing.
 		 */
 		 */
 		void synchronize() const;
 		void synchronize() const;
 
 
@@ -48,7 +55,9 @@ namespace BansheeEngine
 		 * 			by the constructors, or if you constructed just using a UUID, then you need to
 		 * 			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.
 		 * 			call this manually before you can access the resource from this handle.
 		 * 			
 		 * 			
-		 * @note	Two set construction is sometimes required due to multithreaded nature of resource loading.
+		 * @note	This is needed because two part construction is required due to 
+		 *			multithreaded nature of resource loading.
+		 *			Internal method.
 		 */
 		 */
 		void _setHandleData(std::shared_ptr<Resource> ptr, const String& uuid);
 		void _setHandleData(std::shared_ptr<Resource> ptr, const String& uuid);
 
 
@@ -75,6 +84,14 @@ namespace BansheeEngine
 		virtual RTTITypeBase* getRTTI() const;
 		virtual RTTITypeBase* getRTTI() const;
 	};
 	};
 
 
+	/**
+	 * @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>
 	template <typename T>
 	class ResourceHandle : public ResourceHandleBase
 	class ResourceHandle : public ResourceHandleBase
 	{
 	{
@@ -83,8 +100,10 @@ namespace BansheeEngine
 			:ResourceHandleBase()
 			:ResourceHandleBase()
 		{ }
 		{ }
 
 
-		// Note: This constructor requires you to call "setHandleData" with the actual resource pointer,
-		// before the resource is considered as loaded
+		/**
+		 * @brief	Constructs an invalid handle with the specified UUID. You must call _setHandleData
+		 *			with the actual resource pointer to make the handle valid.
+		 */
 		ResourceHandle(const String& uuid)
 		ResourceHandle(const String& uuid)
 			:ResourceHandleBase()
 			:ResourceHandleBase()
 		{
 		{
@@ -92,6 +111,9 @@ namespace BansheeEngine
 			mData->mUUID = uuid;
 			mData->mUUID = uuid;
 		}
 		}
 
 
+		/**
+		 * @brief	Copy constructor.
+		 */
 		template <typename T1>
 		template <typename T1>
 		ResourceHandle(const ResourceHandle<T1>& ptr)
 		ResourceHandle(const ResourceHandle<T1>& ptr)
 			:ResourceHandleBase()
 			:ResourceHandleBase()
@@ -99,14 +121,32 @@ namespace BansheeEngine
 			mData = ptr.getHandleData();
 			mData = ptr.getHandleData();
 		}
 		}
 
 
+		/**
+		 * @brief	Converts a specific handle to generic Resource handle.
+		 */
 		operator ResourceHandle<Resource>() 
 		operator ResourceHandle<Resource>() 
 		{
 		{
 			return ResourceHandle<Resource>(*this); 
 			return ResourceHandle<Resource>(*this); 
 		}
 		}
 
 
+		/**
+		 * @brief	Returns internal resource pointer.
+		 *
+		 * @note	Throws exception if handle is invalid.
+		 */
 		T* operator->() const { return get(); }
 		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(); }
 		T& operator*() const { return *get(); }
 
 
+		/**
+		 * @brief	Clears the handle making it invalid and releases any references
+		 *			held to the resource.
+		 */
 		ResourceHandle<T>& operator=(std::nullptr_t ptr)
 		ResourceHandle<T>& operator=(std::nullptr_t ptr)
 		{ 	
 		{ 	
 			mData = nullptr;
 			mData = nullptr;
@@ -114,18 +154,27 @@ namespace BansheeEngine
 		}
 		}
 
 
 		template<class _Ty>
 		template<class _Ty>
-		struct CM_Bool_struct
+		struct Bool_struct
 		{
 		{
 			int _Member;
 			int _Member;
 		};
 		};
 
 
-		// Conversion to bool
-		// (Why not just directly convert to bool? Because then we can assign pointer to bool and that's weird)
-		operator int CM_Bool_struct<T>::*() const
+		/**
+		 * @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->mPtr != nullptr) ? &CM_Bool_struct<T>::_Member : 0);
+			return ((mData != nullptr && mData->mPtr != nullptr) ? &Bool_struct<T>::_Member : 0);
 		}
 		}
 
 
+		/**
+		 * @brief	Returns internal resource pointer and dereferences it.
+		 *
+		 * @note	Throws exception if handle is invalid.
+		 */
 		T* get() const 
 		T* get() const 
 		{ 
 		{ 
 			throwIfNotLoaded();
 			throwIfNotLoaded();
@@ -133,6 +182,11 @@ namespace BansheeEngine
 			return reinterpret_cast<T*>(mData->mPtr.get()); 
 			return reinterpret_cast<T*>(mData->mPtr.get()); 
 		}
 		}
 
 
+		/**
+		 * @brief	Returns the internal shared pointer to the resource.
+		 *
+		 * @note	Throws exception if handle is invalid.
+		 */
 		std::shared_ptr<T> getInternalPtr() const
 		std::shared_ptr<T> getInternalPtr() const
 		{ 
 		{ 
 			throwIfNotLoaded();
 			throwIfNotLoaded();
@@ -143,6 +197,12 @@ namespace BansheeEngine
 	private:
 	private:
 		friend class Resources;
 		friend class Resources;
 
 
+		/**
+		 * @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 ResourceHandle(T* ptr, const String& uuid)
 		explicit ResourceHandle(T* ptr, const String& uuid)
 			:ResourceHandleBase()
 			:ResourceHandleBase()
 		{
 		{
@@ -150,6 +210,9 @@ namespace BansheeEngine
 			_setHandleData(std::shared_ptr<Resource>(ptr, uuid));
 			_setHandleData(std::shared_ptr<Resource>(ptr, uuid));
 		}
 		}
 
 
+		/**
+		 * @brief	Constructs a new valid handle for the provided resource with the provided UUID.
+		 */
 		ResourceHandle(std::shared_ptr<T> ptr, const String& uuid)
 		ResourceHandle(std::shared_ptr<T> ptr, const String& uuid)
 			:ResourceHandleBase()
 			:ResourceHandleBase()
 		{
 		{
@@ -158,12 +221,18 @@ namespace BansheeEngine
 		}
 		}
 	};
 	};
 
 
+	/**
+	 * @brief	Casts one resource handle to another.
+	 */
 	template<class _Ty1, class _Ty2>
 	template<class _Ty1, class _Ty2>
 		ResourceHandle<_Ty1> static_resource_cast(const ResourceHandle<_Ty2>& other)
 		ResourceHandle<_Ty1> static_resource_cast(const ResourceHandle<_Ty2>& other)
 	{	
 	{	
 		return ResourceHandle<_Ty1>(other);
 		return ResourceHandle<_Ty1>(other);
 	}
 	}
 
 
+	/**
+	 * @brief	Checks if two handles point to the same resource.
+	 */
 	template<class _Ty1, class _Ty2>
 	template<class _Ty1, class _Ty2>
 	bool operator==(const ResourceHandle<_Ty1>& _Left, const ResourceHandle<_Ty2>& _Right)
 	bool operator==(const ResourceHandle<_Ty1>& _Left, const ResourceHandle<_Ty2>& _Right)
 	{	
 	{	

+ 38 - 2
CamelotCore/Include/CmResourceManifest.h

@@ -13,6 +13,8 @@ namespace BansheeEngine
 	 * 			save the resource manifest, and then restore it at the start of a new session. This way
 	 * 			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
 	 * 			ensures that resource UUIDs stay consistent and anything referencing them can find the
 	 * 			resources.
 	 * 			resources.
+	 *
+	 *			Thread safe.
 	 */
 	 */
 	class CM_EXPORT ResourceManifest : public IReflectable
 	class CM_EXPORT ResourceManifest : public IReflectable
 	{
 	{
@@ -21,22 +23,48 @@ namespace BansheeEngine
 		explicit ResourceManifest(const ConstructPrivately& dummy);
 		explicit ResourceManifest(const ConstructPrivately& dummy);
 		ResourceManifest(const String& name);
 		ResourceManifest(const String& name);
 
 
+		/**
+		 * @brief	Returns an unique name of the resource manifest.
+		 */
 		const String& getName() const { return mName; }
 		const String& getName() const { return mName; }
 
 
+		/**
+		 * @brief	Registers a new resource in the manifest.
+		 */
 		void registerResource(const String& uuid, const Path& filePath);
 		void registerResource(const String& uuid, const Path& filePath);
+
+		/**
+		 * @brief	Removes a resource from the manifest.
+		 */
 		void unregisterResource(const String& uuid);
 		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;
 		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;
 		bool filePathToUUID(const Path& filePath, String& outUUID) const;
 
 
+		/**
+		 * @brief	Checks if provided UUID exists in the manifest.
+		 */
 		bool uuidExists(const String& uuid) const;
 		bool uuidExists(const String& uuid) const;
+
+		/**
+		 * @brief	Checks if the provided path exists in the manifest.
+		 */
 		bool filePathExists(const Path& filePath) const;
 		bool filePathExists(const Path& filePath) const;
 
 
 		/**
 		/**
 		 * @brief	Saves the resource manifest to the specified location.
 		 * @brief	Saves the resource manifest to the specified location.
 		 *
 		 *
 		 * @param	manifest		Manifest to save.
 		 * @param	manifest		Manifest to save.
-		 * @param	path			Full pathname of the file.
+		 * @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
 		 * @param	relativePath	If not empty, all pathnames in the manifest will be stored
 		 * 							as if relative to this path.
 		 * 							as if relative to this path.
 		 */
 		 */
@@ -45,12 +73,16 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @brief	Loads the resource manifest from the specified location.
 		 * @brief	Loads the resource manifest from the specified location.
 		 *
 		 *
-		 * @param	path			Full pathname of the file.
+		 * @param	path			Full pathname of the file to load the manifest from.
 		 * @param	relativePath	If not empty, all loaded pathnames will have this
 		 * @param	relativePath	If not empty, all loaded pathnames will have this
 		 * 							path prepended.
 		 * 							path prepended.
 		 */
 		 */
 		static ResourceManifestPtr load(const Path& path, const Path& relativePath);
 		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);
 		static ResourceManifestPtr create(const String& name);
 
 
 	private:
 	private:
@@ -61,6 +93,10 @@ namespace BansheeEngine
 		/************************************************************************/
 		/************************************************************************/
 		/* 								RTTI		                     		*/
 		/* 								RTTI		                     		*/
 		/************************************************************************/
 		/************************************************************************/
+
+		/**
+		 * @brief	Creates a new empty resource manifest.
+		 */
 		static ResourceManifestPtr createEmpty();
 		static ResourceManifestPtr createEmpty();
 
 
 	public:
 	public:

+ 60 - 39
CamelotCore/Include/CmResources.h

@@ -5,65 +5,59 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
+	/**
+	 * @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.
+	 *
+	 * @note	Sim thread only.
+	 */
 	class CM_EXPORT Resources : public Module<Resources>
 	class CM_EXPORT Resources : public Module<Resources>
 	{
 	{
 	public:
 	public:
-		/**
-		 * @brief	Constructor.
-		 *
-		 * @param	resMetaPath		Folder where the resource meta-data will be stored. If the folder doesn't exist
-		 * 							it will be created.
-		 */
 		Resources();
 		Resources();
 		~Resources();
 		~Resources();
 
 
 		/**
 		/**
-		 * @brief	Loads the resource from a given path. Returns null if resource can't be loaded.
-		 *
-		 * @param	filePath					The path of the file to load. The file is searched for in
-		 * 										the AssetDatabase first, and if it cannot be found it is
-		 * 										loaded as a temporary resource object. You can't save
-		 * 										references to temporary resource objects because they won't
-		 * 										persist after application shut-down, but otherwise they act
-		 * 										the same as normal resources.
-		 *
-		 * @return	Loaded resource, or null if it cannot be found.
+		 * @brief	Loads the resource from a given path. Returns an empty handle if resource can't be loaded.
+		 *			Resource is loaded synchronously.
 		 */
 		 */
 		HResource load(const Path& filePath);
 		HResource load(const Path& filePath);
 
 
 		/**
 		/**
-		 * @brief	Loads the resource asynchronously. Initially returned resource should not be used
-		 * 			until BaseResourceHandle.isLoaded gets set to true.
+		 * @brief	Loads the resource asynchronously. Initially returned resource handle will be invalid
+		 *			until resource loading is done.
 		 *
 		 *
 		 * @param	filePath	Full pathname of the file.
 		 * @param	filePath	Full pathname of the file.
 		 * 						
 		 * 						
-		 * @return	Resource where the data will eventually be loaded, or null if the file cannot be found.
+		 * @note	You can use returned invalid handle in engine systems as the engine will check for handle 
+		 *			validity before using it.
 		 */
 		 */
 		HResource loadAsync(const Path& filePath);
 		HResource loadAsync(const Path& filePath);
 
 
 		/**
 		/**
-		 * @brief	Loads the resource with the given uuid.
-		 *
-		 * @param	uuid	UUID of the resource to load. 
-		 *
-		 * @return	Loaded resource, or null if it cannot be found.
+		 * @brief	Loads the resource with the given UUID. Returns an empty handle if resource can't be loaded.
+		 *			Resource is loaded synchronously.
 		 */
 		 */
 		HResource loadFromUUID(const String& uuid);
 		HResource loadFromUUID(const String& uuid);
 
 
 		/**
 		/**
-		* @brief	Loads the resource with the given UUID asynchronously. Initially returned resource should not be used
-		* 			until BaseResourceHandle.isLoaded gets set to true.
+		* @brief	Loads the resource with the given UUID asynchronously. Initially returned resource handle will be invalid
+		*			until resource loading is done.
 		 *
 		 *
 		 * @param	uuid	UUID of the resource to load. 
 		 * @param	uuid	UUID of the resource to load. 
 		 *
 		 *
-		 * @return	Resource where the data will eventually be loaded, or null if the file cannot be found.
+		 * @note	You can use returned invalid handle in engine systems as the engine will check for handle
+		 *			validity before using it.
 		 */
 		 */
 		HResource loadFromUUIDAsync(const String& uuid);
 		HResource loadFromUUIDAsync(const String& uuid);
 
 
 		/**
 		/**
-		 * @brief	Unloads the resource that is referenced by the handle.
+		 * @brief	Unloads the resource that is referenced by the handle. 
 		 *
 		 *
-		 * @param	resourceHandle	Handle of the resource.
+		 * @param	resourceHandle	Handle of the resource to unload.
 		 * 							
 		 * 							
 		 * @note	GPU resources held by the resource will be scheduled to be destroyed on the core thread.
 		 * @note	GPU resources held by the resource will be scheduled to be destroyed on the core thread.
 		 * 			Actual resource pointer wont be deleted until all user-held references to it are removed.
 		 * 			Actual resource pointer wont be deleted until all user-held references to it are removed.
@@ -79,22 +73,25 @@ namespace BansheeEngine
 		 * @brief	Saves the resource at the specified location.
 		 * @brief	Saves the resource at the specified location.
 		 *
 		 *
 		 * @param	resource 	Handle to the resource.
 		 * @param	resource 	Handle to the resource.
-		 * @param	filePath 	Full pathname of the file.
+		 * @param	filePath 	Full pathname of the file to save as.
 		 * @param	overwrite	(optional) If true, any existing resource at the specified location will
 		 * @param	overwrite	(optional) If true, any existing resource at the specified location will
 		 * 						be overwritten.
 		 * 						be overwritten.
 		 * 						
 		 * 						
 		 * @note	If the resource is a GpuResource and you are in some way modifying it from the Core thread, make
 		 * @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
 		 * 			sure all those commands are submitted before you call this method. Otherwise an obsolete
 		 * 			version of the resource might get saved.
 		 * 			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.
 		 */
 		 */
 		void save(HResource resource, const Path& filePath, bool overwrite);
 		void save(HResource resource, const Path& filePath, bool overwrite);
 
 
 		/**
 		/**
 		 * @brief	Creates a new resource handle from a resource pointer. 
 		 * @brief	Creates a new resource handle from a resource pointer. 
-		 * 			You will almost never need to call this manually and should instead use
-		 * 			resource-specific methods that return a resource handle in the first place.
+		 *
+		 * @note	Internal method used primarily be resource factory methods.
 		 */
 		 */
-		HResource createResourceHandle(const ResourcePtr& obj);
+		HResource _createResourceHandle(const ResourcePtr& obj);
 
 
 		/**
 		/**
 		 * @brief	Allows you to set a resource manifest containing UUID <-> file path mapping that is
 		 * @brief	Allows you to set a resource manifest containing UUID <-> file path mapping that is
@@ -118,9 +115,35 @@ namespace BansheeEngine
 		 */
 		 */
 		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.
+		 */
 		bool getFilePathFromUUID(const String& uuid, Path& filePath) const;
 		bool getFilePathFromUUID(const String& uuid, Path& filePath) const;
+
+		/**
+		 * @brief	Attempts to retrieve UUID from the provided file path. Returns true
+		 *			if successful, false otherwise.
+		 */
 		bool getUUIDFromFilePath(const Path& path, String& uuid) const;
 		bool getUUIDFromFilePath(const Path& path, String& uuid) const;
 
 
+	private:
+		/**
+		 * @brief	Starts resource loading or returns an already loaded resource.
+		 */
+		HResource loadInternal(const Path& filePath, bool synchronous);
+
+		/**
+		 * @brief	Performs actually reading and deserializing of the resource file. 
+		 *			Called from various worker threads.
+		 */
+		ResourcePtr loadFromDiskAndDeserialize(const Path& filePath);
+
+		/**
+		 * @brief	Callback triggered when the task manager is ready to process the loading task.
+		 */
+		void loadCallback(const Path& filePath, HResource& resource);
+
 	private:
 	private:
 		Vector<ResourceManifestPtr> mResourceManifests;
 		Vector<ResourceManifestPtr> mResourceManifests;
 		ResourceManifestPtr mDefaultResourceManifest;
 		ResourceManifestPtr mDefaultResourceManifest;
@@ -128,14 +151,12 @@ namespace BansheeEngine
 		CM_MUTEX(mInProgressResourcesMutex);
 		CM_MUTEX(mInProgressResourcesMutex);
 		CM_MUTEX(mLoadedResourceMutex);
 		CM_MUTEX(mLoadedResourceMutex);
 
 
-		UnorderedMap<String, HResource> mLoadedResources; 
+		UnorderedMap<String, HResource> mLoadedResources;
 		UnorderedMap<String, HResource> mInProgressResources; // Resources that are being asynchronously loaded
 		UnorderedMap<String, HResource> mInProgressResources; // Resources that are being asynchronously loaded
-
-		HResource loadInternal(const Path& filePath, bool synchronous);
-		ResourcePtr loadFromDiskAndDeserialize(const Path& filePath);
-
-		void loadCallback(const Path& filePath, HResource& resource);
 	};
 	};
 
 
+	/**
+	 * @brief	Provides easy access to the resource manager.
+	 */
 	CM_EXPORT Resources& gResources();
 	CM_EXPORT Resources& gResources();
 }
 }

+ 167 - 118
CamelotCore/Include/CmTexture.h

@@ -1,30 +1,3 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-    (Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2011 Torus Knot Software Ltd
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
 #pragma once
 #pragma once
 
 
 #include "CmPrerequisites.h"
 #include "CmPrerequisites.h"
@@ -35,49 +8,43 @@ THE SOFTWARE.
 
 
 namespace BansheeEngine 
 namespace BansheeEngine 
 {
 {
-	/** Enum identifying the texture usage
-    */
+	/**
+	 * @brief	Properties that describe how is the texture used.
+	 */
     enum TextureUsage
     enum TextureUsage
     {
     {
-		/// @copydoc HardwareBuffer::Usage
-		TU_STATIC = GBU_STATIC, // Optimal setting if texture is read by the GPU often, and very rarely written by CPU
-		TU_DYNAMIC = GBU_DYNAMIC, // Optimal if the texture is updated by CPU often (e.g. every frame)
-		TU_RENDERTARGET = 0x200, // Used for rendering by the GPU
-		TU_DEPTHSTENCIL = 0x400,
+		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 used for rendering by the GPU. */
+		TU_DEPTHSTENCIL = 0x400, /**< Texture used as a depth/stencil buffer by the GPU. */
 		TU_DEFAULT = TU_STATIC
 		TU_DEFAULT = TU_STATIC
     };
     };
 
 
-    /** Enum identifying the texture type
-    */
+	/**
+	 * @brief	Different texture types.
+	 */
     enum TextureType
     enum TextureType
     {
     {
-        /// 1D texture, used in combination with 1D texture coordinates
-        TEX_TYPE_1D = 1,
-        /// 2D texture, used in combination with 2D texture coordinates (default)
-        TEX_TYPE_2D = 2,
-        /// 3D volume texture, used in combination with 3D texture coordinates
-        TEX_TYPE_3D = 3,
-        /// 3D cube map, used in combination with 3D texture coordinates
-        TEX_TYPE_CUBE_MAP = 4
+		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. */
     };
     };
 
 
-	/** Enum identifying special mipmap numbers
-    */
+	/**
+	 * @brief	Mipmap options.
+	 */
 	enum TextureMipmap
 	enum TextureMipmap
 	{
 	{
-		/// Generate mipmaps up to 1x1
-		MIP_UNLIMITED = 0x7FFFFFFF
+		MIP_UNLIMITED = 0x7FFFFFFF /**< Create all mip maps down to 1x1. */
 	};
 	};
 
 
-    /** Abstract class representing a Texture resource.
-        @remarks
-            The actual concrete subclass which will exist for a texture
-            is dependent on the rendering system in use (Direct3D, OpenGL etc).
-            This class represents the commonalities, and is the one 'used'
-            by programmers even though the real implementation could be
-            different in reality. Texture objects are created through
-            the 'create' method of the TextureManager concrete subclass.
-     */
+	/**
+	 * @brief	Abstract class representing a texture. Specific render systems have their
+	 *			own Texture implementations.
+	 *
+	 * @note	Core thread unless specified otherwise.
+	 */
     class CM_EXPORT Texture : public GpuResource
     class CM_EXPORT Texture : public GpuResource
     {
     {
     public:
     public:
@@ -167,15 +134,6 @@ namespace BansheeEngine
          */
          */
         virtual UINT32 getNumFaces() const;
         virtual UINT32 getNumFaces() const;
 
 
-		/**
-		 * @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)
-		 * 			
-		 *			Core thread only.
-		 */
-		virtual bool isBindableAsShaderResource() const { return true; }
-
 		/**
 		/**
 		 * @copydoc GpuResource::writeSubresource
 		 * @copydoc GpuResource::writeSubresource
 		 */
 		 */
@@ -187,31 +145,33 @@ namespace BansheeEngine
 		virtual void readSubresource(UINT32 subresourceIdx, GpuResourceData& data);
 		virtual void readSubresource(UINT32 subresourceIdx, GpuResourceData& data);
 
 
 		/**
 		/**
-		 * @brief	Allocates a buffer you may use for storage when reading a subresource. You
+		 * @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".
 		 * 			need to allocate such a buffer if you are calling "readSubresource".
+		 *
+		 *			You can retrieve a sub-resource index by calling "mapToSubresourceIdx".
 		 * 			
 		 * 			
 		 * @note	Thread safe.
 		 * @note	Thread safe.
 		 */
 		 */
 		PixelDataPtr allocateSubresourceBuffer(UINT32 subresourceIdx) const;
 		PixelDataPtr allocateSubresourceBuffer(UINT32 subresourceIdx) const;
 
 
 		/**
 		/**
-		 * @brief	Maps a subresource index to an exact face and mip level. Subresource indexes
+		 * @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.
 		 * 			are used when reading or writing to the resource.
 		 * 			
 		 * 			
-		 * @note	Subresource index is only valid for the instance it was created on. You cannot use a subresource
+		 * @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
 		 * 			index from a different texture and expect to get valid result. Modifying the resource so the number
-		 * 			of subresources changes, invalidates all subresource indexes.
+		 * 			of sub-resources changes invalidates all sub-resource indexes.
 		 * 			
 		 * 			
 		 *			Thread safe.
 		 *			Thread safe.
 		 */
 		 */
 		void mapFromSubresourceIdx(UINT32 subresourceIdx, UINT32& face, UINT32& mip) const;
 		void mapFromSubresourceIdx(UINT32 subresourceIdx, UINT32& face, UINT32& mip) const;
 
 
 		/**
 		/**
-		 * @brief	Map a face and a mip level to a subresource index you can use for updating or reading
+		 * @brief	Map a face and a mip level to a sub-resource index you can use for updating or reading
 		 * 			a specific sub-resource.
 		 * 			a specific sub-resource.
 		 * 			
 		 * 			
-		 * @note	Generated subresource index is only valid for the instance it was created on. Modifying the resource so the number
-		 * 			of subresources changes, invalidates all subresource indexes.
+		 * @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.
 		 * 			
 		 * 			
 		 *			Thread safe.
 		 *			Thread safe.
 		 */
 		 */
@@ -220,14 +180,14 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @brief	Locks the buffer for reading or writing.
 		 * @brief	Locks the buffer for reading or writing.
 		 *
 		 *
-		 * @param	options 	Options for controlling the operation.
-		 * @param	mipLevel	(optional) the mip level.
-		 * @param	face		(optional) the face.
+		 * @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.
 		 * @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
 		 * @note	If you are just reading or writing one block of data use
-		 * 			readData/writeData methods as they can be must faster in certain situations.
+		 * 			readData/writeData methods as they can be much faster in certain situations.
 		 * 			
 		 * 			
 		 *			Core thread only.
 		 *			Core thread only.
 		 */
 		 */
@@ -252,6 +212,10 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @brief	Reads data from the texture buffer into the provided buffer.
 		 * @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.
+		 *
 		 * @note	Core thread only.
 		 * @note	Core thread only.
 		 */
 		 */
 		virtual void readData(PixelData& dest, UINT32 mipLevel = 0, UINT32 face = 0) = 0;
 		virtual void readData(PixelData& dest, UINT32 mipLevel = 0, UINT32 face = 0) = 0;
@@ -259,6 +223,12 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @brief	Writes data from the provided buffer into the texture buffer.
 		 * @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.
+		 *
 		 * @note	Core thread only.
 		 * @note	Core thread only.
 		 */
 		 */
 		virtual void writeData(const PixelData& src, UINT32 mipLevel = 0, UINT32 face = 0, bool discardWholeBuffer = false) = 0;
 		virtual void writeData(const PixelData& src, UINT32 mipLevel = 0, UINT32 face = 0, bool discardWholeBuffer = false) = 0;
@@ -270,18 +240,108 @@ namespace BansheeEngine
 		 */
 		 */
 		static const HTexture& dummy();
 		static const HTexture& dummy();
 
 
+		/**
+		 * @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; }
+
 		/************************************************************************/
 		/************************************************************************/
 		/* 								TEXTURE VIEW                      		*/
 		/* 								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.
+		 */
 		static TextureViewPtr requestView(TexturePtr texture, UINT32 mostDetailMip, UINT32 numMips, UINT32 firstArraySlice, UINT32 numArraySlices, GpuViewUsage usage);
 		static TextureViewPtr requestView(TexturePtr 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.
+		 */
 		static void releaseView(TextureViewPtr view);
 		static void releaseView(TextureViewPtr view);
 
 
+		/************************************************************************/
+		/* 								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	fsaa				If higher than 1, texture containing multiple samples per pixel is created.
+		 * @param	fsaaHint			Hint about what kind of multisampling to use. Render system specific.
+		 */
+		static HTexture create(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
+			int numMips, PixelFormat format, int usage = TU_DEFAULT,
+			bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
+
+
+		/**
+		 * @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 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	fsaa				If higher than 1, texture containing multiple samples per pixel is created.
+		 * @param	fsaaHint			Hint about what kind of multisampling to use. Render system specific.
+		 */
+		static HTexture create(TextureType texType, UINT32 width, UINT32 height, int numMips,
+			PixelFormat format, int usage = TU_DEFAULT,
+			bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
+
+		/**
+		 * @copydoc	create
+		 *
+		 * @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 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
+
+		/**
+		 * @copydoc	create
+		 *
+		 * @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 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
+
 	protected:
 	protected:
+		/************************************************************************/
+		/* 								TEXTURE VIEW                      		*/
+		/************************************************************************/
 
 
+		/**
+		 * @brief	Creates a new empty/undefined texture view.
+		 */
 		virtual TextureViewPtr createView();
 		virtual TextureViewPtr createView();
+
+		/**
+		 * @brief	Releases all internal texture view references. Views won't get destroyed if there are external references still held.
+		 */
 		void clearBufferViews();
 		void clearBufferViews();
 
 
+		/**
+		 * @brief	Holds a single texture view with a usage reference count.
+		 */
 		struct TextureViewReference
 		struct TextureViewReference
 		{
 		{
 			TextureViewReference(TextureViewPtr _view)
 			TextureViewReference(TextureViewPtr _view)
@@ -297,38 +357,47 @@ namespace BansheeEngine
     protected:
     protected:
 		friend class TextureManager;
 		friend class TextureManager;
 
 
-        UINT32 mHeight; // Immutable
-        UINT32 mWidth; // Immutable
-        UINT32 mDepth; // Immutable
-
-		UINT32 mNumMipmaps; // Immutable
-		bool mHwGamma; // Immutable
-		UINT32 mFSAA; // Immutable
-		String mFSAAHint; // Immutable
-
-        TextureType mTextureType; // Immutable
-		PixelFormat mFormat; // Immutable
-        int mUsage; // Immutable
-
 		Texture();
 		Texture();
 
 
 		/**
 		/**
-		 * @brief	Initializes the texture. This must be called right after the texture is constructed. Called by TextureManager
-		 * 			upon texture creation, so usually you don't want to call this manually.
-		 * 			
-		 * @note	Initialization is not done immediately, and is instead just scheduled on the
-		 * 			core thread. Unless called from core thread, in which case it is initialized
-		 * 			right away.
+		 * @copydoc	GpuResource::initialize
 		 */
 		 */
 		void initialize(TextureType textureType, UINT32 width, UINT32 height, UINT32 depth, UINT32 numMipmaps, 
 		void initialize(TextureType textureType, UINT32 width, UINT32 height, UINT32 depth, UINT32 numMipmaps, 
 			PixelFormat format, int usage, bool hwGamma, UINT32 fsaa, const String& fsaaHint);
 			PixelFormat format, int usage, bool hwGamma, UINT32 fsaa, const String& fsaaHint);
 
 
+		/**
+		 * @copydoc	lock
+		 */
 		virtual PixelData lockImpl(GpuLockOptions options, UINT32 mipLevel = 0, UINT32 face = 0) = 0;
 		virtual PixelData lockImpl(GpuLockOptions options, UINT32 mipLevel = 0, UINT32 face = 0) = 0;
+
+		/**
+		 * @copydoc	unlock
+		 */
 		virtual void unlockImpl() = 0;
 		virtual void unlockImpl() = 0;
 
 
+		/**
+		 * @copydoc	copy
+		 */
 		virtual void copyImpl(TexturePtr& target) = 0;
 		virtual void copyImpl(TexturePtr& target) = 0;
-		/// @copydoc Resource::calculateSize
-		UINT32 calculateSize(void) const;
+
+		/**
+		 * @copydoc	Resource::calculateSize
+		 */
+		UINT32 calculateSize() const;
+
+	protected:
+		UINT32 mHeight; // Immutable
+		UINT32 mWidth; // Immutable
+		UINT32 mDepth; // Immutable
+
+		UINT32 mNumMipmaps; // Immutable
+		bool mHwGamma; // Immutable
+		UINT32 mFSAA; // Immutable
+		String mFSAAHint; // Immutable
+
+		TextureType mTextureType; // Immutable
+		PixelFormat mFormat; // Immutable
+		int mUsage; // Immutable
 
 
 		/************************************************************************/
 		/************************************************************************/
 		/* 								SERIALIZATION                      		*/
 		/* 								SERIALIZATION                      		*/
@@ -337,25 +406,5 @@ namespace BansheeEngine
 		friend class TextureRTTI;
 		friend class TextureRTTI;
 		static RTTITypeBase* getRTTIStatic();
 		static RTTITypeBase* getRTTIStatic();
 		virtual RTTITypeBase* getRTTI() const;
 		virtual RTTITypeBase* getRTTI() const;
-
-		/************************************************************************/
-		/* 								STATICS		                     		*/
-		/************************************************************************/
-	public:
-		static HTexture create(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, 
-			int num_mips, PixelFormat format, int usage = TU_DEFAULT,
-			bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
-
-		static HTexture create(TextureType texType, UINT32 width, UINT32 height, int num_mips,
-			PixelFormat format, int usage = TU_DEFAULT,
-			bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
-
-		static TexturePtr _createPtr(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, 
-			int num_mips, PixelFormat format, int usage = TU_DEFAULT,
-			bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
-
-		static TexturePtr _createPtr(TextureType texType, UINT32 width, UINT32 height, int num_mips,
-			PixelFormat format, int usage = TU_DEFAULT,
-			bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
     };
     };
 }
 }

+ 50 - 141
CamelotCore/Include/CmTextureManager.h

@@ -1,30 +1,3 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-    (Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2011 Torus Knot Software Ltd
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
 #pragma once
 #pragma once
 
 
 #include "CmPrerequisites.h"
 #include "CmPrerequisites.h"
@@ -35,9 +8,10 @@ THE SOFTWARE.
 namespace BansheeEngine 
 namespace BansheeEngine 
 {
 {
     /**
     /**
-     * @brief	Class for loading and managing textures.
-     *
-     * @note	Must be initialized when RenderSystem is first started.
+     * @brief	Defines interface for creation of textures. Render systems
+	 *			provide their own implementations.
+	 *
+	 * @note	Thread safe.
      */
      */
     class CM_EXPORT TextureManager : public Module<TextureManager>
     class CM_EXPORT TextureManager : public Module<TextureManager>
     {
     {
@@ -46,112 +20,47 @@ namespace BansheeEngine
         TextureManager();
         TextureManager();
         virtual ~TextureManager();
         virtual ~TextureManager();
 
 
-		/** Create a manual texture with specified width, height and depth (not loaded from a file).
-            @param
-                name The name to give the resulting texture
-            @param
-                group The name of the resource group to assign the texture to
-            @param
-                texType The type of texture to load/create, defaults to normal 2D textures
-            @param
-                width, height, depth The dimensions of the texture
-            @param
-                numMipmaps The number of pre-filtered mipmaps to generate. If left to MIP_DEFAULT then
-                the TextureManager's default number of mipmaps will be used (see setDefaultNumMipmaps())
-				If set to MIP_UNLIMITED mipmaps will be generated until the lowest possible
-				level, 1x1x1.
-            @param
-                format The internal format you wish to request; the manager reserves
-                the right to create a different format if the one you select is
-                not available in this context.
-			@param 
-				usage The kind of usage this texture is intended for. It 
-				is a combination of TU_STATIC, TU_DYNAMIC, TU_WRITE_ONLY, 
-				TU_AUTOMIPMAP and TU_RENDERTARGET (see TextureUsage enum). You are
-            	strongly advised to use HBU_STATIC_WRITE_ONLY wherever possible, if you need to 
-            	update regularly, consider HBU_DYNAMIC_WRITE_ONLY.
-            @param
-                loader If you intend the contents of the manual texture to be 
-                regularly updated, to the extent that you don't need to recover 
-                the contents if the texture content is lost somehow, you can leave
-                this parameter as 0. However, if you intend to populate the
-                texture only once, then you should implement ManualResourceLoader
-                and pass a pointer to it in this parameter; this means that if the
-                manual texture ever needs to be reloaded, the ManualResourceLoader
-                will be called to do it.
-			@param hwGammaCorrection Pass 'true' to enable hardware gamma correction
-				(sRGB) on this texture. The hardware will convert from gamma space
-				to linear space when reading from this texture. Only applicable for 
-				8-bits per channel textures, will be ignored for other types. Has the advantage
-				over pre-applied gamma that the texture precision is maintained.
-			@param fsaa The level of multisampling to use if this is a render target. Ignored
-				if usage does not include TU_RENDERTARGET or if the device does
-				not support it.
-        */
+		/**
+		 * @copydoc	Texture::create(TextureType, UINT32, UINT32, UINT32, int, PixelFormat, int, bool, UINT32, const String&)
+		 */
         TexturePtr createTexture(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, 
         TexturePtr createTexture(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, 
-			int num_mips, PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false, 
+			int numMips, PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false, 
 			UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
 			UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
 			
 			
-        /** Create a manual texture with a depth of 1 (not loaded from a file).
-            @param
-                name The name to give the resulting texture
-            @param
-                group The name of the resource group to assign the texture to
-            @param
-                texType The type of texture to load/create, defaults to normal 2D textures
-            @param
-                width, height The dimensions of the texture
-            @param
-                numMipmaps The number of pre-filtered mipmaps to generate. If left to MIP_DEFAULT then
-                the TextureManager's default number of mipmaps will be used (see setDefaultNumMipmaps()).
-				If set to MIP_UNLIMITED mipmaps will be generated until the lowest possible
-				level, 1x1x1.
-            @param
-                format The internal format you wish to request; the manager reserves
-                the right to create a different format if the one you select is
-                not available in this context.
-			@param 
-				usage The kind of usage this texture is intended for. It 
-				is a combination of TU_STATIC, TU_DYNAMIC, TU_WRITE_ONLY, 
-				TU_AUTOMIPMAP and TU_RENDERTARGET (see TextureUsage enum). You are
-            	strongly advised to use HBU_STATIC_WRITE_ONLY wherever possible, if you need to 
-            	update regularly, consider HBU_DYNAMIC_WRITE_ONLY.
-            @param
-                loader If you intend the contents of the manual texture to be 
-                regularly updated, to the extent that you don't need to recover 
-                the contents if the texture content is lost somehow, you can leave
-                this parameter as 0. However, if you intend to populate the
-                texture only once, then you should implement ManualResourceLoader
-                and pass a pointer to it in this parameter; this means that if the
-                manual texture ever needs to be reloaded, the ManualResourceLoader
-                will be called to do it.
-			 @param hwGammaCorrection Pass 'true' to enable hardware gamma correction
-				 (sRGB) on this texture. The hardware will convert from gamma space
-				 to linear space when reading from this texture. Only applicable for 
-				 8-bits per channel textures, will be ignored for other types. Has the advantage
-				 over pre-applied gamma that the texture precision is maintained.
-			@param fsaa The level of multisampling to use if this is a render target. Ignored
-				if usage does not include TU_RENDERTARGET or if the device does
-				not support it.
-        */
-        TexturePtr createTexture(TextureType texType, UINT32 width, UINT32 height, int num_mips,
+		/**
+		 * @copydoc	Texture::create(TextureType, UINT32, UINT32, int, PixelFormat, int, bool, UINT32, const String&)
+		 */
+		TexturePtr createTexture(TextureType texType, UINT32 width, UINT32 height, int numMips,
             PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false, UINT32 fsaa = 0, 
             PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false, UINT32 fsaa = 0, 
 			const String& fsaaHint = StringUtil::BLANK)
 			const String& fsaaHint = StringUtil::BLANK)
 		{
 		{
 			return createTexture(texType, width, height, 1, 
 			return createTexture(texType, width, height, 1, 
-				num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
+				numMips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
 		}
 		}
 
 
 		/**
 		/**
 		 * @brief	Creates a completely empty and uninitialized Texture.
 		 * @brief	Creates a completely empty and uninitialized Texture.
-		 * 			Should only be used for VERY specific purposes, like deserialization,
+		 *
+		 * @note	Internal method. Should only be used for very specific purposes, like deserialization,
 		 * 			as it requires additional manual initialization that is not required normally.
 		 * 			as it requires additional manual initialization that is not required normally.
 		 */
 		 */
-		TexturePtr createEmpty();
+		TexturePtr _createEmpty();
 
 
 		/**
 		/**
 		 * @brief	Creates a new RenderTexture and automatically generates a color surface
 		 * @brief	Creates a new RenderTexture and automatically generates a color surface
-		 * 			and (optionally) a depth/stencil 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	fsaa				If higher than 1, texture containing multiple samples per pixel is created.
+		 * @param	fsaaHint			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, 
 		virtual RenderTexturePtr createRenderTexture(TextureType textureType, UINT32 width, UINT32 height, 
 			PixelFormat format = PF_R8G8B8A8, bool hwGamma = false, UINT32 fsaa = 0, const String& fsaaHint = "", 
 			PixelFormat format = PF_R8G8B8A8, bool hwGamma = false, UINT32 fsaa = 0, const String& fsaaHint = "", 
@@ -166,25 +75,7 @@ namespace BansheeEngine
 		 * @brief	Creates a new multi render texture. You may use this type of texture
 		 * @brief	Creates a new multi render texture. You may use this type of texture
 		 * 			to render to multiple output textures at once.
 		 * 			to render to multiple output textures at once.
 		 */
 		 */
-		virtual MultiRenderTexturePtr createEmptyMultiRenderTexture();
-
-		/** Returns whether this render system can natively support the precise texture 
-			format requested with the given usage options.
-		@remarks
-			You can still create textures with this format even if this method returns
-			false; the texture format will just be altered to one which the device does
-			support.
-		@note
-			Sometimes the device may just slightly change the format, such as reordering the 
-			channels or packing the channels differently, without it making and qualitative 
-			differences to the texture. If you want to just detect whether the quality of a
-			given texture will be reduced, use isEquivalentFormatSupport instead.
-		@param format The pixel format requested
-		@param usage The kind of usage this texture is intended for, a combination of 
-			the TextureUsage flags.
-		@returns true if the format is natively supported, false if a fallback would be used.
-		*/
-		virtual bool isFormatSupported(TextureType ttype, PixelFormat format, int usage);
+		virtual MultiRenderTexturePtr createMultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc);
 
 
 		/**
 		/**
 		 * @brief	Gets the format which will be natively used for a requested format given the
 		 * @brief	Gets the format which will be natively used for a requested format given the
@@ -197,12 +88,30 @@ namespace BansheeEngine
 		const HTexture& getDummyTexture() const { return mDummyTexture; }
 		const HTexture& getDummyTexture() const { return mDummyTexture; }
 
 
 	protected:
 	protected:
-		HTexture mDummyTexture;
-
+		/**
+		 * @brief	Creates an empty and uninitialized texture of a specific type. This is to be implemented
+		 *			by render systems with their own implementations.
+		 */
 		virtual TexturePtr createTextureImpl() = 0;
 		virtual TexturePtr createTextureImpl() = 0;
+
+		/**
+		 * @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() = 0;
 		virtual RenderTexturePtr createRenderTextureImpl() = 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() = 0;
 		virtual MultiRenderTexturePtr createMultiRenderTextureImpl() = 0;
 
 
+		/**
+		 * @copydoc	Module::onStartUp
+		 */
 		virtual void onStartUp();
 		virtual void onStartUp();
+
+	protected:
+		HTexture mDummyTexture;
     };
     };
 }
 }

+ 1 - 1
CamelotCore/Include/CmTextureRTTI.h

@@ -137,7 +137,7 @@ namespace BansheeEngine
 
 
 		virtual std::shared_ptr<IReflectable> newRTTIObject()
 		virtual std::shared_ptr<IReflectable> newRTTIObject()
 		{
 		{
-			return TextureManager::instance().createEmpty();
+			return TextureManager::instance()._createEmpty();
 		}
 		}
 	};
 	};
 }
 }

+ 18 - 0
CamelotCore/Include/CmTransientMesh.h

@@ -5,6 +5,16 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
+	/**
+	 * @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
+	 */
 	class CM_EXPORT TransientMesh : public MeshBase
 	class CM_EXPORT TransientMesh : public MeshBase
 	{
 	{
 	public:
 	public:
@@ -48,9 +58,17 @@ namespace BansheeEngine
 	protected:
 	protected:
 		friend class MeshHeap;
 		friend class MeshHeap;
 
 
+		/**
+		 * @brief	Constructs a new transient mesh.
+		 *
+		 * @see		MeshHeap::alloc
+		 */
 		TransientMesh(const MeshHeapPtr& parentHeap, UINT32 id, UINT32 numIndices, 
 		TransientMesh(const MeshHeapPtr& parentHeap, UINT32 id, UINT32 numIndices, 
 			UINT32 numVertices, DrawOperationType drawOp = DOT_TRIANGLE_LIST);
 			UINT32 numVertices, 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; }
 		void markAsDestroyed() { mIsDestroyed = true; }
 
 
 	protected:
 	protected:

+ 46 - 6
CamelotCore/Include/CmVertexDataDesc.h

@@ -5,14 +5,19 @@
 
 
 namespace BansheeEngine
 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 CM_EXPORT VertexDataDesc : public IReflectable
 	class CM_EXPORT VertexDataDesc : public IReflectable
 	{
 	{
 	public:
 	public:
 		VertexDataDesc() {}
 		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. 
+		 * @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	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	semantic   	Semantic that allows the engine to connect the data to a shader input slot.
@@ -27,31 +32,66 @@ namespace BansheeEngine
 		bool hasElement(VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0) const;
 		bool hasElement(VertexElementSemantic semantic, UINT32 semanticIdx = 0, UINT32 streamIdx = 0) const;
 
 
 		/**
 		/**
-		 * @brief	Creates a new vertex declaration based on set vertex elements.
+		 * @brief	Creates a new vertex declaration based on currently set vertex elements.
 		 */
 		 */
 		VertexDeclarationPtr createDeclaration() const;
 		VertexDeclarationPtr createDeclaration() 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;
 		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;
 		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;
 		UINT32 getVertexStride(UINT32 streamIdx) const;
+
+		/**
+		 * @brief	Gets vertex stride in bytes (offset from one vertex to another) in all the streams.
+		 */
 		UINT32 getVertexStride() const;
 		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;
 		UINT32 getStreamOffset(UINT32 streamIdx) const;
 
 
+		/**
+		 * @brief	Returns the number of vertex elements.
+		 */
 		UINT32 getNumElements() const { return (UINT32)mVertexElements.size(); }
 		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]; }
 		const VertexElement& getElement(UINT32 idx) const { return mVertexElements[idx]; }
 	private:
 	private:
-		friend class Mesh; // To avoid polluting the public interface with a bunch of nearly useless methods for outside world
+		friend class Mesh;
 		friend class MeshHeap;
 		friend class MeshHeap;
 
 
-		Vector<VertexElement> mVertexElements;
-
+		/**
+		 * @brief	Returns the largest stream index of all the stored vertex elements.
+		 */
 		UINT32 getMaxStreamIdx() const;
 		UINT32 getMaxStreamIdx() const;
+
+		/**
+		 * @brief	Checks if any of the vertex elements use the specified stream index.
+		 */
 		bool hasStream(UINT32 streamIdx) const;
 		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);
 		void clearIfItExists(VertexElementType type, VertexElementSemantic semantic, UINT32 semanticIdx, UINT32 streamIdx);
 
 
+	private:
+		Vector<VertexElement> mVertexElements;
+
 		/************************************************************************/
 		/************************************************************************/
 		/* 								SERIALIZATION                      		*/
 		/* 								SERIALIZATION                      		*/
 		/************************************************************************/
 		/************************************************************************/

+ 1 - 1
CamelotCore/Source/CmBlendState.cpp

@@ -78,7 +78,7 @@ namespace BansheeEngine
 	{
 	{
 		BlendStatePtr blendStatePtr = RenderStateManager::instance().createBlendState(desc);
 		BlendStatePtr blendStatePtr = RenderStateManager::instance().createBlendState(desc);
 
 
-		return static_resource_cast<BlendState>(gResources().createResourceHandle(blendStatePtr));
+		return static_resource_cast<BlendState>(gResources()._createResourceHandle(blendStatePtr));
 	}
 	}
 
 
 	/************************************************************************/
 	/************************************************************************/

+ 1 - 1
CamelotCore/Source/CmDepthStencilState.cpp

@@ -23,7 +23,7 @@ namespace BansheeEngine
 	{
 	{
 		DepthStencilStatePtr depthStencilPtr = RenderStateManager::instance().createDepthStencilState(desc);
 		DepthStencilStatePtr depthStencilPtr = RenderStateManager::instance().createDepthStencilState(desc);
 
 
-		return static_resource_cast<DepthStencilState>(gResources().createResourceHandle(depthStencilPtr));
+		return static_resource_cast<DepthStencilState>(gResources()._createResourceHandle(depthStencilPtr));
 	}
 	}
 
 
 	/************************************************************************/
 	/************************************************************************/

+ 1 - 1
CamelotCore/Source/CmFont.cpp

@@ -87,7 +87,7 @@ namespace BansheeEngine
 	{
 	{
 		FontPtr newFont = _createPtr(fontData);
 		FontPtr newFont = _createPtr(fontData);
 
 
-		return gResources().createResourceHandle(newFont);
+		return gResources()._createResourceHandle(newFont);
 	}
 	}
 
 
 	FontPtr Font::_createPtr(const Vector<FontData>& fontData)
 	FontPtr Font::_createPtr(const Vector<FontData>& fontData)

+ 1 - 1
CamelotCore/Source/CmGpuProgInclude.cpp

@@ -11,7 +11,7 @@ namespace BansheeEngine
 
 
 	HGpuProgInclude GpuProgInclude::create(const String& includeString)
 	HGpuProgInclude GpuProgInclude::create(const String& includeString)
 	{
 	{
-		return static_resource_cast<GpuProgInclude>(gResources().createResourceHandle(_createPtr(includeString)));
+		return static_resource_cast<GpuProgInclude>(gResources()._createResourceHandle(_createPtr(includeString)));
 	}
 	}
 
 
 	GpuProgIncludePtr GpuProgInclude::_createPtr(const String& includeString)
 	GpuProgIncludePtr GpuProgInclude::_createPtr(const String& includeString)

+ 1 - 1
CamelotCore/Source/CmGpuProgram.cpp

@@ -76,7 +76,7 @@ namespace BansheeEngine
 	{
 	{
 		GpuProgramPtr programPtr = _createPtr(source, entryPoint, language, gptype, profile, includes);
 		GpuProgramPtr programPtr = _createPtr(source, entryPoint, language, gptype, profile, includes);
 
 
-		return static_resource_cast<GpuProgram>(gResources().createResourceHandle(programPtr));
+		return static_resource_cast<GpuProgram>(gResources()._createResourceHandle(programPtr));
 	}
 	}
 
 
 	GpuProgramPtr GpuProgram::_createPtr(const String& source, const String& entryPoint,
 	GpuProgramPtr GpuProgram::_createPtr(const String& source, const String& entryPoint,

+ 1 - 1
CamelotCore/Source/CmImporter.cpp

@@ -78,7 +78,7 @@ namespace BansheeEngine
 		}
 		}
 
 
 		ResourcePtr importedResource = importer->import(inputFilePath, importOptions);
 		ResourcePtr importedResource = importer->import(inputFilePath, importOptions);
-		return gResources().createResourceHandle(importedResource);
+		return gResources()._createResourceHandle(importedResource);
 	}
 	}
 
 
 	void Importer::reimport(HResource& existingResource, const Path& inputFilePath, ConstImportOptionsPtr importOptions)
 	void Importer::reimport(HResource& existingResource, const Path& inputFilePath, ConstImportOptionsPtr importOptions)

+ 2 - 2
CamelotCore/Source/CmMaterial.cpp

@@ -713,14 +713,14 @@ namespace BansheeEngine
 	{
 	{
 		MaterialPtr materialPtr = MaterialManager::instance().create();
 		MaterialPtr materialPtr = MaterialManager::instance().create();
 
 
-		return static_resource_cast<Material>(gResources().createResourceHandle(materialPtr));
+		return static_resource_cast<Material>(gResources()._createResourceHandle(materialPtr));
 	}
 	}
 
 
 	HMaterial Material::create(ShaderPtr shader)
 	HMaterial Material::create(ShaderPtr shader)
 	{
 	{
 		MaterialPtr materialPtr = MaterialManager::instance().create(shader);
 		MaterialPtr materialPtr = MaterialManager::instance().create(shader);
 
 
-		return static_resource_cast<Material>(gResources().createResourceHandle(materialPtr));
+		return static_resource_cast<Material>(gResources()._createResourceHandle(materialPtr));
 	}
 	}
 
 
 	RTTITypeBase* Material::getRTTIStatic()
 	RTTITypeBase* Material::getRTTIStatic()

+ 3 - 3
CamelotCore/Source/CmMesh.cpp

@@ -355,7 +355,7 @@ namespace BansheeEngine
 	{
 	{
 		MeshPtr meshPtr = _createPtr(numVertices, numIndices, vertexDesc, bufferType, drawOp, indexType);
 		MeshPtr meshPtr = _createPtr(numVertices, numIndices, vertexDesc, bufferType, drawOp, indexType);
 
 
-		return static_resource_cast<Mesh>(gResources().createResourceHandle(meshPtr));
+		return static_resource_cast<Mesh>(gResources()._createResourceHandle(meshPtr));
 	}
 	}
 
 
 	HMesh Mesh::create(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc, 
 	HMesh Mesh::create(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc, 
@@ -364,14 +364,14 @@ namespace BansheeEngine
 		MeshPtr meshPtr = _createPtr(numVertices, numIndices, vertexDesc, 
 		MeshPtr meshPtr = _createPtr(numVertices, numIndices, vertexDesc, 
 			initialMeshData, bufferType, drawOp, indexType);
 			initialMeshData, bufferType, drawOp, indexType);
 
 
-		return static_resource_cast<Mesh>(gResources().createResourceHandle(meshPtr));
+		return static_resource_cast<Mesh>(gResources()._createResourceHandle(meshPtr));
 	}
 	}
 
 
 	HMesh Mesh::create(const MeshDataPtr& initialMeshData, MeshBufferType bufferType, DrawOperationType drawOp)
 	HMesh Mesh::create(const MeshDataPtr& initialMeshData, MeshBufferType bufferType, DrawOperationType drawOp)
 	{
 	{
 		MeshPtr meshPtr = _createPtr(initialMeshData, bufferType, drawOp);
 		MeshPtr meshPtr = _createPtr(initialMeshData, bufferType, drawOp);
 
 
-		return static_resource_cast<Mesh>(gResources().createResourceHandle(meshPtr));
+		return static_resource_cast<Mesh>(gResources()._createResourceHandle(meshPtr));
 	}
 	}
 
 
 	MeshPtr Mesh::_createPtr(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc, 
 	MeshPtr Mesh::_createPtr(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc, 

+ 57 - 0
CamelotCore/Source/CmPixelData.cpp

@@ -1,6 +1,7 @@
 #include "CmPixelData.h"
 #include "CmPixelData.h"
 #include "CmPixelUtil.h"
 #include "CmPixelUtil.h"
 #include "CmPixelDataRTTI.h"
 #include "CmPixelDataRTTI.h"
+#include "CmColor.h"
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
@@ -25,6 +26,62 @@ namespace BansheeEngine
 		return *this;
 		return *this;
 	}
 	}
 
 
+	UINT32 PixelData::getConsecutiveSize() const
+	{
+		return PixelUtil::getMemorySize(getWidth(), getHeight(), getDepth(), mFormat);
+	}
+
+	PixelData PixelData::getSubVolume(const PixelVolume &def) const
+	{
+		if (PixelUtil::isCompressed(mFormat))
+		{
+			if (def.left == getLeft() && def.top == getTop() && def.front == getFront() &&
+				def.right == getRight() && def.bottom == getBottom() && def.back == getBack())
+			{
+				// Entire buffer is being queried
+				return *this;
+			}
+
+			CM_EXCEPT(InvalidParametersException, "Cannot return subvolume of compressed PixelBuffer");
+		}
+
+		if (!mExtents.contains(def))
+		{
+			CM_EXCEPT(InvalidParametersException, "Bounds out of range");
+		}
+
+		const size_t elemSize = PixelUtil::getNumElemBytes(mFormat);
+		PixelData rval(def.getWidth(), def.getHeight(), def.getDepth(), mFormat);
+
+		rval.setExternalBuffer(((UINT8*)getData()) + ((def.left - getLeft())*elemSize)
+			+ ((def.top - getTop())*mRowPitch*elemSize)
+			+ ((def.front - getFront())*mSlicePitch*elemSize));
+
+		rval.mRowPitch = mRowPitch;
+		rval.mSlicePitch = mSlicePitch;
+		rval.mFormat = mFormat;
+
+		return rval;
+	}
+
+	Color PixelData::getColorAt(UINT32 x, UINT32 y, UINT32 z)
+	{
+		Color cv;
+
+		UINT32 pixelSize = PixelUtil::getNumElemBytes(mFormat);
+		UINT32 pixelOffset = pixelSize * (z * mSlicePitch + y * mRowPitch + x);
+		PixelUtil::unpackColour(&cv, mFormat, (unsigned char *)getData() + pixelOffset);
+
+		return cv;
+	}
+
+	void PixelData::setColorAt(Color const &cv, UINT32 x, UINT32 y, UINT32 z)
+	{
+		UINT32 pixelSize = PixelUtil::getNumElemBytes(mFormat);
+		UINT32 pixelOffset = pixelSize * (z * mSlicePitch + y * mRowPitch + x);
+		PixelUtil::packColour(cv, mFormat, (unsigned char *)getData() + pixelOffset);
+	}
+
 	UINT32 PixelData::getInternalBufferSize()
 	UINT32 PixelData::getInternalBufferSize()
 	{
 	{
 		return PixelUtil::getMemorySize(getWidth(), getHeight(), getDepth(), getFormat());
 		return PixelUtil::getMemorySize(getWidth(), getHeight(), getDepth(), getFormat());

+ 0 - 56
CamelotCore/Source/CmPixelUtil.cpp

@@ -746,44 +746,6 @@ namespace BansheeEngine {
 		0, 0, 0, 0, 0, 0, 0, 0
 		0, 0, 0, 0, 0, 0, 0, 0
 		}, 
 		}, 
     };
     };
-    //-----------------------------------------------------------------------
-	UINT32 PixelData::getConsecutiveSize() const
-	{
-		return PixelUtil::getMemorySize(getWidth(), getHeight(), getDepth(), mFormat);
-	}
-	PixelData PixelData::getSubVolume(const PixelVolume &def) const
-	{
-		if(PixelUtil::isCompressed(mFormat))
-		{
-			if(def.left == getLeft() && def.top == getTop() && def.front == getFront() &&
-			   def.right == getRight() && def.bottom == getBottom() && def.back == getBack())
-			{
-				// Entire buffer is being queried
-				return *this;
-			}
-			CM_EXCEPT(InvalidParametersException, "Cannot return subvolume of compressed PixelBuffer");
-		}
-		if(!mExtents.contains(def))
-		{
-			CM_EXCEPT(InvalidParametersException, "Bounds out of range");
-		}
-
-		const size_t elemSize = PixelUtil::getNumElemBytes(mFormat);
-		// Calculate new data origin
-		// Notice how we do not propagate left/top/front from the incoming box, since
-		// the returned pointer is already offset
-		PixelData rval(def.getWidth(), def.getHeight(), def.getDepth(), mFormat);
-
-		rval.setExternalBuffer(((UINT8*)getData()) + ((def.left-getLeft())*elemSize)
-			+ ((def.top-getTop())*mRowPitch*elemSize)
-			+ ((def.front-getFront())*mSlicePitch*elemSize));
-
-		rval.mRowPitch = mRowPitch;
-		rval.mSlicePitch = mSlicePitch;
-		rval.mFormat = mFormat;
-
-		return rval;
-	}
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     /**
     /**
     * Directly get the description record for provided pixel format. For debug builds,
     * Directly get the description record for provided pixel format. For debug builds,
@@ -1484,22 +1446,4 @@ namespace BansheeEngine {
 			buffer[2] = (UINT8)b;
 			buffer[2] = (UINT8)b;
 		}
 		}
 	}
 	}
-
-    Color PixelData::getColorAt(UINT32 x, UINT32 y, UINT32 z)
-    {
-        Color cv;
-
-        UINT32 pixelSize = PixelUtil::getNumElemBytes(mFormat);
-        UINT32 pixelOffset = pixelSize * (z * mSlicePitch + y * mRowPitch + x);
-        PixelUtil::unpackColour(&cv, mFormat, (unsigned char *)getData() + pixelOffset);
-
-        return cv;
-    }
-
-    void PixelData::setColorAt(Color const &cv, UINT32 x, UINT32 y, UINT32 z)
-    {
-        UINT32 pixelSize = PixelUtil::getNumElemBytes(mFormat);
-        UINT32 pixelOffset = pixelSize * (z * mSlicePitch + y * mRowPitch + x);
-        PixelUtil::packColour(cv, mFormat, (unsigned char *)getData() + pixelOffset);
-    }
 }
 }

+ 1 - 1
CamelotCore/Source/CmRasterizerState.cpp

@@ -22,7 +22,7 @@ namespace BansheeEngine
 	{
 	{
 		RasterizerStatePtr rasterizerPtr = RenderStateManager::instance().createRasterizerState(desc);
 		RasterizerStatePtr rasterizerPtr = RenderStateManager::instance().createRasterizerState(desc);
 
 
-		return static_resource_cast<RasterizerState>(gResources().createResourceHandle(rasterizerPtr));
+		return static_resource_cast<RasterizerState>(gResources()._createResourceHandle(rasterizerPtr));
 	}
 	}
 
 
 	/************************************************************************/
 	/************************************************************************/

+ 2 - 2
CamelotCore/Source/CmRenderTexture.cpp

@@ -94,10 +94,10 @@ namespace BansheeEngine
 		// Create non-persistent resource handles for the used textures (we only need them because a lot of the code accepts only handles,
 		// Create non-persistent resource handles for the used textures (we only need them because a lot of the code accepts only handles,
 		// since they're non persistent they don't really have any benefit over shared pointers)
 		// since they're non persistent they don't really have any benefit over shared pointers)
 		if(mColorSurface != nullptr)
 		if(mColorSurface != nullptr)
-			mBindableColorTex = gResources().createResourceHandle(mColorSurface->getTexture());
+			mBindableColorTex = gResources()._createResourceHandle(mColorSurface->getTexture());
 
 
 		if(mDepthStencilSurface != nullptr)
 		if(mDepthStencilSurface != nullptr)
-			mBindableDepthStencilTex = gResources().createResourceHandle(mDepthStencilSurface->getTexture());
+			mBindableDepthStencilTex = gResources()._createResourceHandle(mDepthStencilSurface->getTexture());
 	}
 	}
 
 
 	void RenderTexture::throwIfBuffersDontMatch() const
 	void RenderTexture::throwIfBuffersDontMatch() const

+ 1 - 1
CamelotCore/Source/CmResources.cpp

@@ -250,7 +250,7 @@ namespace BansheeEngine
 		return nullptr;
 		return nullptr;
 	}
 	}
 
 
-	HResource Resources::createResourceHandle(const ResourcePtr& obj)
+	HResource Resources::_createResourceHandle(const ResourcePtr& obj)
 	{
 	{
 		String uuid = UUIDGenerator::instance().generateRandom();
 		String uuid = UUIDGenerator::instance().generateRandom();
 		HResource newHandle(obj, uuid);
 		HResource newHandle(obj, uuid);

+ 1 - 1
CamelotCore/Source/CmSamplerState.cpp

@@ -43,7 +43,7 @@ namespace BansheeEngine
 	{
 	{
 		SamplerStatePtr samplerPtr = RenderStateManager::instance().createSamplerState(desc);
 		SamplerStatePtr samplerPtr = RenderStateManager::instance().createSamplerState(desc);
 
 
-		return static_resource_cast<SamplerState>(gResources().createResourceHandle(samplerPtr));
+		return static_resource_cast<SamplerState>(gResources()._createResourceHandle(samplerPtr));
 	}
 	}
 
 
 	/************************************************************************/
 	/************************************************************************/

+ 6 - 13
CamelotCore/Source/CmTexture.cpp

@@ -11,16 +11,9 @@
 namespace BansheeEngine 
 namespace BansheeEngine 
 {
 {
     Texture::Texture()
     Texture::Texture()
-        : 
-            mHeight(32),
-            mWidth(32),
-            mDepth(1),
-            mNumMipmaps(0),
-			mHwGamma(false),
-			mFSAA(0),
-            mTextureType(TEX_TYPE_2D),            
-            mFormat(PF_UNKNOWN),
-            mUsage(TU_DEFAULT)
+        :mHeight(32), mWidth(32), mDepth(1), mNumMipmaps(0),
+		 mHwGamma(false), mFSAA(0), mTextureType(TEX_TYPE_2D), 
+		 mFormat(PF_UNKNOWN), mUsage(TU_DEFAULT)
     {
     {
         
         
     }
     }
@@ -55,7 +48,7 @@ namespace BansheeEngine
         return getNumFaces() * PixelUtil::getMemorySize(mWidth, mHeight, mDepth, mFormat);
         return getNumFaces() * PixelUtil::getMemorySize(mWidth, mHeight, mDepth, mFormat);
 	}
 	}
 
 
-	UINT32 Texture::getNumFaces(void) const
+	UINT32 Texture::getNumFaces() const
 	{
 	{
 		return getTextureType() == TEX_TYPE_CUBE_MAP ? 6 : 1;
 		return getTextureType() == TEX_TYPE_CUBE_MAP ? 6 : 1;
 	}
 	}
@@ -305,7 +298,7 @@ namespace BansheeEngine
 		TexturePtr texturePtr = _createPtr(texType, 
 		TexturePtr texturePtr = _createPtr(texType, 
 			width, height, depth, num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
 			width, height, depth, num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
 
 
-		return static_resource_cast<Texture>(gResources().createResourceHandle(texturePtr));
+		return static_resource_cast<Texture>(gResources()._createResourceHandle(texturePtr));
 	}
 	}
 	
 	
 	HTexture Texture::create(TextureType texType, UINT32 width, UINT32 height, 
 	HTexture Texture::create(TextureType texType, UINT32 width, UINT32 height, 
@@ -314,7 +307,7 @@ namespace BansheeEngine
 		TexturePtr texturePtr = _createPtr(texType, 
 		TexturePtr texturePtr = _createPtr(texType, 
 			width, height, num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
 			width, height, num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
 
 
-		return static_resource_cast<Texture>(gResources().createResourceHandle(texturePtr));
+		return static_resource_cast<Texture>(gResources()._createResourceHandle(texturePtr));
 	}
 	}
 
 
 	TexturePtr Texture::_createPtr(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, 
 	TexturePtr Texture::_createPtr(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, 

+ 3 - 7
CamelotCore/Source/CmTextureManager.cpp

@@ -47,7 +47,7 @@ namespace BansheeEngine
 		return ret;
 		return ret;
     }
     }
 
 
-	TexturePtr TextureManager::createEmpty()
+	TexturePtr TextureManager::_createEmpty()
 	{
 	{
 		TexturePtr texture = createTextureImpl();
 		TexturePtr texture = createTextureImpl();
 		texture->_setThisPtr(texture);
 		texture->_setThisPtr(texture);
@@ -92,16 +92,12 @@ namespace BansheeEngine
 		return newRT;
 		return newRT;
 	}
 	}
 
 
-	MultiRenderTexturePtr TextureManager::createEmptyMultiRenderTexture()
+	MultiRenderTexturePtr TextureManager::createMultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc)
 	{
 	{
 		MultiRenderTexturePtr newRT = createMultiRenderTextureImpl();
 		MultiRenderTexturePtr newRT = createMultiRenderTextureImpl();
 		newRT->_setThisPtr(newRT);
 		newRT->_setThisPtr(newRT);
+		newRT->initialize(desc);
 
 
 		return newRT;
 		return newRT;
 	}
 	}
-
-	bool TextureManager::isFormatSupported(TextureType ttype, PixelFormat format, int usage)
-	{
-		return getNativeFormat(ttype, format, usage) == format;
-	}
 }
 }

+ 1 - 1
CamelotD3D9Renderer/Include/CmD3D9Texture.h

@@ -44,7 +44,7 @@ namespace BansheeEngine {
 		/**
 		/**
 		 * @copydoc Texture::isBindableAsShaderResource
 		 * @copydoc Texture::isBindableAsShaderResource
 		 */
 		 */
-		bool isBindableAsShaderResource() const { return mIsBindableAsShaderResource; }
+		bool _isBindableAsShaderResource() const { return mIsBindableAsShaderResource; }
 
 
 		/// retrieves a pointer to the actual texture
 		/// retrieves a pointer to the actual texture
 		IDirect3DBaseTexture9 *getTexture_internal();		
 		IDirect3DBaseTexture9 *getTexture_internal();		

+ 1 - 1
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -460,7 +460,7 @@ namespace BansheeEngine
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		if(!tex->isBindableAsShaderResource())
+		if(!tex->_isBindableAsShaderResource())
 			CM_EXCEPT(InvalidParametersException, "Texture you have specified cannot be bound to a shader.");
 			CM_EXCEPT(InvalidParametersException, "Texture you have specified cannot be bound to a shader.");
 
 
 		if(gptype != GPT_FRAGMENT_PROGRAM && gptype != GPT_VERTEX_PROGRAM)
 		if(gptype != GPT_FRAGMENT_PROGRAM && gptype != GPT_VERTEX_PROGRAM)