Просмотр исходного кода

More documentation and refactoring

Marko Pintera 11 лет назад
Родитель
Сommit
638ad070a3

+ 192 - 48
CamelotCore/Include/CmCPUProfiler.h

@@ -7,45 +7,89 @@ namespace BansheeEngine
 	class CPUProfilerReport;
 
 	/**
-	 * @brief	Provides various performance measuring methods
+	 * @brief	Provides various performance measuring methods.
 	 * 			
 	 * @note	This class is thread safe. Matching begin*\end* calls
 	 * 			must belong to the same thread though.
 	 */
 	class CM_EXPORT CPUProfiler
 	{
+		/**
+		 * @brief	Timer class responsible for tracking elapsed time.
+		 */
 		class Timer
 		{
 		public:
 			Timer();
 
+			/**
+			 * @brief	Sets the start time for the timer.
+			 */
 			void start();
+
+			/**
+			 * @brief	Stops the timer and calculates the elapsed time
+			 *			from start time to now.
+			 */
 			void stop();
+
+			/**
+			 * @brief	Resets the elapsed time to zero.
+			 */
 			void reset();
 
 			double time;
 		private:
 			double startTime;
 
+			/**
+			 * @brief	Returns time elapsed since CPU was started in millseconds.
+			 */
 			static inline double getCurrentTime();
 		};
 
+		/**
+		 * @brief	Timer class responsible for tracking number of elapsed CPU cycles.
+		 */
 		class TimerPrecise
 		{
 		public:
 			TimerPrecise();
 
+			/**
+			 * @brief	Starts the counter marking the current number of executed
+			 *			CPU cycles since CPU was started.
+			 */
 			void start();
+
+			/**
+			 * @brief	Ends the counter and calculates the number of CPU cycles between
+			 *			now and the start time.
+			 */
 			void stop();
+
+			/**
+			 * @brief	Resets the cycle count to zero.
+			 */
 			void reset();
 
 			UINT64 cycles;
 		private:
 			UINT64 startCycles;
 
+			/**
+			 * @brief	Queries the CPU for the current number of CPU cycles executed since the
+			 *			program was started.
+			 */
 			static inline UINT64 getNumCycles();
 		};
 
+		/**
+		 * @brief	Contains data about a single profiler sample (counting time in milliseconds).
+		 *	
+		 * @note	A sample is created whenever a named profile block is entered. e.g. if you have a function
+		 *			you are profiling, and it gets called 10 times, there will be 10 samples.
+		 */
 		struct ProfileSample
 		{
 			ProfileSample(double _time, UINT64 _numAllocs, UINT64 _numFrees)
@@ -57,6 +101,12 @@ namespace BansheeEngine
 			UINT64 numFrees;
 		};
 
+		/**
+		 * @brief	Contains data about a single precise profiler sample (counting CPU cycles).
+		 *
+		 * @note	A sample is created whenever a named profile block is entered. e.g. if you have a function
+		 *			you are profiling, and it gets called 10 times, there will be 10 samples.
+		 */
 		struct PreciseProfileSample
 		{
 			PreciseProfileSample(UINT64 _cycles, UINT64 _numAllocs, UINT64 _numFrees)
@@ -68,56 +118,101 @@ namespace BansheeEngine
 			UINT64 numFrees;
 		};
 
+		/**
+		 * @brief	Contains basic (time based) profiling data contained in a profiling block.
+		 */
 		struct ProfileData
 		{
+			/**
+			 * @brief	Begins a new sample and records current sample state. Previous sample must
+			 *			not be active.
+			 */
+			void beginSample();
+
+			/**
+			 * @brief	Records current sample state and creates a new sample based on start and end state.
+			 *			Adds the sample to the sample list.
+			 */
+			void endSample();
+
+			/**
+			 * @brief	Removes the last added sample from the sample list and makes it active again. You must
+			 *			call endSample when done as if you called beginSample.
+			 */
+			void resumeLastSample();
+
 			ProfilerVector<ProfileSample> samples;
 			Timer timer;
 
 			UINT64 memAllocs;
 			UINT64 memFrees;
+		};
 
+		/**
+		 * @brief	Contains precise (CPU cycle based) profiling data contained in a profiling block.
+		 */
+		struct PreciseProfileData
+		{
+			/**
+			 * @brief	Begins a new sample and records current sample state. Previous sample must
+			 *			not be active.
+			 */
 			void beginSample();
+
+			/**
+			 * @brief	Records current sample state and creates a new sample based on start and end state.
+			 *			Adds the sample to the sample list.
+			 */
 			void endSample();
+
+			/**
+			 * @brief	Removes the last added sample from the sample list and makes it active again. You must
+			 *			call endSample when done as if you called beginSample.
+			 */
 			void resumeLastSample();
-		};
 
-		struct PreciseProfileData
-		{
 			ProfilerVector<PreciseProfileSample> samples;
 			TimerPrecise timer;
 
 			UINT64 memAllocs;
 			UINT64 memFrees;
-
-			void beginSample();
-			void endSample();
-			void resumeLastSample();
 		};
 
-		struct PreciseProfiledBlock;
-		struct ProfiledBlock;
-
+		/**
+		 * @brief	Contains all sampling information about a single named profiling block.
+		 *			Each block has its own sampling information and optionally child blocks.
+		 */
 		struct ProfiledBlock
 		{
 			ProfiledBlock();
 			~ProfiledBlock();
 
+			/**
+			 * @brief	Attempts to find a child block with the specified name. Returns
+			 *			null if not found.
+			 */
+			ProfiledBlock* findChild(const ProfilerString& name) const;
+
 			ProfilerString name;
 			
 			ProfileData basic;
 			PreciseProfileData precise;
 
 			ProfilerVector<ProfiledBlock*> children;
-
-			ProfiledBlock* findChild(const ProfilerString& name) const;
 		};
 
+		/**
+		 * @brief	CPU sampling type.
+		 */
 		enum class ActiveSamplingType
 		{
-			Basic,
-			Precise
+			Basic, /**< Sample using milliseconds. */
+			Precise /**< Sample using CPU cycles. */
 		};
 
+		/**
+		 * @brief	Contains data about the currently active profiling block.
+		 */
 		struct ActiveBlock
 		{
 			ActiveBlock()
@@ -132,10 +227,41 @@ namespace BansheeEngine
 			ProfiledBlock* block;
 		};
 
+		/**
+		 * @brief	Contains data about an active profiling thread.
+		 */
 		struct ThreadInfo
 		{
 			ThreadInfo();
 
+			/**
+			 * @brief	Starts profiling on the thread. New primary profiling block
+			 *			is created with the given name.
+			 */
+			void begin(const ProfilerString& _name);
+
+			/**
+			 * @brief	Ends profiling on the thread. You should end all samples before calling this,
+			 *			but if you don't they will be terminated automatically.
+			 */
+			void end();
+
+			/**
+			 * @brief	Deletes all internal profiling data and makes the object ready for another
+			 *			iteration. Should be called after end in order to delete any existing data.
+			 */
+			void reset();
+
+			/**
+			 * @brief	Gets the primary profiling block used by the thread.
+			 */
+			ProfiledBlock* getBlock();
+			
+			/**
+			 * @brief	Deletes the provided block.
+			 */
+			void releaseBlock(ProfiledBlock* block);
+
 			static CM_THREADLOCAL ThreadInfo* activeThread;
 			bool isActive;
 
@@ -143,13 +269,6 @@ namespace BansheeEngine
 
 			ProfilerStack<ActiveBlock> activeBlocks;
 			ActiveBlock activeBlock;
-
-			void begin(const ProfilerString& _name);
-			void end();
-			void reset();
-
-			ProfiledBlock* getBlock();
-			void releaseBlock(ProfiledBlock* block);
 		};
 
 	public:
@@ -221,6 +340,13 @@ namespace BansheeEngine
 		 */
 		CPUProfilerReport generateReport();
 
+	private:
+		/**
+		 * @brief	Calculates overhead that the timing and sampling methods themselves introduce
+		 *			so we might get more accurate measurements when creating reports.
+		 */
+		void estimateTimerOverhead();
+
 	private:
 		double mBasicTimerOverhead;
 		UINT64 mPreciseTimerOverhead;
@@ -232,72 +358,90 @@ namespace BansheeEngine
 
 		ProfilerVector<ThreadInfo*> mActiveThreads;
 		CM_MUTEX(mThreadSync);
-
-		void estimateTimerOverhead();
 	};
 
+	/**
+	 * @brief	Profiling entry containing information about a single CPU profiling block
+	 *			containing timing information.
+	 */
 	struct CM_EXPORT CPUProfilerBasicSamplingEntry
 	{
 		struct CM_EXPORT Data
 		{
 			Data();
 
-			String name;
-			UINT32 numCalls;
+			String name; /**< Name of the profiling block. */
+			UINT32 numCalls; /**< Number of times the block was entered. */
 
-			UINT64 memAllocs;
-			UINT64 memFrees;
+			UINT64 memAllocs; /**< Number of memory allocations that happened within the block. */
+			UINT64 memFrees; /**< Number of memory deallocations that happened within the block. */
 
-			double avgTimeMs;
-			double maxTimeMs;
-			double totalTimeMs;
+			double avgTimeMs; /**< Average time it took to execute the block, per call. In milliseconds. */
+			double maxTimeMs; /**< Maximum time of a single call in the block. In milliseconds. */
+			double totalTimeMs; /**< Total time the block took, across all calls. In milliseconds. */
 
-			double avgSelfTimeMs;
-			double totalSelfTimeMs;
+			double avgSelfTimeMs; /**< Average time it took to execute the block, per call. Ignores time used by child blocks. In milliseconds. */
+			double totalSelfTimeMs; /**< Total time the block took, across all calls. Ignores time used by child blocks. In milliseconds. */
 
-			double estimatedSelfOverheadMs;
-			double estimatedOverheadMs;
+			double estimatedSelfOverheadMs; /**< Estimated overhead of profiling methods, only for this exact block. In milliseconds. */
+			double estimatedOverheadMs; /**< Estimated overhead of profiling methods for this block and all children. In milliseconds. */
 
-			float pctOfParent;
+			float pctOfParent; /**< Percent of parent block time this block took to execute. Ranging [0.0, 1.0]. */
 		} data;
 
 		ProfilerVector<CPUProfilerBasicSamplingEntry> childEntries;
 	};
 
+	/**
+	* @brief	Profiling entry containing information about a single CPU profiling block
+	*			containing CPU cycle count based information.
+	*/
 	struct CM_EXPORT CPUProfilerPreciseSamplingEntry
 	{
 		struct CM_EXPORT Data
 		{
 			Data();
 
-			String name;
-			UINT32 numCalls;
+			String name; /**< Name of the profiling block. */
+			UINT32 numCalls; /**< Number of times the block was entered. */
 
-			UINT64 memAllocs;
-			UINT64 memFrees;
+			UINT64 memAllocs; /**< Number of memory allocations that happened within the block. */
+			UINT64 memFrees; /**< Number of memory deallocations that happened within the block. */
 
-			UINT64 avgCycles;
-			UINT64 maxCycles;
-			UINT64 totalCycles;
+			UINT64 avgCycles; /**< Average number of cycles it took to execute the block, per call. */
+			UINT64 maxCycles; /**< Maximum number of cycles of a single call in the block. */
+			UINT64 totalCycles; /**< Total number of cycles across all calls in the block. */
 
-			UINT64 avgSelfCycles;
-			UINT64 totalSelfCycles;
+			UINT64 avgSelfCycles; /**< Average number of cycles it took to execute the block, per call. Ignores cycles used by child blocks. */
+			UINT64 totalSelfCycles; /**< Total number of cycles across all calls in the block. Ignores time used by child blocks. */
 
-			UINT64 estimatedSelfOverhead;
-			UINT64 estimatedOverhead;
+			UINT64 estimatedSelfOverhead; /**< Estimated overhead of profiling methods, only for this exact block. In cycles. */
+			UINT64 estimatedOverhead; /**< Estimated overhead of profiling methods for this block and all children. In cycles. */
 
-			float pctOfParent;
+			float pctOfParent; /**< Percent of parent block cycles used by this block. Ranging [0.0, 1.0]. */
 		} data;
 
 		ProfilerVector<CPUProfilerPreciseSamplingEntry> childEntries;
 	};
 
+	/**
+	 * @brief	CPU profiling report containing all profiling information for a single profiling session.
+	 */
 	class CM_EXPORT CPUProfilerReport
 	{
 	public:
 		CPUProfilerReport();
 
+		/**
+		 * @brief	Returns root entry for the basic (time based) sampling data. Root entry always contains the
+		 *			profiling block associated with the entire thread.
+		 */
 		const CPUProfilerBasicSamplingEntry& getBasicSamplingData() const { return mBasicSamplingRootEntry; }
+
+		/**
+		 * @brief	Returns root entry for the precise (CPU cycle based) sampling data. Root entry always contains the
+		 *			profiling block associated with the entire thread.
+		 */
 		const CPUProfilerPreciseSamplingEntry& getPreciseSamplingData() const { return mPreciseSamplingRootEntry; }
 
 	private:

+ 4 - 2
CamelotCore/Include/CmDeferredCallManager.h

@@ -23,9 +23,11 @@ namespace BansheeEngine
 		void queueDeferredCall(std::function<void()> func);
 
 		/**
-		 * @brief	Executes all the scheduled calls.
+		 * @brief	Executes all the scheduled calls. To be called once per frame.
+		 *
+		 * @note	Internal method.
 		 */
-		void update();
+		void _update();
 
 	private:
 		friend class DeferredCall;

+ 166 - 238
CamelotCore/Include/CmPixelUtil.h

@@ -1,267 +1,195 @@
-/*
------------------------------------------------------------------------------
-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.
------------------------------------------------------------------------------
-*/
-#ifndef _PixelFormat_H__
-#define _PixelFormat_H__
+#pragma once
 
 #include "CmPrerequisites.h"
 #include "CmPixelData.h"
 
-namespace BansheeEngine {
-    /**
-     * Some utility functions for packing and unpacking pixel data
-     */
-    class CM_EXPORT PixelUtil {
+namespace BansheeEngine 
+{
+	/**
+	 * @brief	Utility methods for converting and managing pixel data and formats.
+	 */
+    class CM_EXPORT PixelUtil 
+	{
     public:
-        /** Returns the size in bytes of an element of the given pixel format.
-         @returns
-               The size in bytes of an element. See Remarks.
-         @remarks
-               Passing PF_UNKNOWN will result in returning a size of 0 bytes.
-        */
-        static UINT32 getNumElemBytes( PixelFormat format );
+		/**
+		 * @brief	A list of filtering types to use when scaling images.
+		 */
+		enum Filter
+		{
+			FILTER_NEAREST,
+			FILTER_LINEAR,
+			FILTER_BILINEAR,
+			FILTER_BOX,
+			FILTER_TRIANGLE,
+			FILTER_BICUBIC
+		};
 
-        /** Returns the size in bits of an element of the given pixel format.
-          @returns
-               The size in bits of an element. See Remarks.
-           @remarks
-               Passing PF_UNKNOWN will result in returning a size of 0 bits.
-        */
+		/**
+		 * @brief	Returns the size of a single pixel of the provided pixel format,
+		 *			in bytes.
+		 */
+        static UINT32 getNumElemBytes(PixelFormat format);
+
+		/**
+		 * @brief	Returns the size of a single pixel of the provided pixel format,
+		 *			in bits.
+		 */
         static UINT32 getNumElemBits( PixelFormat format );
 
-		/** Returns the size in memory of a region with the given extents and pixel
-			format with consecutive memory layout.
-			@param width
-				The width of the area
-			@param height
-				The height of the area
-			@param depth
-				The depth of the area
-			@param format
-				The format of the area
-		  	@returns
-		  		The size in bytes
-			@remarks
-				In case that the format is non-compressed, this simply returns
-				width*height*depth*PixelUtil::getNumElemBytes(format). In the compressed
-				case, this does serious magic.
-		*/
+		/**
+		 * @brief	Returns the size of the memory region of the provided size and the pixel format.
+		 */
 		static UINT32 getMemorySize(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format);
 		
-        /** Returns the property flags for this pixel format
-          @returns
-               A bitfield combination of PFF_HASALPHA, PFF_ISCOMPRESSED,
-               PFF_FLOAT, PFF_DEPTH, PFF_NATIVEENDIAN, PFF_LUMINANCE
-          @remarks
-               This replaces the seperate functions for formatHasAlpha, formatIsFloat, ...
-        */
-        static unsigned int getFlags( PixelFormat format );
-
-        /** Shortcut method to determine if the format has an alpha component */
+		/**
+		 * @brief	Returns property flags for this pixel format.
+		 *
+		 * @see		PixelFormatFlags
+		 */
+        static UINT32 getFlags(PixelFormat format);
+
+		/**
+		 * @brief	Checks if the provided pixel format has an alpha channel.
+		 */
         static bool hasAlpha(PixelFormat format);
-        /** Shortcut method to determine if the format is floating point */
+
+		/**
+		 * @brief	Checks is the provided pixel format a floating point format.
+		 */
         static bool isFloatingPoint(PixelFormat format);
-        /** Shortcut method to determine if the format is compressed */
+
+		/**
+		 * @brief	Checks is the provided pixel format compressed.
+		 */
         static bool isCompressed(PixelFormat format);
-        /** Shortcut method to determine if the format is a depth format. */
+
+		/**
+		 * @brief	Checks is the provided pixel format a depth/stencil buffer format.
+		 */
         static bool isDepth(PixelFormat format);
-        /** Shortcut method to determine if the format is in native endian format. */
+
+		/**
+		 * @brief	Checks is the provided format in native endian format.
+		 */
         static bool isNativeEndian(PixelFormat format);
 		
-		/** Return wether a certain image extent is valid for this image format.
-			@param width
-				The width of the area
-			@param height
-				The height of the area
-			@param depth
-				The depth of the area
-			@param format
-				The format of the area
-			@remarks For non-compressed formats, this is always true. For DXT formats,
-			only sizes with a width and height multiple of 4 and depth 1 are allowed.
-		*/
-		static bool isValidExtent(size_t width, size_t height, size_t depth, PixelFormat format);
-
-        /** Gives the number of bits (RGBA) for a format. See remarks.          
-          @remarks      For non-colour formats (dxt, depth) this returns [0,0,0,0].
-        */
+		/**
+		 * @brief	Checks are the provided dimensions valid for the specified pixel format.
+		 *			Some formats (like DXT) require width/height to be multiples of four and some
+		 *			formats dont allow depth larger than 1.
+		 */
+		static bool isValidExtent(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format);
+
+		/**
+		 * @brief	Returns the number of bits per each element in the provided pixel format.
+		 *			This will return all zero for compressed and depth/stencil formats.
+		 */
         static void getBitDepths(PixelFormat format, int rgba[4]);
 
-		/** Gives the masks for the R, G, B and A component
-		  @note			Only valid for native endian formats
-        */
+		/**
+		 * @brief	Returns bit masks that determine in what bit range is each channel stored.
+		 *
+		 * @note	e.g. if your color is stored in an UINT32 and you want to extract the red channel
+		 *			you should AND the color UINT32 with the bit-mask for the red channel and then
+		 *			right shift it by the red channel bit shift amount.
+		 */
         static void getBitMasks(PixelFormat format, UINT32 rgba[4]);
 
-		/** Gives the bit shifts for R, G, B and A component
-		@note			Only valid for native endian formats
-		*/
-		static void getBitShifts(PixelFormat format, unsigned char rgba[4]);
-
-        /** Gets the name of an image format
-        */
+		/**
+		 * @brief	Returns number of bits you need to shift a pixel element in order
+		 *			to move it to the start of the data type.
+		 *
+		 * @note	e.g. if your color is stored in an UINT32 and you want to extract the red channel
+		 *			you should AND the color UINT32 with the bit-mask for the red channel and then
+		 *			right shift it by the red channel bit shift amount.
+		 */
+		static void getBitShifts(PixelFormat format, UINT8 rgba[4]);
+
+		/**
+		 * @brief	Returns the name of the pixel format.
+		 */
         static String getFormatName(PixelFormat srcformat);
 
-        /** Returns wether the format can be packed or unpacked with the packColour()
-        and unpackColour() functions. This is generally not true for compressed and
-        depth formats as they are special. It can only be true for formats with a
-        fixed element size.
-          @returns 
-               true if yes, otherwise false
-        */
+		/**
+		 * @brief	Returns true if the pixel data in the format can be directly accessed and read.
+		 *			This is generally not true for compressed formats.
+		 */
         static bool isAccessible(PixelFormat srcformat);
         
-        /** Returns the component type for a certain pixel format. Returns PCT_BYTE
-            in case there is no clear component type like with compressed formats.
-            This is one of PCT_BYTE, PCT_SHORT, PCT_FLOAT16, PCT_FLOAT32.
-        */
-        static PixelComponentType getComponentType(PixelFormat fmt);
+		/**
+		 * @brief	Returns the type of an individual pixel element in the provided format.
+		 */
+        static PixelComponentType getElementType(PixelFormat format);
         
-        /** Returns the component count for a certain pixel format. Returns 3(no alpha) or 
-            4 (has alpha) in case there is no clear component type like with compressed formats.
-         */
-        static UINT32 getComponentCount(PixelFormat fmt);
-
-        /** Gets the format from given name.
-            @param  name            The string of format name
-            @param  accessibleOnly  If true, non-accessible format will treat as invalid format,
-                                    otherwise, all supported format are valid.
-            @param  caseSensitive   Should be set true if string match should use case sensitivity.
-            @returns                The format match the format name, or PF_UNKNOWN if is invalid name.
-        */
-        static PixelFormat getFormatFromName(const String& name, bool accessibleOnly = false, bool caseSensitive = false);
-
-        /** Gets the BNF expression of the pixel-formats.
-            @note                   The string returned by this function is intented to use as a BNF expression
-                                    to work with Compiler2Pass.
-            @param  accessibleOnly  If true, only accessible pixel format will take into account, otherwise all
-                                    pixel formats list in PixelFormat enumeration will being returned.
-            @returns                A string contains the BNF expression.
-        */
-        static String getBNFExpressionOfPixelFormats(bool accessibleOnly = false);
-
-		/** Returns the maximum number of Mipmaps that can be generated until we reach
-			the mininum format possible. This does not count the base level.
-			@param width
-				The width of the area
-			@param height
-				The height of the area
-			@param depth
-				The depth of the area
-			@param format
-				The format of the area
-			@remarks
-				In case that the format is non-compressed, this simply returns
-				how many times we can divide this texture in 2 until we reach 1x1.
-				For compressed formats, constraints apply on minimum size and alignment
-				so this might differ.
-		*/
+		/**
+		 * @brief	Returns the number of pixel elements in the provided format.
+		 */
+		static UINT32 getNumElements(PixelFormat format);
+
+		/**
+		 * @brief	Returns the maximum number of mip maps that can be generated until we reach
+		 *			the minimum size possible. This does not count the base level.
+		 */
 		static UINT32 getMaxMipmaps(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format);
 
-        /** Pack a colour value to memory
-        	@param colour	The colour
-        	@param pf		Pixelformat in which to write the colour
-        	@param dest		Destination memory location
-        */
-        static void packColour(const Color &colour, const PixelFormat pf,  void* dest);
-        /** Pack a colour value to memory
-        	@param r,g,b,a	The four colour components, range 0x00 to 0xFF
-        	@param pf		Pixelformat in which to write the colour
-        	@param dest		Destination memory location
-        */
-        static void packColour(const UINT8 r, const UINT8 g, const UINT8 b, const UINT8 a, const PixelFormat pf,  void* dest);
-         /** Pack a colour value to memory
-        	@param r,g,b,a	The four colour components, range 0.0f to 1.0f
-        					(an exception to this case exists for floating point pixel
-        					formats, which don't clamp to 0.0f..1.0f)
-        	@param pf		Pixelformat in which to write the colour
-        	@param dest		Destination memory location
-        */
-        static void packColour(const float r, const float g, const float b, const float a, const PixelFormat pf,  void* dest);
-
-        /** Unpack a colour value from memory
-        	@param colour	The colour is returned here
-        	@param pf		Pixelformat in which to read the colour
-        	@param src		Source memory location
-        */
-        static void unpackColour(Color *colour, PixelFormat pf,  const void* src);
-        /** Unpack a colour value from memory
-        	@param r,g,b,a	The colour is returned here (as byte)
-        	@param pf		Pixelformat in which to read the colour
-        	@param src		Source memory location
-        	@remarks 	This function returns the colour components in 8 bit precision,
-        		this will lose precision when coming from PF_A2R10G10B10 or floating
-        		point formats.  
-        */
-        static void unpackColour(UINT8 *r, UINT8 *g, UINT8 *b, UINT8 *a, PixelFormat pf,  const void* src);
-        /** Unpack a colour value from memory
-        	@param r,g,b,a	The colour is returned here (as float)
-        	@param pf		Pixelformat in which to read the colour
-        	@param src		Source memory location
-        */
-        static void unpackColour(float *r, float *g, float *b, float *a, PixelFormat pf,  const void* src); 
+		/**
+		 * @brief	Writes the color to the provided memory location.
+		 */
+        static void packColor(const Color& color, PixelFormat format, void* dest);
+
+		/**
+		 * @brief	Writes the color to the provided memory location. If the destination
+		 *			format is floating point, the byte values will be converted into [0.0, 1.0] range.
+		 */
+		static void packColor(UINT8 r, UINT8 g, UINT8 b, UINT8 a, PixelFormat format, void* dest);
+
+		/**
+		 * @brief	Writes the color to the provided memory location. If the destination format
+		 *			in non-floating point, the float values will be assumed to be in [0.0, 1.0] which
+		 *			will be converted to integer range. ([0, 255] in the case of bytes)
+		 */
+		static void packColor(float r, float g, float b, float a, const PixelFormat format, void* dest);
+
+		/**
+		 * @brief	Reads the color from the provided memory location and stores it 
+		 *			into the provided color object.
+		 */
+		static void unpackColor(Color* color, PixelFormat format, const void* src);
+
+		/**
+		 * @brief	Reads the color from the provided memory location and stores it 
+		 *			into the provided color elements, as bytes clamped to [0, 255] range.
+		 */
+		static void unpackColor(UINT8* r, UINT8* g, UINT8* b, UINT8* a, PixelFormat format, const void* src);
+
+		/**
+		 * @brief	Reads the color from the provided memory location and stores it 
+		 *			into the provided color elements. If the format is not natively floating
+		 *			point a conversion is done in such a way that returned values range [0.0, 1.0].
+		 */
+        static void unpackColor(float* r, float* g, float* b, float* a, PixelFormat format, const void* src); 
         
-      	/** Convert pixels from one format to another. No dithering or filtering is being done. Converting
-          	from RGB to luminance takes the R channel. 
-		 	@param	src			PixelBox containing the source pixels, pitches and format
-		 	@param	dst			PixelBox containing the destination pixels, pitches and format
-		 	@remarks The source and destination boxes must have the same
-         	dimensions. In case the source and destination format match, a plain copy is done.
-        */
-        static void bulkPixelConversion(const PixelData &src, const PixelData &dst);
-
-		enum Filter
-		{
-			FILTER_NEAREST,
-			FILTER_LINEAR,
-			FILTER_BILINEAR,
-			FILTER_BOX,
-			FILTER_TRIANGLE,
-			FILTER_BICUBIC
-		};
-
-		/** Scale a 1D, 2D or 3D image volume. 
-			@param 	src			PixelBox containing the source pointer, dimensions and format
-			@param 	dst			PixelBox containing the destination pointer, dimensions and format
-			@param 	filter		Which filter to use
-			@remarks 	This function can do pixel format conversion in the process.
-			@note	dst and src can point to the same PixelBox object without any problem
-		*/
-		static void scale(const PixelData &src, const PixelData &dst, Filter filter = FILTER_BILINEAR);
-
-		/** Does gamma adjustment.
-            @note
-                Basic algo taken from Titan Engine, copyright (c) 2000 Ignacio 
-                Castano Iguado
-        */
-        static void applyGamma(UINT8 *buffer, float gamma, size_t size, UINT8 bpp);
+		/**
+		 * @brief	Converts pixels from one format to another. Provided pixel data objects
+		 *			must have previously allocated buffers of adequate size and their sizes must match.
+		 */
+        static void bulkPixelConversion(const PixelData& src, const PixelData& dst);
+
+		/**
+		 * @brief	Scales pixel data in the source buffer and stores the scaled data in the destination buffer.
+		 *			Provided pixel data objects must have previously allocated buffers of adequate size. You may
+		 *			also provided a filtering method to use when scaling.
+		 */
+		static void scale(const PixelData& src, const PixelData& dst, Filter filter = FILTER_BILINEAR);
+
+		/**
+		 * @brief	Applies gamma correction to the pixels in the provided buffer.
+		 *
+		 * @param	buffer	Pointer to the buffer containing the pixels.
+		 * @param	gamma	Gamma value to apply.
+		 * @param	size	Size of the buffer in bytes.
+		 * @param	bpp		Number of bits per pixel of the pixels in the buffer.
+		 */
+        static void applyGamma(UINT8* buffer, float gamma, UINT32 size, UINT8 bpp);
     };
-	/** @} */
-	/** @} */
-
-}
-
-#endif
+}

+ 25 - 8
CamelotCore/Include/CmProfiler.h

@@ -6,22 +6,34 @@
 
 namespace BansheeEngine
 {
-#define PROFILE_CALL(call, name) \
-	BansheeEngine::gProfiler().beginSample(##name##); \
-	call; \
+/**
+ * @brief	Shortcut for profiling a single function call.
+ */
+#define PROFILE_CALL(call, name)						\
+	BansheeEngine::gProfiler().beginSample(##name##);	\
+	call;												\
 	BansheeEngine::gProfiler().endSample(##name##);
 
+	/**
+	 * @brief	Contains data about a profiling session.
+	 */
 	struct ProfilerReport
 	{
 		CPUProfilerReport cpuReport;
 	};
 
+	/**
+	 * @brief	Type of thread used by the profiler.
+	 */
 	enum class ProfiledThread
 	{
 		Sim,
 		Core
 	};
 
+	/**
+	 * @brief	Provides performance measuring methods for the CPU.
+	 */
 	class CM_EXPORT Profiler : public Module<Profiler>
 	{
 	public:
@@ -89,16 +101,18 @@ namespace BansheeEngine
 		}
 
 		/**
-		 * @brief	Called every frame. Internal method.
+		 * @brief	Called every frame.
+		 *
+		 * @note	Internal method.
 		 */
-		void update();
+		void _update();
 
 		/**
-		 * @brief	Called every frame from the core thread. Internal method.
+		 * @brief	Called every frame from the core thread.
 		 * 			
-		 * @note	Only call from core thread.
+		 * @note	Internal method. Only call from core thread.
 		 */
-		void updateCore();
+		void _updateCore();
 
 		/**
 		 * @brief	Returns a profiler report for the specified frame, for the specified thread.
@@ -125,5 +139,8 @@ namespace BansheeEngine
 		CM_MUTEX(mSync);
 	};
 
+	/**
+	 * @brief	Quick way to access the profiler.
+	 */
 	CM_EXPORT Profiler& gProfiler();
 }

+ 3 - 3
CamelotCore/Source/CmApplication.cpp

@@ -106,7 +106,7 @@ namespace BansheeEngine
 
 			gCoreThread().update();
 			Platform::_update();
-			DeferredCallManager::instance().update();
+			DeferredCallManager::instance()._update();
 			RenderWindowManager::instance()._update();
 			gInput()._update();
 
@@ -145,7 +145,7 @@ namespace BansheeEngine
 			gTime().update();
 
 			gProfiler().endThread();
-			gProfiler().update();
+			gProfiler()._update();
 		}
 	}
 
@@ -171,7 +171,7 @@ namespace BansheeEngine
 	void Application::endCoreProfiling()
 	{
 		gProfiler().endThread();
-		gProfiler().updateCore();
+		gProfiler()._updateCore();
 	}
 
 	void Application::shutDown()

+ 1 - 1
CamelotCore/Source/CmDeferredCallManager.cpp

@@ -12,7 +12,7 @@ namespace BansheeEngine
 		mCallbacks.push_back(func);
 	}
 
-	void DeferredCallManager::update()
+	void DeferredCallManager::_update()
 	{
 		while(!mCallbacks.empty())
 		{

+ 2 - 2
CamelotCore/Source/CmPixelData.cpp

@@ -70,7 +70,7 @@ namespace BansheeEngine
 
 		UINT32 pixelSize = PixelUtil::getNumElemBytes(mFormat);
 		UINT32 pixelOffset = pixelSize * (z * mSlicePitch + y * mRowPitch + x);
-		PixelUtil::unpackColour(&cv, mFormat, (unsigned char *)getData() + pixelOffset);
+		PixelUtil::unpackColor(&cv, mFormat, (unsigned char *)getData() + pixelOffset);
 
 		return cv;
 	}
@@ -79,7 +79,7 @@ namespace BansheeEngine
 	{
 		UINT32 pixelSize = PixelUtil::getNumElemBytes(mFormat);
 		UINT32 pixelOffset = pixelSize * (z * mSlicePitch + y * mRowPitch + x);
-		PixelUtil::packColour(cv, mFormat, (unsigned char *)getData() + pixelOffset);
+		PixelUtil::packColor(cv, mFormat, (unsigned char *)getData() + pixelOffset);
 	}
 
 	UINT32 PixelData::getInternalBufferSize()

+ 172 - 225
CamelotCore/Source/CmPixelUtil.cpp

@@ -3,9 +3,8 @@
 #include "CmColor.h"
 #include "CmException.h"
 
-
-namespace BansheeEngine {
-
+namespace BansheeEngine 
+{
 	//-----------------------------------------------------------------------
     /**
     * Resamplers
@@ -131,7 +130,7 @@ namespace BansheeEngine {
 							x1y2z2 * ((1.0f - sxf)*        syf *        szf ) +
 							x2y2z2 * (        sxf *        syf *        szf );
 
-						PixelUtil::packColour(accum, dst.getFormat(), pdst);
+						PixelUtil::packColor(accum, dst.getFormat(), pdst);
 
 						pdst += dstelemsize;
 					}
@@ -313,37 +312,27 @@ namespace BansheeEngine {
 		}
 	};
 
-    //-----------------------------------------------------------------------
-    /**
-    * A record that describes a pixel format in detail.
-    */
-    struct PixelFormatDescription {
-        /* Name of the format, as in the enum */
-        const char *name;
-        /* Number of bytes one element (colour value) takes. */
-        unsigned char elemBytes;
-        /* Pixel format flags, see enum PixelFormatFlags for the bit field
-        * definitions
-        */
-        UINT32 flags;
-        /** Component type
-         */
-        PixelComponentType componentType;
-        /** Component count
-         */
-        unsigned char componentCount;
-        /* Number of bits for red(or luminance), green, blue, alpha
-        */
-        unsigned char rbits,gbits,bbits,abits; /*, ibits, dbits, ... */
-
-        /* Masks and shifts as used by packers/unpackers */
-        UINT32 rmask, gmask, bmask, amask;
-        unsigned char rshift, gshift, bshift, ashift;
+	/**
+	 * @brief	Data describing a pixel format.
+	 */
+    struct PixelFormatDescription 
+	{
+		const char* name; /**< Name of the format. */
+		UINT8 elemBytes; /**< Number of bytes one element (color value) uses. */
+		UINT32 flags; /**< PixelFormatFlags set by the pixel format. */
+        PixelComponentType componentType; /**< Data type of a single element of the format. */
+		UINT8 componentCount; /**< Number of elements in the format. */
+
+		UINT8 rbits, gbits, bbits, abits; /**< Number of bits per element in the format. */
+
+        UINT32 rmask, gmask, bmask, amask; /**< Masks used by packers/unpackers. */
+		UINT8 rshift, gshift, bshift, ashift; /**< Shifts used by packers/unpackers. */
     };
-    //-----------------------------------------------------------------------
-    /** Pixel format database */
+
+	/**
+	 * @brief	A list of all available pixel formats.
+	 */
     PixelFormatDescription _pixelFormats[PF_COUNT] = {
-	//-----------------------------------------------------------------------
         {"PF_UNKNOWN",
         /* Bytes per element */
         0,
@@ -746,11 +735,7 @@ namespace BansheeEngine {
 		0, 0, 0, 0, 0, 0, 0, 0
 		}, 
     };
-    //-----------------------------------------------------------------------
-    /**
-    * Directly get the description record for provided pixel format. For debug builds,
-    * this checks the bounds of fmt with an assertion.
-    */
+
     static inline const PixelFormatDescription &getDescriptionFor(const PixelFormat fmt)
     {
         const int ord = (int)fmt;
@@ -758,12 +743,12 @@ namespace BansheeEngine {
 
         return _pixelFormats[ord];
     }
-    //-----------------------------------------------------------------------
-    UINT32 PixelUtil::getNumElemBytes( PixelFormat format )
+
+    UINT32 PixelUtil::getNumElemBytes(PixelFormat format)
     {
         return getDescriptionFor(format).elemBytes;
     }
-	//-----------------------------------------------------------------------
+
 	UINT32 PixelUtil::getMemorySize(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format)
 	{
 		if(isCompressed(format))
@@ -789,43 +774,43 @@ namespace BansheeEngine {
 			return width*height*depth*getNumElemBytes(format);
 		}
 	}
-    //-----------------------------------------------------------------------
-    UINT32 PixelUtil::getNumElemBits( PixelFormat format )
+
+    UINT32 PixelUtil::getNumElemBits(PixelFormat format)
     {
         return getDescriptionFor(format).elemBytes * 8;
     }
-    //-----------------------------------------------------------------------
-    unsigned int PixelUtil::getFlags( PixelFormat format )
+
+    UINT32 PixelUtil::getFlags(PixelFormat format)
     {
         return getDescriptionFor(format).flags;
     }
-    //-----------------------------------------------------------------------
+
     bool PixelUtil::hasAlpha(PixelFormat format)
     {
         return (PixelUtil::getFlags(format) & PFF_HASALPHA) > 0;
     }
-    //-----------------------------------------------------------------------
+
     bool PixelUtil::isFloatingPoint(PixelFormat format)
     {
         return (PixelUtil::getFlags(format) & PFF_FLOAT) > 0;
     }
-    //-----------------------------------------------------------------------
+
     bool PixelUtil::isCompressed(PixelFormat format)
     {
         return (PixelUtil::getFlags(format) & PFF_COMPRESSED) > 0;
     }
-    //-----------------------------------------------------------------------
+
     bool PixelUtil::isDepth(PixelFormat format)
     {
         return (PixelUtil::getFlags(format) & PFF_DEPTH) > 0;
     }
-    //-----------------------------------------------------------------------
+
     bool PixelUtil::isNativeEndian(PixelFormat format)
     {
         return (PixelUtil::getFlags(format) & PFF_NATIVEENDIAN) > 0;
     }
-    //-----------------------------------------------------------------------
-	bool PixelUtil::isValidExtent(size_t width, size_t height, size_t depth, PixelFormat format)
+
+	bool PixelUtil::isValidExtent(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format)
 	{
 		if(isCompressed(format))
 		{
@@ -836,7 +821,7 @@ namespace BansheeEngine {
 				case PF_DXT3:
 				case PF_DXT4:
 				case PF_DXT5:
-					return ((width&3)==0 && (height&3)==0 && depth==1);
+					return ((width & 3) == 0 && (height & 3) == 0 && depth == 1);
 				default:
 					return true;
 			}
@@ -846,107 +831,58 @@ namespace BansheeEngine {
 			return true;
 		}
 	}
-	//-----------------------------------------------------------------------
+
     void PixelUtil::getBitDepths(PixelFormat format, int rgba[4])
     {
-        const PixelFormatDescription &des = getDescriptionFor(format);
+        const PixelFormatDescription& des = getDescriptionFor(format);
         rgba[0] = des.rbits;
         rgba[1] = des.gbits;
         rgba[2] = des.bbits;
         rgba[3] = des.abits;
     }
-	//-----------------------------------------------------------------------
+
 	void PixelUtil::getBitMasks(PixelFormat format, UINT32 rgba[4])
     {
-        const PixelFormatDescription &des = getDescriptionFor(format);
+        const PixelFormatDescription& des = getDescriptionFor(format);
         rgba[0] = des.rmask;
         rgba[1] = des.gmask;
         rgba[2] = des.bmask;
         rgba[3] = des.amask;
     }
-	//---------------------------------------------------------------------
-	void PixelUtil::getBitShifts(PixelFormat format, unsigned char rgba[4])
+
+	void PixelUtil::getBitShifts(PixelFormat format, UINT8 rgba[4])
 	{
-		const PixelFormatDescription &des = getDescriptionFor(format);
+		const PixelFormatDescription& des = getDescriptionFor(format);
 		rgba[0] = des.rshift;
 		rgba[1] = des.gshift;
 		rgba[2] = des.bshift;
 		rgba[3] = des.ashift;
 	}
-    //-----------------------------------------------------------------------
+
     String PixelUtil::getFormatName(PixelFormat srcformat)
     {
         return getDescriptionFor(srcformat).name;
     }
-    //-----------------------------------------------------------------------
+
     bool PixelUtil::isAccessible(PixelFormat srcformat)
     {
         if (srcformat == PF_UNKNOWN)
             return false;
-        unsigned int flags = getFlags(srcformat);
+
+        UINT32 flags = getFlags(srcformat);
         return !((flags & PFF_COMPRESSED) || (flags & PFF_DEPTH));
     }
-    //-----------------------------------------------------------------------
-    PixelComponentType PixelUtil::getComponentType(PixelFormat fmt)
+
+    PixelComponentType PixelUtil::getElementType(PixelFormat format)
     {
-        const PixelFormatDescription &des = getDescriptionFor(fmt);
+		const PixelFormatDescription& des = getDescriptionFor(format);
         return des.componentType;
     }
-    //-----------------------------------------------------------------------
-    UINT32 PixelUtil::getComponentCount(PixelFormat fmt)
-    {
-        const PixelFormatDescription &des = getDescriptionFor(fmt);
-        return des.componentCount;
-    }
-    //-----------------------------------------------------------------------
-    PixelFormat PixelUtil::getFormatFromName(const String& name, bool accessibleOnly, bool caseSensitive)
-    {
-        String tmp = name;
-        if (!caseSensitive)
-        {
-            // We are stored upper-case format names.
-            StringUtil::toUpperCase(tmp);
-        }
 
-        for (int i = 0; i < PF_COUNT; ++i)
-        {
-            PixelFormat pf = static_cast<PixelFormat>(i);
-            if (!accessibleOnly || isAccessible(pf))
-            {
-                if (tmp == getFormatName(pf))
-                    return pf;
-            }
-        }
-        return PF_UNKNOWN;
-    }
-    //-----------------------------------------------------------------------
-    String PixelUtil::getBNFExpressionOfPixelFormats(bool accessibleOnly)
+	UINT32 PixelUtil::getNumElements(PixelFormat format)
     {
-        // Collect format names sorted by length, it's required by BNF compiler
-        // that similar tokens need longer ones comes first.
-        typedef MultiMap<String::size_type, String> FormatNameMap;
-        FormatNameMap formatNames;
-        for (size_t i = 0; i < PF_COUNT; ++i)
-        {
-            PixelFormat pf = static_cast<PixelFormat>(i);
-            if (!accessibleOnly || isAccessible(pf))
-            {
-                String formatName = getFormatName(pf);
-                formatNames.insert(std::make_pair(formatName.length(), formatName));
-            }
-        }
-
-        // Populate the BNF expression in reverse order
-        String result;
-        // Note: Stupid M$ VC7.1 can't dealing operator!= with FormatNameMap::const_reverse_iterator.
-        for (FormatNameMap::reverse_iterator j = formatNames.rbegin(); j != formatNames.rend(); ++j)
-        {
-            if (!result.empty())
-                result += " | ";
-            result += "'" + j->second + "'";
-        }
-
-        return result;
+		const PixelFormatDescription& des = getDescriptionFor(format);
+        return des.componentCount;
     }
 
 	UINT32 PixelUtil::getMaxMipmaps(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format)
@@ -958,60 +894,59 @@ namespace BansheeEngine {
                 if(width>1)		width = width/2;
                 if(height>1)	height = height/2;
                 if(depth>1)		depth = depth/2;
-                /*
-                NOT needed, compressed formats will have mipmaps up to 1x1
-                if(PixelUtil::isValidExtent(width, height, depth, format))
-                    count ++;
-                else
-                    break;
-                */
                     
                 count ++;
             } while(!(width == 1 && height == 1 && depth == 1));
-        }		
+        }
+
 		return count;
 	}
-    //-----------------------------------------------------------------------
-    /*************************************************************************
-    * Pixel packing/unpacking utilities
-    */
-    void PixelUtil::packColour(const Color &colour, const PixelFormat pf,  void* dest)
+
+    void PixelUtil::packColor(const Color& color, PixelFormat format, void* dest)
     {
-        packColour(colour.r, colour.g, colour.b, colour.a, pf, dest);
+        packColor(color.r, color.g, color.b, color.a, format, dest);
     }
-    //-----------------------------------------------------------------------
-    void PixelUtil::packColour(const UINT8 r, const UINT8 g, const UINT8 b, const UINT8 a, const PixelFormat pf,  void* dest)
+
+    void PixelUtil::packColor(UINT8 r, UINT8 g, UINT8 b, UINT8 a, PixelFormat format,  void* dest)
     {
-        const PixelFormatDescription &des = getDescriptionFor(pf);
-        if(des.flags & PFF_NATIVEENDIAN) {
+        const PixelFormatDescription &des = getDescriptionFor(format);
+
+        if(des.flags & PFF_NATIVEENDIAN) 
+		{
             // Shortcut for integer formats packing
-            unsigned int value = ((Bitwise::fixedToFixed(r, 8, des.rbits)<<des.rshift) & des.rmask) |
+            UINT32 value = ((Bitwise::fixedToFixed(r, 8, des.rbits)<<des.rshift) & des.rmask) |
                 ((Bitwise::fixedToFixed(g, 8, des.gbits)<<des.gshift) & des.gmask) |
                 ((Bitwise::fixedToFixed(b, 8, des.bbits)<<des.bshift) & des.bmask) |
                 ((Bitwise::fixedToFixed(a, 8, des.abits)<<des.ashift) & des.amask);
+
             // And write to memory
             Bitwise::intWrite(dest, des.elemBytes, value);
-        } else {
+        } 
+		else 
+		{
             // Convert to float
-            packColour((float)r/255.0f,(float)g/255.0f,(float)b/255.0f,(float)a/255.0f, pf, dest);
+            packColor((float)r/255.0f,(float)g/255.0f,(float)b/255.0f,(float)a/255.0f, format, dest);
         }
     }
-    //-----------------------------------------------------------------------
-    void PixelUtil::packColour(const float r, const float g, const float b, const float a, const PixelFormat pf,  void* dest)
+
+    void PixelUtil::packColor(float r, float g, float b, float a, const PixelFormat format, void* dest)
     {
-        // Catch-it-all here
-        const PixelFormatDescription &des = getDescriptionFor(pf);
-        if(des.flags & PFF_NATIVEENDIAN) {
+        const PixelFormatDescription& des = getDescriptionFor(format);
+
+        if(des.flags & PFF_NATIVEENDIAN) 
+		{
             // Do the packing
-            //std::cerr << dest << " " << r << " " << g <<  " " << b << " " << a << std::endl;
             const unsigned int value = ((Bitwise::floatToFixed(r, des.rbits)<<des.rshift) & des.rmask) |
                 ((Bitwise::floatToFixed(g, des.gbits)<<des.gshift) & des.gmask) |
                 ((Bitwise::floatToFixed(b, des.bbits)<<des.bshift) & des.bmask) |
                 ((Bitwise::floatToFixed(a, des.abits)<<des.ashift) & des.amask);
+
             // And write to memory
             Bitwise::intWrite(dest, des.elemBytes, value);
-        } else {
-            switch(pf)
+        }
+		else 
+		{
+            switch(format)
             {
             case PF_FLOAT32_R:
                 ((float*)dest)[0] = r;
@@ -1057,25 +992,24 @@ namespace BansheeEngine {
 				((UINT8*)dest)[0] = (UINT8)Bitwise::floatToFixed(r, 8);
 				break;
             default:
-                // Not yet supported
-                CM_EXCEPT(NotImplementedException,
-                    "pack to "+getFormatName(pf)+" not implemented");
+                CM_EXCEPT(NotImplementedException, "Pack to " + getFormatName(format) + " not implemented");
                 break;
             }
         }
     }
-    //-----------------------------------------------------------------------
-    void PixelUtil::unpackColour(Color *colour, PixelFormat pf,  const void* src)
+    void PixelUtil::unpackColor(Color* color, PixelFormat format, const void* src)
     {
-        unpackColour(&colour->r, &colour->g, &colour->b, &colour->a, pf, src);
+		unpackColor(&color->r, &color->g, &color->b, &color->a, format, src);
     }
-    //-----------------------------------------------------------------------
-    void PixelUtil::unpackColour(UINT8 *r, UINT8 *g, UINT8 *b, UINT8 *a, PixelFormat pf,  const void* src)
+
+    void PixelUtil::unpackColor(UINT8* r, UINT8* g, UINT8* b, UINT8* a, PixelFormat format, const void* src)
     {
-        const PixelFormatDescription &des = getDescriptionFor(pf);
-        if(des.flags & PFF_NATIVEENDIAN) {
+        const PixelFormatDescription &des = getDescriptionFor(format);
+
+        if(des.flags & PFF_NATIVEENDIAN) 
+		{
             // Shortcut for integer formats unpacking
-            const unsigned int value = Bitwise::intRead(src, des.elemBytes);
+            const UINT32 value = Bitwise::intRead(src, des.elemBytes);
 
             *r = (UINT8)Bitwise::fixedToFixed((value & des.rmask)>>des.rshift, des.rbits, 8);
             *g = (UINT8)Bitwise::fixedToFixed((value & des.gmask)>>des.gshift, des.gbits, 8);
@@ -1089,22 +1023,26 @@ namespace BansheeEngine {
             {
                 *a = 255; // No alpha, default a component to full
             }
-        } else {
+        } 
+		else 
+		{
             // Do the operation with the more generic floating point
             float rr, gg, bb, aa;
-            unpackColour(&rr,&gg,&bb,&aa, pf, src);
+            unpackColor(&rr,&gg,&bb,&aa, format, src);
+
             *r = (UINT8)Bitwise::floatToFixed(rr, 8);
             *g = (UINT8)Bitwise::floatToFixed(gg, 8);
             *b = (UINT8)Bitwise::floatToFixed(bb, 8);
             *a = (UINT8)Bitwise::floatToFixed(aa, 8);
         }
     }
-    //-----------------------------------------------------------------------
-    void PixelUtil::unpackColour(float *r, float *g, float *b, float *a,
-        PixelFormat pf,  const void* src)
+
+    void PixelUtil::unpackColor(float* r, float* g, float* b, float* a, PixelFormat format, const void* src)
     {
-        const PixelFormatDescription &des = getDescriptionFor(pf);
-        if(des.flags & PFF_NATIVEENDIAN) {
+        const PixelFormatDescription &des = getDescriptionFor(format);
+
+        if(des.flags & PFF_NATIVEENDIAN) 
+		{
             // Shortcut for integer formats unpacking
             const unsigned int value = Bitwise::intRead(src, des.elemBytes);
 
@@ -1120,8 +1058,10 @@ namespace BansheeEngine {
             {
                 *a = 1.0f; // No alpha, default a component to full
             }
-        } else {
-            switch(pf)
+        } 
+		else 
+		{
+            switch(format)
             {
             case PF_FLOAT32_R:
                 *r = *g = *b = ((float*)src)[0];
@@ -1178,14 +1118,12 @@ namespace BansheeEngine {
 				*a = 1.0f;
 				break;
             default:
-                // Not yet supported
-                CM_EXCEPT(NotImplementedException,
-                    "unpack from "+getFormatName(pf)+" not implemented");
+                CM_EXCEPT(NotImplementedException, "Unpack from " + getFormatName(format) + " not implemented");
                 break;
             }
         }
     }
-    //-----------------------------------------------------------------------
+
     void PixelUtil::bulkPixelConversion(const PixelData &src, const PixelData &dst)
     {
         assert(src.getWidth() == dst.getWidth() &&
@@ -1207,7 +1145,8 @@ namespace BansheeEngine {
 		}
 
         // The easy case
-        if(src.getFormat() == dst.getFormat()) {
+        if(src.getFormat() == dst.getFormat()) 
+		{
             // Everything consecutive?
             if(src.isConsecutive() && dst.isConsecutive())
             {
@@ -1215,51 +1154,54 @@ namespace BansheeEngine {
                 return;
             }
 
-            const size_t srcPixelSize = PixelUtil::getNumElemBytes(src.getFormat());
-            const size_t dstPixelSize = PixelUtil::getNumElemBytes(dst.getFormat());
+			const UINT32 srcPixelSize = PixelUtil::getNumElemBytes(src.getFormat());
+			const UINT32 dstPixelSize = PixelUtil::getNumElemBytes(dst.getFormat());
             UINT8 *srcptr = static_cast<UINT8*>(src.getData())
                 + (src.getLeft() + src.getTop() * src.getRowPitch() + src.getFront() * src.getSlicePitch()) * srcPixelSize;
             UINT8 *dstptr = static_cast<UINT8*>(dst.getData())
 				+ (dst.getLeft() + dst.getTop() * dst.getRowPitch() + dst.getFront() * dst.getSlicePitch()) * dstPixelSize;
 
             // Calculate pitches+skips in bytes
-            const size_t srcRowPitchBytes = src.getRowPitch()*srcPixelSize;
-            //const size_t srcRowSkipBytes = src.getRowSkip()*srcPixelSize;
-            const size_t srcSliceSkipBytes = src.getSliceSkip()*srcPixelSize;
+			const UINT32 srcRowPitchBytes = src.getRowPitch()*srcPixelSize;
+			const UINT32 srcSliceSkipBytes = src.getSliceSkip()*srcPixelSize;
 
-            const size_t dstRowPitchBytes = dst.getRowPitch()*dstPixelSize;
-            //const size_t dstRowSkipBytes = dst.getRowSkip()*dstPixelSize;
-            const size_t dstSliceSkipBytes = dst.getSliceSkip()*dstPixelSize;
+			const UINT32 dstRowPitchBytes = dst.getRowPitch()*dstPixelSize;
+			const UINT32 dstSliceSkipBytes = dst.getSliceSkip()*dstPixelSize;
 
             // Otherwise, copy per row
-            const size_t rowSize = src.getWidth()*srcPixelSize;
-            for(size_t z=src.getFront(); z<src.getBack(); z++)
+			const UINT32 rowSize = src.getWidth()*srcPixelSize;
+			for (UINT32 z = src.getFront(); z < src.getBack(); z++)
             {
-                for(size_t y=src.getTop(); y<src.getBottom(); y++)
+                for(UINT32 y = src.getTop(); y < src.getBottom(); y++)
                 {
 					memcpy(dstptr, srcptr, rowSize);
+
                     srcptr += srcRowPitchBytes;
                     dstptr += dstRowPitchBytes;
                 }
+
                 srcptr += srcSliceSkipBytes;
                 dstptr += dstSliceSkipBytes;
             }
+
             return;
         }
+
 		// Converting to PF_X8R8G8B8 is exactly the same as converting to
 		// PF_A8R8G8B8. (same with PF_X8B8G8R8 and PF_A8B8G8R8)
 		if(dst.getFormat() == PF_X8R8G8B8 || dst.getFormat() == PF_X8B8G8R8)
 		{
 			// Do the same conversion, with PF_A8R8G8B8, which has a lot of
 			// optimized conversions
-			PixelFormat tempFormat = dst.getFormat()==PF_X8R8G8B8?PF_A8R8G8B8:PF_A8B8G8R8;
+			PixelFormat tempFormat = dst.getFormat() == PF_X8R8G8B8?PF_A8R8G8B8:PF_A8B8G8R8;
 			PixelData tempdst(dst.getWidth(), dst.getHeight(), dst.getDepth(), tempFormat);
 			bulkPixelConversion(src, tempdst);
 			return;
 		}
+
 		// Converting from PF_X8R8G8B8 is exactly the same as converting from
 		// PF_A8R8G8B8, given that the destination format does not have alpha.
-		if((src.getFormat() == PF_X8R8G8B8||src.getFormat() == PF_X8B8G8R8) && !hasAlpha(dst.getFormat()))
+		if((src.getFormat() == PF_X8R8G8B8 || src.getFormat() == PF_X8B8G8R8) && !hasAlpha(dst.getFormat()))
 		{
 			// Do the same conversion, with PF_A8R8G8B8, which has a lot of
 			// optimized conversions
@@ -1270,44 +1212,44 @@ namespace BansheeEngine {
 			return;
 		}
 
-        const size_t srcPixelSize = PixelUtil::getNumElemBytes(src.getFormat());
-        const size_t dstPixelSize = PixelUtil::getNumElemBytes(dst.getFormat());
+		const UINT32 srcPixelSize = PixelUtil::getNumElemBytes(src.getFormat());
+		const UINT32 dstPixelSize = PixelUtil::getNumElemBytes(dst.getFormat());
         UINT8 *srcptr = static_cast<UINT8*>(src.getData())
             + (src.getLeft() + src.getTop() * src.getRowPitch() + src.getFront() * src.getSlicePitch()) * srcPixelSize;
         UINT8 *dstptr = static_cast<UINT8*>(dst.getData())
             + (dst.getLeft() + dst.getTop() * dst.getRowPitch() + dst.getFront() * dst.getSlicePitch()) * dstPixelSize;
 		
-		// Old way, not taking into account box dimensions
-		//UINT8 *srcptr = static_cast<UINT8*>(src.data), *dstptr = static_cast<UINT8*>(dst.data);
-
         // Calculate pitches+skips in bytes
-        const size_t srcRowSkipBytes = src.getRowSkip()*srcPixelSize;
-        const size_t srcSliceSkipBytes = src.getSliceSkip()*srcPixelSize;
-        const size_t dstRowSkipBytes = dst.getRowSkip()*dstPixelSize;
-        const size_t dstSliceSkipBytes = dst.getSliceSkip()*dstPixelSize;
+		const UINT32 srcRowSkipBytes = src.getRowSkip()*srcPixelSize;
+		const UINT32 srcSliceSkipBytes = src.getSliceSkip()*srcPixelSize;
+		const UINT32 dstRowSkipBytes = dst.getRowSkip()*dstPixelSize;
+		const UINT32 dstSliceSkipBytes = dst.getSliceSkip()*dstPixelSize;
 
         // The brute force fallback
         float r,g,b,a;
-        for(size_t z=src.getFront(); z<src.getBack(); z++)
-        {
-            for(size_t y=src.getTop(); y<src.getBottom(); y++)
+		for (UINT32 z = src.getFront(); z<src.getBack(); z++)
+		{
+			for (UINT32 y = src.getTop(); y < src.getBottom(); y++)
             {
-                for(size_t x=src.getLeft(); x<src.getRight(); x++)
+				for (UINT32 x = src.getLeft(); x<src.getRight(); x++)
                 {
-                    unpackColour(&r, &g, &b, &a, src.getFormat(), srcptr);
-                    packColour(r, g, b, a, dst.getFormat(), dstptr);
+                    unpackColor(&r, &g, &b, &a, src.getFormat(), srcptr);
+                    packColor(r, g, b, a, dst.getFormat(), dstptr);
+
                     srcptr += srcPixelSize;
                     dstptr += dstPixelSize;
                 }
+
                 srcptr += srcRowSkipBytes;
                 dstptr += dstRowSkipBytes;
             }
+
             srcptr += srcSliceSkipBytes;
             dstptr += dstSliceSkipBytes;
         }
     }
 
-	void PixelUtil::scale(const PixelData &src, const PixelData &scaled, Filter filter)
+	void PixelUtil::scale(const PixelData& src, const PixelData& scaled, Filter filter)
 	{
 		assert(PixelUtil::isAccessible(src.getFormat()));
 		assert(PixelUtil::isAccessible(scaled.getFormat()));
@@ -1328,7 +1270,8 @@ namespace BansheeEngine {
 				temp = PixelData(scaled.getWidth(), scaled.getHeight(), scaled.getDepth(), src.getFormat());
 				temp.allocateInternalBuffer();
 			}
-			// super-optimized: no conversion
+
+			// No conversion
 			switch (PixelUtil::getNumElemBytes(src.getFormat())) 
 			{
 			case 1: NearestResampler<1>::scale(src, temp); break;
@@ -1340,9 +1283,10 @@ namespace BansheeEngine {
 			case 12: NearestResampler<12>::scale(src, temp); break;
 			case 16: NearestResampler<16>::scale(src, temp); break;
 			default:
-				// never reached
+				// Never reached
 				assert(false);
 			}
+
 			if(temp.getData() != scaled.getData())
 			{
 				// Blit temp buffer
@@ -1350,6 +1294,7 @@ namespace BansheeEngine {
 
 				temp.freeInternalBuffer();
 			}
+
 			break;
 
 		case FILTER_LINEAR:
@@ -1372,7 +1317,8 @@ namespace BansheeEngine {
 					temp = PixelData(scaled.getWidth(), scaled.getHeight(), scaled.getDepth(), src.getFormat());
 					temp.allocateInternalBuffer();
 				}
-				// super-optimized: byte-oriented math, no conversion
+
+				// No conversion
 				switch (PixelUtil::getNumElemBytes(src.getFormat())) 
 				{
 				case 1: LinearResampler_Byte<1>::scale(src, temp); break;
@@ -1380,15 +1326,17 @@ namespace BansheeEngine {
 				case 3: LinearResampler_Byte<3>::scale(src, temp); break;
 				case 4: LinearResampler_Byte<4>::scale(src, temp); break;
 				default:
-					// never reached
+					// Never reached
 					assert(false);
 				}
+
 				if(temp.getData() != scaled.getData())
 				{
 					// Blit temp buffer
 					PixelUtil::bulkPixelConversion(temp, scaled);
 					temp.freeInternalBuffer();
 				}
+
 				break;
 			case PF_FLOAT32_RGB:
 			case PF_FLOAT32_RGBA:
@@ -1398,48 +1346,47 @@ namespace BansheeEngine {
 					LinearResampler_Float32::scale(src, scaled);
 					break;
 				}
-				// else, fall through
+				// Else, fall through
 			default:
-				// non-optimized: floating-point math, performs conversion but always works
+				// Fallback case, slow but works
 				LinearResampler::scale(src, scaled);
 			}
 			break;
 		}
 	}
 
-	//-----------------------------------------------------------------------------
-	void PixelUtil::applyGamma(UINT8 *buffer, float gamma, size_t size, UINT8 bpp)
+	void PixelUtil::applyGamma(UINT8* buffer, float gamma, UINT32 size, UINT8 bpp)
 	{
-		if( gamma == 1.0f )
+		if(gamma == 1.0f)
 			return;
 
-		//NB only 24/32-bit supported
-		if( bpp != 24 && bpp != 32 ) return;
-
 		UINT32 stride = bpp >> 3;
 
-		for( size_t i = 0, j = size / stride; i < j; i++, buffer += stride )
+		for(size_t i = 0, j = size / stride; i < j; i++, buffer += stride)
 		{
-			float r, g, b;
-
-			r = (float)buffer[0];
-			g = (float)buffer[1];
-			b = (float)buffer[2];
+			float r = (float)buffer[0];
+			float g = (float)buffer[1];
+			float b = (float)buffer[2];
 
 			r = r * gamma;
 			g = g * gamma;
 			b = b * gamma;
 
-			float scale = 1.0f, tmp;
+			float scale = 1.0f;
+			float tmp = 0.0f;
 
-			if( r > 255.0f && (tmp=(255.0f/r)) < scale )
+			if(r > 255.0f && (tmp=(255.0f/r)) < scale)
 				scale = tmp;
-			if( g > 255.0f && (tmp=(255.0f/g)) < scale )
+
+			if(g > 255.0f && (tmp=(255.0f/g)) < scale)
 				scale = tmp;
-			if( b > 255.0f && (tmp=(255.0f/b)) < scale )
+
+			if(b > 255.0f && (tmp=(255.0f/b)) < scale)
 				scale = tmp;
 
-			r *= scale; g *= scale; b *= scale;
+			r *= scale; 
+			g *= scale; 
+			b *= scale;
 
 			buffer[0] = (UINT8)r;
 			buffer[1] = (UINT8)g;

+ 2 - 2
CamelotCore/Source/CmProfiler.cpp

@@ -29,7 +29,7 @@ namespace BansheeEngine
 			cm_deleteN<ProfilerAlloc>(mSavedCoreReports, NUM_SAVED_FRAMES);
 	}
 
-	void Profiler::update()
+	void Profiler::_update()
 	{
 #if CM_PROFILING_ENABLED
 		mSavedSimReports[mNextSimReportIdx].cpuReport = mCPUProfiler->generateReport();
@@ -40,7 +40,7 @@ namespace BansheeEngine
 #endif
 	}
 
-	void Profiler::updateCore()
+	void Profiler::_updateCore()
 	{
 #if CM_PROFILING_ENABLED
 		CM_LOCK_MUTEX(mSync);

+ 1 - 1
CamelotGLRenderer/Source/CmGLRenderTexture.cpp

@@ -334,7 +334,7 @@ static const UINT32 depthBits[] =
         if(checkFormat(format))
             return format;
         /// Find first alternative
-        PixelComponentType pct = PixelUtil::getComponentType(format);
+        PixelComponentType pct = PixelUtil::getElementType(format);
         switch(pct)
         {
         case PCT_BYTE: format = PF_A8R8G8B8; break;