浏览代码

More documentation

Marko Pintera 11 年之前
父节点
当前提交
72dc696f1c

+ 5 - 5
BansheeCore/Include/BsRenderSystem.h

@@ -226,8 +226,8 @@ namespace BansheeEngine
 		 * @param	buffers			Combination of one or more elements of FrameBufferType
 		 *							denoting which buffers are to be cleared.
 		 * @param	color			(optional) The color to clear the color buffer with, if enabled.
-		 * @param	depth			(optional) The value to initialise the depth buffer with, if enabled.
-		 * @param	stencil			(optional) The value to initialise the stencil buffer with, if enabled.
+		 * @param	depth			(optional) The value to initialize the depth buffer with, if enabled.
+		 * @param	stencil			(optional) The value to initialize the stencil buffer with, if enabled.
 		 */
 		virtual void clearRenderTarget(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0) = 0;
 
@@ -238,8 +238,8 @@ namespace BansheeEngine
 		 * @param	buffers			Combination of one or more elements of FrameBufferType
 		 *							denoting which buffers are to be cleared.
 		 * @param	color			(optional) The color to clear the color buffer with, if enabled.
-		 * @param	depth			(optional) The value to initialise the depth buffer with, if enabled.
-		 * @param	stencil			(optional) The value to initialise the stencil buffer with, if enabled.
+		 * @param	depth			(optional) The value to initialize the depth buffer with, if enabled.
+		 * @param	stencil			(optional) The value to initialize the stencil buffer with, if enabled.
 		 */
 		virtual void clearViewport(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0) = 0;
 
@@ -319,7 +319,7 @@ namespace BansheeEngine
 		 * @brief	Gets the maximum (farthest) depth value used by this
 		 *			render system.
 		 *
-		 * @note		Thread safe.
+		 * @note	Thread safe.
 		 */
 		virtual float getMaximumDepthInputValue() = 0;
 

+ 3 - 1
BansheeCore/Include/BsTextureManager.h

@@ -17,7 +17,6 @@ namespace BansheeEngine
     class BS_CORE_EXPORT TextureManager : public Module<TextureManager>
     {
     public:
-
         TextureManager();
         virtual ~TextureManager();
 
@@ -86,6 +85,9 @@ namespace BansheeEngine
 		 */
 		virtual PixelFormat getNativeFormat(TextureType ttype, PixelFormat format, int usage, bool hwGamma) = 0;
 
+		/**
+		 * @brief	Returns tiny dummy texture for use when no other is available.
+		 */
 		const HTexture& getDummyTexture() const { return mDummyTexture; }
 
 	protected:

+ 1 - 1
BansheeCore/Source/BsPixelUtil.cpp

@@ -1703,7 +1703,7 @@ namespace BansheeEngine
 
 		nvtt::CompressionOptions co;
 		co.setFormat(nvtt::Format_RGBA);
-
+		
 		UINT32 numMips = getMaxMipmaps(src.getWidth(), src.getHeight(), 1, src.getFormat());
 
 		Vector<PixelDataPtr> argbMipBuffers;

+ 81 - 36
BansheeD3D9RenderSystem/Include/BsD3D9PixelBuffer.h

@@ -5,84 +5,129 @@
 
 namespace BansheeEngine 
 {
+	/**
+	 * @brief	DirectX9 implementation of a pixel buffer. Represents a hardware buffer
+	 *			containing a surface of pixels.
+	 */
 	class BS_D3D9_EXPORT D3D9PixelBuffer : public PixelBuffer
 	{
 	protected:
+		/**
+		 * @brief	Internal DX9 buffer resources container.
+		 */
 		struct BufferResources
 		{
-			/// Surface abstracted by this buffer
 			IDirect3DSurface9* surface;
-			/// Volume abstracted by this buffer
 			IDirect3DVolume9* volume;
-			/// Temporary surface in main memory if direct locking of mSurface is not possible
 			IDirect3DSurface9* tempSurface;
-			/// Temporary volume in main memory if direct locking of mVolume is not possible
 			IDirect3DVolume9* tempVolume;
-			/// Mip map texture.
-			IDirect3DBaseTexture9 *mipTex;
+			IDirect3DBaseTexture9* mipTex;
 		};
 
 	public:
 		D3D9PixelBuffer(GpuBufferUsage usage, D3D9Texture* ownerTexture);
 		~D3D9PixelBuffer();
 
-		/// Call this to associate a D3D surface or volume with this pixel buffer
-		void bind(IDirect3DDevice9* dev, IDirect3DSurface9* mSurface,
-			bool writeGamma, UINT32 multisampleCount, const String& srcName, IDirect3DBaseTexture9* mipTex);
-		void bind(IDirect3DDevice9* dev, IDirect3DVolume9* mVolume, IDirect3DBaseTexture9* mipTex);
-		/// Internal function to update mipmaps on update of level 0
-		void genMipmaps(IDirect3DBaseTexture9* mipTex);
-
-		/// Function to set mipmap generation
+		/**
+		 * @brief	Binds the specified surface object to this buffer. This needs to be called in order
+		 *			to initialize the pixel buffer.
+		 *
+		 * @param	dev			Device the surface was created on.
+		 * @param	surface		DirectX 9 object representing the surface.
+		 * @param	mipTex		Base texture that will be used for generating mipmaps. Usually
+		 *						the parent texture of the surface.
+		 */
+		void bind(IDirect3DDevice9* dev, IDirect3DSurface9* surface, IDirect3DBaseTexture9* mipTex);
+
+		/**
+		 * @brief	Binds the specified volume object to this buffer. This needs to be called in order
+		 *			to initialize the pixel buffer.
+		 *
+		 * @param	dev			Device the volume was created on.
+		 * @param	surface		DirectX 9 object representing the volume.
+		 * @param	mipTex		Base texture that will be used for generating mipmaps. Usually
+		 *						the parent texture of the volume.
+		 */
+		void bind(IDirect3DDevice9* dev, IDirect3DVolume9* volume, IDirect3DBaseTexture9* mipTex);
+
+		/**
+		 * @brief	Enables/disabled automatic mipmap generation on updates.
+		 *
+		 * @param	doMipmapGen	If true, mipmaps will be regenerated whenever data is written to the buffer.
+		 * @param	HWMipmaps	If true the mipmaps will be generated by the hardware, otherwise software (slower).
+		 */
 		void setMipmapping(bool doMipmapGen, bool HWMipmaps);
 
-		/// Accessor for surface
-		IDirect3DSurface9 *getSurface(IDirect3DDevice9* d3d9Device);
+		/**
+		 * @brief	Returns internal DirectX 9 surface object for this buffer.
+		 */
+		IDirect3DSurface9* getSurface(IDirect3DDevice9* d3d9Device);
 
-		/// Release surfaces held by this pixel buffer.
+		/**
+		 * @brief	Release all surface objects held by this buffer for the specified device.
+		 */
 		void releaseSurfaces(IDirect3DDevice9* d3d9Device);
 
-		/// Destroy resources associated with the given device.
+		/**
+		 * @brief	Destroy all resources associated with the specified device.
+		 */
 		void destroyBufferResources(IDirect3DDevice9* d3d9Device);
 
-		// Called when device state is changing. Access to any device should be locked.
-		// Relevant for multi thread application.
+		/**
+		 * @brief	Called when device state is changing. Access to any device should be locked.
+		 */
 		static void lockDeviceAccess();
 
-		// Called when device state change completed. Access to any device is allowed.
-		// Relevant for multi thread application.
+		/**
+		 * @brief	Called when device state change completed. Access to any device is allowed.
+		 */
 		static void unlockDeviceAccess();
 
 	protected:
-		/// Lock a box
+		/**
+		 * @copydoc	PixelBuffer::lockImpl
+		 */
 		PixelData lockImpl(PixelVolume lockBox, GpuLockOptions options);
-		PixelData lockBuffer(BufferResources* bufferResources, const PixelVolume& lockBox, DWORD flags);
 
-		/// Unlock a box
+		/**
+		 * @copydoc	PixelBuffer::unlockImpl
+		 */
 		void unlockImpl();
+
+		/**
+		 * @brief	Locks the specified volume of the provided buffer objects and 
+		 *			returns a data buffer that you may use to access it.
+		 */
+		PixelData lockBuffer(BufferResources* bufferResources, const PixelVolume& lockBox, DWORD flags);
+
+		/**
+		 * @brief	Unlocks the specified buffer objects.
+		 */
 		void unlockBuffer(BufferResources* bufferResources);
 
-		BufferResources* getBufferResources(IDirect3DDevice9* d3d9Device);
-		BufferResources* createBufferResources();
+		/**
+		 * @brief	Generates mip-map chain for the specified texture.
+		 */
+		void genMipmaps(IDirect3DBaseTexture9* mipTex);
 
-		void blit(IDirect3DDevice9* d3d9Device, const PixelBufferPtr& src, const PixelVolume& srcBox, const PixelVolume& dstBox, 
-				BufferResources* srcBufferResources, BufferResources* dstBufferResources);
+		/**
+		 * @brief	Retrieves buffer resources for the specified device, or null if they
+		 *			do not exist.
+		 */
+		BufferResources* getBufferResources(IDirect3DDevice9* d3d9Device);
 
-		void blitFromMemory(const PixelData& src, const PixelVolume& dstBox, BufferResources* dstBufferResources);
-		void blitToMemory(const PixelVolume& srcBox, const PixelData& dst, BufferResources* srcBufferResources, IDirect3DDevice9* d3d9Device);
+		/**
+		 * @brief	Creates a new empty set of buffer resources.
+		 */
+		BufferResources* createBufferResources();
 
 	protected:
-		/// Map between device to buffer resources.
 		Map<IDirect3DDevice9*, BufferResources*> mMapDeviceToBufferResources;
 
-		/// Mipmapping
 		bool mDoMipmapGen;
 		bool mHWMipmaps;
 
-		// The owner texture if exists.
 		D3D9Texture* mOwnerTexture;
-
-		// The current lock flags of this surface.
 		DWORD mLockFlags;
 	};
 };

+ 1 - 4
BansheeD3D9RenderSystem/Include/BsD3D9Prerequisites.h

@@ -8,10 +8,8 @@
 
 #define DIRECT3D_VERSION 0x0900
 
-// some D3D commonly used macros
 #define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=NULL; } }
 
-// enable extended d3d debug 
 #if BS_DEBUG_MODE
 #	define D3D_DEBUG_INFO
 #endif
@@ -20,11 +18,11 @@
 #if !defined(NOMINMAX) && defined(_MSC_VER)
 #	define NOMINMAX // required to stop windows.h messing up std::min
 #endif
+
 #include <d3d9.h>
 #include <d3dx9.h>
 #include <DxErr.h>
 
-
 namespace BansheeEngine
 {
 	// Predefine classes
@@ -58,7 +56,6 @@ namespace BansheeEngine
 		TID_D3D9_GpuFragmentProgram = 10002
 	};
 
-
 #if (BS_PLATFORM == BS_PLATFORM_WIN32) && !defined(BS_STATIC_LIB)
 #	ifdef BS_RSD3D9_EXPORTS
 #		define BS_D3D9_EXPORT __declspec(dllexport)

+ 3 - 0
BansheeD3D9RenderSystem/Include/BsD3D9QueryManager.h

@@ -5,6 +5,9 @@
 
 namespace BansheeEngine
 {
+	/**
+	 * @brief	Handles creation of DirectX 9 queries.
+	 */
 	class BS_D3D9_EXPORT D3D9QueryManager : public QueryManager
 	{
 	public:

+ 298 - 218
BansheeD3D9RenderSystem/Include/BsD3D9RenderSystem.h

@@ -9,14 +9,16 @@
 namespace BansheeEngine 
 {
 	/**
-	Implementation of DirectX9 as a rendering system.
-	*/
+	 * @brief	Implementation of a render system using DirectX 9. Provides abstracted
+	 *			access to various low level DX9 methods.
+	 */
 	class BS_D3D9_EXPORT D3D9RenderSystem : public RenderSystem
 	{
 	public:
-		// constructor
+		/**
+		 * @brief	Constructs a new instance of the render system using the provided module instance.
+		 */
 		D3D9RenderSystem(HINSTANCE hInstance);
-		// destructor
 		~D3D9RenderSystem();
 
 		/**
@@ -119,6 +121,9 @@ namespace BansheeEngine
 		 */
 		void drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexOffset, UINT32 vertexCount);
 
+		/**
+		 * @copydoc RenderSystem::setScissorRect()
+		 */
         void setScissorRect(UINT32 left, UINT32 top, UINT32 right, UINT32 bottom);
 
 		/**
@@ -131,256 +136,299 @@ namespace BansheeEngine
 		 */
 		void clearViewport(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0);
 
+		/**
+		 * @copydoc RenderSystem::convertProjectionMatrix()
+		 */
 		void convertProjectionMatrix(const Matrix4& matrix, Matrix4& dest, bool forGpuProgram = false);
 
+		/**
+		 * @copydoc	RenderSystem::getHorizontalTexelOffset
+		 */
         float getHorizontalTexelOffset();
+
+		/**
+		 * @copydoc	RenderSystem::getVerticalTexelOffset
+		 */
         float getVerticalTexelOffset();
+
+		/**
+		 * @copydoc	RenderSystem::getMinimumDepthInputValue
+		 */
         float getMinimumDepthInputValue();
+
+		/**
+		 * @copydoc	RenderSystem::getMaximumDepthInputValue
+		 */
         float getMaximumDepthInputValue();
+
+		/**
+		 * @copydoc	RenderSystem::getColorVertexElementType
+		 */
 		VertexElementType getColorVertexElementType() const;
 
 		/************************************************************************/
 		/* 				Internal use by DX9 RenderSystem only                   */
 		/************************************************************************/
 
+		/**
+		 * @brief	Returns the resource manager instance.
+		 */
 		static D3D9ResourceManager* getResourceManager();
+
+		/**
+		 * @brief	Returns the device manager instance.
+		 */
 		static D3D9DeviceManager* getDeviceManager();
+
+		/**
+		 * @brief	Returns the internal DirectX 9 device object.
+		 */
 		static IDirect3D9* getDirect3D9();
+
+		/**
+		 * @brief	Returns the number of devices that resources should be created on.
+		 */
 		static UINT	getResourceCreationDeviceCount();
+
+		/**
+		 * @brief	Returns DirectX 9 device used for resource creation at the specified index.
+		 */
 		static IDirect3DDevice9* getResourceCreationDevice(UINT index);
+
+		/**
+		 * @brief	Returns the currently active DirectX 9 device.
+		 */
 		static IDirect3DDevice9* getActiveD3D9Device();
 
+		/**
+		 * @brief	Converts engine multisample options into DirectX 9 specific ones.
+		 *			Also test for multi-sample support on the device and returns nearest
+		 *			supported type if requested type is not available.
+		 *
+		 * @param	d3d9Device				Device to check for multisampling.
+		 * @param	multisampleCount		Number of requested samples.
+		 * @param	multisampleHint			String describing an optional hint to which multisample method to use.
+		 * @param	d3dPixelFormat			Pixel format used by the render target.
+		 * @param	fullscreen				Are we testing multisampling for a full-screen render target.
+		 * @param	outMultisampleType		Output parameter containing DirectX type representing valid multisample type.
+		 * @param	outMultisampleQuality	Output parameter containing multisample quality.
+		 */
 		void determineMultisampleSettings(IDirect3DDevice9* d3d9Device, UINT32 multisampleCount, const String& multisampleHint, D3DFORMAT d3dPixelFormat,
-			bool fullScreen, D3DMULTISAMPLE_TYPE *outMultisampleType, DWORD *outMultisampleQuality) const;
+			bool fullScreen, D3DMULTISAMPLE_TYPE* outMultisampleType, DWORD* outMultisampleQuality) const;
 
+		/**
+		 * @brief	Register a newly open window with the render system.
+		 */
 		void registerWindow(RenderWindow& renderWindow);
 
 	private:
-		static D3D9RenderSystem* msD3D9RenderSystem;
-
-		IDirect3D9*	mpD3D;
-		bool mIsFrameInProgress;
-		bool mRestoreFrameOnReset;
-
-		mutable D3D9DriverList* mDriverList;
-		D3D9Driver* mActiveD3DDriver;
-
-		HINSTANCE mhInstance;
-
-		UINT32 mViewportLeft, mViewportTop, mViewportWidth, mViewportHeight;
-		RECT mScissorRect;
-
-		DrawOperationType mCurrentDrawOperation;
+		friend class D3D9Texture;
+		friend class D3D9RenderWindow;
+		friend class D3D9Device;
+		friend class D3D9TextureManager;
+		friend class D3D9DeviceManager;
+		friend class D3D9RenderWindowManager;
 
-		/// structure holding texture unit settings for every stage
-		struct sD3DTextureStageDesc
-		{
-			/// the type of the texture
-			D3D9Mappings::D3DTexType texType;
-			/// which texCoordIndex to use
-			size_t coordIndex;
-			/// texture 
-			IDirect3DBaseTexture9 *pTex;
-			/// vertex texture 
-			IDirect3DBaseTexture9 *pVertexTex;
-		};
+		/**
+		 * @copydoc	RenderSystem::initialize_internal
+		 */
+		void initialize_internal(AsyncOp& asyncOp);
 
-		UINT32 mNumTexStages;
-		sD3DTextureStageDesc* mTexStageDesc;
+		/**
+		 * @copydoc	RenderSystem::destroy_internal
+		 */
+		void destroy_internal();
 
+		/**
+		 * @brief	Returns a list of available drivers and their properties.
+		 */
 		D3D9DriverList* getDirect3DDrivers() const;
 				
-		// state management methods, very primitive !!!
-		HRESULT __SetRenderState(D3DRENDERSTATETYPE state, DWORD value);
-		HRESULT __SetSamplerState(DWORD sampler, D3DSAMPLERSTATETYPE type, DWORD value);
-		HRESULT __SetTextureStageState(DWORD stage, D3DTEXTURESTAGESTATETYPE type, DWORD value);
+		/**
+		 * @brief	Sets DirectX 9 render state option.
+		 */
+		HRESULT setRenderState(D3DRENDERSTATETYPE state, DWORD value);
+
+		/**
+		 * @brief	Sets DirectX 9 sampler state option for a sampler at the specified index.
+		 */
+		HRESULT setSamplerState(DWORD sampler, D3DSAMPLERSTATETYPE type, DWORD value);
+
+		/**
+		 * @brief	Sets DirectX 9 texture state option for a texture unit at the specified index.
+		 */
+		HRESULT setTextureStageState(DWORD stage, D3DTEXTURESTAGESTATETYPE type, DWORD value);
 
-		HRESULT __SetFloatRenderState(D3DRENDERSTATETYPE state, float value)
+		/**
+		 * @brief	Set a floating point render state option.
+		 */
+		HRESULT setFloatRenderState(D3DRENDERSTATETYPE state, float value)
 		{
-			return __SetRenderState(state, *((LPDWORD)(&value)));
+			return setRenderState(state, *((LPDWORD)(&value)));
 		}
 
-		/// return anisotropy level
-		DWORD _getCurrentAnisotropy(UINT32 unit);
-		bool _checkMultiSampleQuality(D3DMULTISAMPLE_TYPE type, DWORD *outQuality, D3DFORMAT format, UINT adapterNum, D3DDEVTYPE deviceType, BOOL fullScreen);
-		
-        D3D9HLSLProgramFactory* mHLSLProgramFactory;
-		D3D9ResourceManager* mResourceManager;
-		D3D9DeviceManager* mDeviceManager;
+		/**
+		 * @brief	Returns currently active anisotropy level for the provided texture unit.
+		 */
+		DWORD getCurrentAnisotropy(UINT32 unit);
 
-        /// Internal method for populating the capabilities structure
-		virtual RenderSystemCapabilities* createRenderSystemCapabilities() const;
+		/**
+		 * @brief	Updates active render system capabilities. Requires active render window to check
+		 *			certain capabilities.
+		 *
+		 * @note	Also performs an initialization step when called the first time.
+		 */
 		RenderSystemCapabilities* updateRenderSystemCapabilities(D3D9RenderWindow* renderWindow);
 
-		/** See RenderSystem definition */
-		virtual void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps);
-
-        void convertVertexShaderCaps(RenderSystemCapabilities* rsc) const;
-        void convertPixelShaderCaps(RenderSystemCapabilities* rsc) const;
-
-	protected:
-		// I know that's a lot of friends, but I'd rather have friend classes than exposing the needed methods
-		// as public interface. 
-		friend class D3D9Texture;
-		friend class D3D9RenderWindow;
-		friend class D3D9Device;
-		friend class D3D9TextureManager;
-		friend class D3D9DeviceManager;		
-		friend class D3D9RenderWindowManager;
+		/**
+		 * @brief	Updates render system capabilities with vertex shader related data.
+		 */
+        void updateVertexShaderCaps(RenderSystemCapabilities* rsc) const;
 
-		void initialize_internal(AsyncOp& asyncOp);
-		void destroy_internal();
+		/**
+		 * @brief	Updates render system capabilities with pixel shader related data.
+		 */
+        void updatePixelShaderCaps(RenderSystemCapabilities* rsc) const;
 
+		/**
+		 * @copydoc	RenderSystem::setClipPlanesImpl
+		 */
 		void setClipPlanesImpl(const PlaneList& clipPlanes);	
 
-		String getErrorDescription( long errorNumber ) const;
+		/**
+		 * @brief	Converts a HRESULT error number into an error description.
+		 */
+		String getErrorDescription(long errorNumber) const;
+
+		/**
+		 * @brief	Sets a clip plane with the specified index.
+		 */
+		void setClipPlane(UINT16 index, float A, float B, float C, float D);
 
-		void setClipPlane (UINT16 index, float A, float B, float C, float D);
-		void enableClipPlane (UINT16 index, bool enable);
+		/**
+		 * @brief	Enables or disables a clip plane at the specified index.
+		 */
+		void enableClipPlane(UINT16 index, bool enable);
 
+		/**
+		 * @brief	Returns current module instance.
+		 */
 		HINSTANCE getInstanceHandle() const { return mhInstance; }
 
 		/**
 		 * @brief	Returns the D3D9 specific mode used for drawing, depending on the
-		 * 			currently set draw operation;
+		 * 			currently set draw operation.
 		 */
 		D3DPRIMITIVETYPE getD3D9PrimitiveType() const;
 
-        /** Check whether or not filtering is supported for the precise texture format requested
-        with the given usage options.
-        */
+		/**
+		 * @brief	Check whether or not filtering is supported for the precise texture format requested
+		 *			with the given usage options.
+		 */
         bool checkTextureFilteringSupported(TextureType ttype, PixelFormat format, int usage);
 
 		/************************************************************************/
 		/* 							Sampler states                     			*/
 		/************************************************************************/
 
-		/** Sets the texture addressing mode for a texture unit.*/	
+		/**
+		 * @brief	Sets the texture addressing mode for a texture unit. This determines
+		 *			how are UV address values outside of [0, 1] range handled when sampling
+		 *			from texture.
+		 */
 		void setTextureAddressingMode(UINT16 stage, const UVWAddressingMode& uvw);
 
-		/** Sets a single filter for a given texture unit.
-		@param unit The texture unit to set the filtering options for
-		@param ftype The filter type
-		@param filter The filter to be used
-		*/
+		/**
+		 * @brief	Allows you to specify how is the texture bound to the specified texture unit filtered.
+		 *			Different filter types are used for different situations like magnifying or minifying a texture.
+		 */
 		void setTextureFiltering(UINT16 unit, FilterType ftype, FilterOptions filter);
 
-		/** Sets the maximal anisotropy for the specified texture unit.*/
+		/**
+		 * @brief	Sets anisotropy value for the specified texture unit.
+		 */
 		void setTextureAnisotropy(UINT16 unit, unsigned int maxAnisotropy);
 
-		/** Sets the texture border colour for a texture unit.*/
+		/**
+		 * @brief	Sets the texture border color for a texture unit. Border color
+		 *			determines color returned by the texture sampler when border addressing mode
+		 *			is used and texture address is outside of [0, 1] range.
+		 */
 		void setTextureBorderColor(UINT16 stage, const Color& color);
 
-		/** Sets the mipmap bias value for a given texture unit.
-		@remarks
-		This allows you to adjust the mipmap calculation up or down for a
-		given texture unit. Negative values force a larger mipmap to be used, 
-		positive values force a smaller mipmap to be used. Units are in numbers
-		of levels, so +1 forces the mipmaps to one smaller level.
-		@note Only does something if render system has capability RSC_MIPMAP_LOD_BIAS.
-		*/
+		/**
+		 * @brief	Sets the mipmap bias value for a given texture unit. Bias allows
+		 *			you to adjust the mipmap selection calculation. Negative values force a
+		 *			larger mipmap to be used, and positive values smaller. Units are in values
+		 *			of mip levels, so -1 means use a mipmap one level higher than default.
+		 */
 		void setTextureMipmapBias(UINT16 unit, float bias);
 
 		/************************************************************************/
 		/* 								Blend states                      		*/
 		/************************************************************************/
 
-		/** Sets the global blending factors for combining subsequent renders with the existing frame contents.
-		The result of the blending operation is:</p>
-		<p align="center">final = (texture * sourceFactor) + (pixel * destFactor)</p>
-		Each of the factors is specified as one of a number of options, as specified in the SceneBlendFactor
-		enumerated type.
-		By changing the operation you can change addition between the source and destination pixels to a different operator.
-		@param sourceFactor The source factor in the above calculation, i.e. multiplied by the texture colour components.
-		@param destFactor The destination factor in the above calculation, i.e. multiplied by the pixel colour components.
-		@param op The blend operation mode for combining pixels
-		*/
-		void setSceneBlending( BlendFactor sourceFactor, BlendFactor destFactor, BlendOperation op );
-
-		/** Sets the global blending factors for combining subsequent renders with the existing frame contents.
-		The result of the blending operation is:</p>
-		<p align="center">final = (texture * sourceFactor) + (pixel * destFactor)</p>
-		Each of the factors is specified as one of a number of options, as specified in the SceneBlendFactor
-		enumerated type.
-		@param sourceFactor The source factor in the above calculation, i.e. multiplied by the texture colour components.
-		@param destFactor The destination factor in the above calculation, i.e. multiplied by the pixel colour components.
-		@param sourceFactorAlpha The source factor in the above calculation for the alpha channel, i.e. multiplied by the texture alpha components.
-		@param destFactorAlpha The destination factor in the above calculation for the alpha channel, i.e. multiplied by the pixel alpha components.
-		@param op The blend operation mode for combining pixels
-		@param alphaOp The blend operation mode for combining pixel alpha values
-		*/
-		void setSceneBlending( BlendFactor sourceFactor, BlendFactor destFactor, BlendFactor sourceFactorAlpha, 
-			BlendFactor destFactorAlpha, BlendOperation op, BlendOperation alphaOp );
+		/**
+		 * @brief	Sets up blending mode that allows you to combine new pixels with pixels already in the render target.
+		 *			Final pixel value = (renderTargetPixel * sourceFactor) op (pixel * destFactor).
+		 */
+		void setSceneBlending(BlendFactor sourceFactor, BlendFactor destFactor, BlendOperation op);
 
-		/** Sets the global alpha rejection approach for future renders.
-		By default images are rendered regardless of texture alpha. This method lets you change that.
-		@param func The comparison function which must pass for a pixel to be written.
-		@param val The value to compare each pixels alpha value to (0-255)
+		/**
+		* @brief	Sets up blending mode that allows you to combine new pixels with pixels already in the render target.
+		*			Allows you to set up separate blend operations for alpha values.
+		*	
+		*			Final pixel value = (renderTargetPixel * sourceFactor) op (pixel * destFactor). (And the same for alpha)
 		*/
+		void setSceneBlending(BlendFactor sourceFactor, BlendFactor destFactor, BlendFactor sourceFactorAlpha, 
+			BlendFactor destFactorAlpha, BlendOperation op, BlendOperation alphaOp);
+
+		/**
+		 * @brief	Sets alpha test that allows you to reject pixels that fail the comparison function
+		 *			versus the provided reference value.
+		 */
 		void setAlphaTest(CompareFunction func, unsigned char value);
 
 		/**
-		 * @brief	Enable alpha coverage if supported.
+		 * @brief	Enable alpha to coverage. Alpha to coverage allows you to perform blending without needing 
+		 *			to worry about order of rendering like regular blending does. It requires multi-sampling to 
+		 *			be active in order to work, and you need to supply an alpha texture that determines object transparency.
 		 */
 		void setAlphaToCoverage(bool enabled);
 
-		/** Sets whether or not colour buffer writing is enabled, and for which channels. 
-		@remarks
-		For some advanced effects, you may wish to turn off the writing of certain colour
-		channels, or even all of the colour channels so that only the depth buffer is updated
-		in a rendering pass. However, the chances are that you really want to use this option
-		through the Material class.
-		@param red, green, blue, alpha Whether writing is enabled for each of the 4 colour channels. */
+		/**
+		 * @brief	Enables or disables writing to certain color channels of the render target.
+		 */
 		void setColorBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
 
 		/************************************************************************/
 		/* 								Rasterizer states                  		*/
 		/************************************************************************/
 
-		/** Sets the culling mode for the render system based on the 'vertex winding'.
-		A typical way for the rendering engine to cull triangles is based on the
-		'vertex winding' of triangles. Vertex winding refers to the direction in
-		which the vertices are passed or indexed to in the rendering operation as viewed
-		from the camera, and will wither be clockwise or anticlockwise (that's 'counterclockwise' for
-		you Americans out there ;) The default is CULL_CLOCKWISE i.e. that only triangles whose vertices
-		are passed/indexed in anticlockwise order are rendered - this is a common approach and is used in 3D studio models
-		for example. You can alter this culling mode if you wish but it is not advised unless you know what you are doing.
-		You may wish to use the CULL_NONE option for mesh data that you cull yourself where the vertex
-		winding is uncertain.
-		*/
+		/**
+		 * @brief	Sets vertex winding order. Normally you would use this to cull back facing
+		 *			polygons.
+		 */
 		void setCullingMode(CullingMode mode);
 
-		/** Sets how to rasterise triangles, as points, wireframe or solid polys. */
+		/**
+		 * @brief	Sets the polygon rasterization mode. Determines how are polygons interpreted.
+		 */
 		void setPolygonMode(PolygonMode level);
 
-		/** Sets the depth bias, NB you should use the Material version of this. 
-		@remarks
-		When polygons are coplanar, you can get problems with 'depth fighting' where
-		the pixels from the two polys compete for the same screen pixel. This is particularly
-		a problem for decals (polys attached to another surface to represent details such as
-		bulletholes etc.).
-		@par
-		A way to combat this problem is to use a depth bias to adjust the depth buffer value
-		used for the decal such that it is slightly higher than the true value, ensuring that
-		the decal appears on top.
-		@note
-		The final bias value is a combination of a constant bias and a bias proportional
-		to the maximum depth slope of the polygon being rendered. The final bias
-		is constantBias + slopeScaleBias * maxslope. Slope scale biasing is
-		generally preferable but is not available on older hardware.
-		@param constantBias The constant bias value, expressed as a value in 
-		homogeneous depth coordinates.
-		@param slopeScaleBias The bias value which is factored by the maximum slope
-		of the polygon, see the description above. This is not supported by all
-		cards.
-
-		*/
+		/**
+		 * @brief	Sets a depth bias that will offset the depth values of new pixels by the specified amount.
+		 *			Final depth bias value is a combination of the constant depth bias and slope depth bias.
+		 *			Slope depth bias has more effect the higher the slope of the rendered polygon.
+		 *
+		 * @note	This is useful if you want to avoid z fighting for objects at the same or similar depth.
+		 */
 		void setDepthBias(float constantBias, float slopeScaleBias);
 
 		/**
-		* @brief	Scissor test allows you to 'mask off' rendering in all but a given rectangular area
-		* 			identified by the rectangle set by setScissorRect().
-		*/
+		 * @brief	Scissor test allows you to mask off rendering in all but a given rectangular area
+		 * 			identified by the rectangle set by setScissorRect().
+		 */
 		void setScissorTestEnable(bool enable);
 
 		/**
@@ -401,79 +449,62 @@ namespace BansheeEngine
 		/* 						Depth stencil state                      		*/
 		/************************************************************************/
 		
-		/** Sets the mode of operation for depth buffer tests from this point onwards.
-		Sometimes you may wish to alter the behaviour of the depth buffer to achieve
-		special effects. Because it's unlikely that you'll set these options for an entire frame,
-		but rather use them to tweak settings between rendering objects, this is an internal
-		method (indicated by the '_' prefix) which will be used by a SceneManager implementation
-		rather than directly from the client application.
-		If this method is never called the settings are automatically the same as the default parameters.
-		@param depthTest If true, the depth buffer is tested for each pixel and the frame buffer is only updated
-		if the depth function test succeeds. If false, no test is performed and pixels are always written.
-		@param depthWrite If true, the depth buffer is updated with the depth of the new pixel if the depth test succeeds.
-		If false, the depth buffer is left unchanged even if a new pixel is written.
-		@param depthFunction Sets the function required for the depth test.
-		*/
-		void setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
-
-		/** Sets whether or not the depth buffer check is performed before a pixel write.
-		@param enabled If true, the depth buffer is tested for each pixel and the frame buffer is only updated
-		if the depth function test succeeds. If false, no test is performed and pixels are always written.
-		*/
+		/**
+		 * @brief	Should new pixels perform depth testing using the set depth comparison function before
+		 *			being written.
+		 */
 		void setDepthBufferCheckEnabled(bool enabled = true);
 
-		/** Sets whether or not the depth buffer is updated after a pixel write.
-		@param enabled If true, the depth buffer is updated with the depth of the new pixel if the depth test succeeds.
-		If false, the depth buffer is left unchanged even if a new pixel is written.
-		*/
+		/**
+		 * @brief	Should new pixels write to the depth buffer.
+		 */
 		void setDepthBufferWriteEnabled(bool enabled = true);
 
-		/** Sets the comparison function for the depth buffer check.
-		Advanced use only - allows you to choose the function applied to compare the depth values of
-		new and existing pixels in the depth buffer. Only an issue if the deoth buffer check is enabled
-		(see _setDepthBufferCheckEnabled)
-		@param  func The comparison between the new depth and the existing depth which must return true
-		for the new pixel to be written.
-		*/
+		/**
+		 * @brief	Sets comparison function used for depth testing. Determines how are new and existing
+		 *			pixel values compared - if comparison function returns true the new pixel is written.
+		 */
 		void setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
 
-		/** Turns stencil buffer checking on or off.
-		@remarks
-		Stencilling (masking off areas of the rendering target based on the stencil
-		buffer) can be turned on or off using this method. By default, stencilling is
-		disabled.
-		*/
+		/**
+		 * @brief	Turns stencil tests on or off. By default this is disabled.
+		 *			Stencil testing allow you to mask out a part of the rendered image by using
+		 *			various stencil operations provided.
+		 */
 		void setStencilCheckEnabled(bool enabled);
 
-		/** This method allows you to set stencil buffer operations in one call.
-		@param stencilFailOp The action to perform when the stencil check fails
-		@param depthFailOp The action to perform when the stencil check passes, but the
-		depth buffer check still fails
-		@param passOp The action to take when both the stencil and depth check pass.
-		@param ccw If set to true, the stencil operations will be applied to counterclockwise
-		faces. Otherwise they will be applied to clockwise faces.
-		*/
+		/**
+		 * @brief	Allows you to set stencil operations that are performed when stencil test passes or fails.
+		 *
+		 * @param	stencilFailOp	Operation executed when stencil test fails.
+		 * @param	depthFailOp		Operation executed when stencil test succeeds but depth test fails.
+		 * @param	passOp			Operation executed when stencil test succeeds and depth test succeeds.
+		 * @param	front			Should the stencil operations be applied to front or back facing polygons.
+		 */
 		void setStencilBufferOperations(StencilOperation stencilFailOp = SOP_KEEP,
 			StencilOperation depthFailOp = SOP_KEEP, StencilOperation passOp = SOP_KEEP,
 			bool ccw = true);
 
 		/**
-		* @brief	Sets a stencil buffer comparison function. The result of this will cause one of 3 actions depending on whether the test fails,
-		*		succeeds but with the depth buffer check still failing, or succeeds with the
-		*		depth buffer check passing too.
-		* @param ccw If set to true, the stencil operations will be applied to counterclockwise
-		*		faces. Otherwise they will be applied to clockwise faces.
+		 * @brief	Sets a stencil buffer comparison function. The result of this will cause one of 3 actions 
+		 *			depending on whether the test fails, succeeds but with the depth buffer check still failing, 
+		 *			or succeeds with the depth buffer check passing too.
+		 *
+		 * @param func	Comparison function that determines whether a stencil test fails or passes. Reference value
+		 *				gets compared to the value already in the buffer using this function.
+		 * @param ccw	If set to true, the stencil operations will be applied to counterclockwise
+		 *				faces. Otherwise they will be applied to clockwise faces.
 		 */
 		void setStencilBufferFunc(CompareFunction func = CMPF_ALWAYS_PASS, bool ccw = true);
 
 		/**
-		* @brief	The bitmask applied to both the stencil value and the reference value
-		*		before comparison
+		 * @brief	The bitmask applied to both the stencil value and the reference value
+		 *			before comparison.
 		 */
 		void setStencilBufferReadMask(UINT32 mask = 0xFFFFFFFF);
 
 		/**
-		* @brief	The bitmask applied to the stencil value before writing it to the stencil buffer.
+		 * @brief	The bitmask applied to the stencil value before writing it to the stencil buffer.
 		 */
 		void setStencilBufferWriteMask(UINT32 mask = 0xFFFFFFFF);
 
@@ -483,12 +514,61 @@ namespace BansheeEngine
 		 */
 		void setStencilRefValue(UINT32 refValue);
 
+		/**
+		 * @brief	Clears an area of the currently active render target.
+		 *
+		 * @param	buffers			Combination of one or more elements of FrameBufferType
+		 *							denoting which buffers are to be cleared.
+		 * @param	color			(optional) The color to clear the color buffer with, if enabled.
+		 * @param	depth			(optional) The value to initialize the depth buffer with, if enabled.
+		 * @param	stencil			(optional) The value to initialize the stencil buffer with, if enabled.
+		 * @param	clearArea		(optional) Area in pixels to clear.
+		 */
 		void clearArea(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0, const RectI& clearArea = RectI::EMPTY);
 
-		/// Notify when a device has been lost.
+		/**
+		 * @brief	Triggered when device has been lost.
+		 */
 		void notifyOnDeviceLost(D3D9Device* device);
 
-		/// Notify when a device has been reset.
+		/**
+		 * @brief	Triggered when device is being reset.
+		 */
 		void notifyOnDeviceReset(D3D9Device* device);
+
+	private:
+		/**
+		 * @brief	Holds texture unit settings.
+		 */
+		struct sD3DTextureStageDesc
+		{
+			D3D9Mappings::D3DTexType texType;
+			size_t coordIndex;
+			IDirect3DBaseTexture9 *pTex;
+			IDirect3DBaseTexture9 *pVertexTex;
+		};
+
+		static D3D9RenderSystem* msD3D9RenderSystem;
+
+		IDirect3D9*	mpD3D;
+		D3D9HLSLProgramFactory* mHLSLProgramFactory;
+		D3D9ResourceManager* mResourceManager;
+		D3D9DeviceManager* mDeviceManager;
+
+		mutable D3D9DriverList* mDriverList;
+		D3D9Driver* mActiveD3DDriver;
+
+		UINT32 mNumTexStages;
+		sD3DTextureStageDesc* mTexStageDesc;
+
+		bool mIsFrameInProgress;
+		bool mRestoreFrameOnReset;
+
+		HINSTANCE mhInstance;
+
+		UINT32 mViewportLeft, mViewportTop, mViewportWidth, mViewportHeight;
+		RECT mScissorRect;
+
+		DrawOperationType mCurrentDrawOperation;
 	};
 }

+ 11 - 2
BansheeD3D9RenderSystem/Include/BsD3D9RenderTexture.h

@@ -6,13 +6,22 @@
 
 namespace BansheeEngine
 {
-	/// RenderTexture implementation for D3D9
+	/**
+	 * @brief	DirectX 9 implementation of a render texture.
+	 */
 	class BS_D3D9_EXPORT D3D9RenderTexture : public RenderTexture, public D3D9Resource
 	{
 	public:
 		virtual ~D3D9RenderTexture();
 
-		bool requiresTextureFlipping() const { return false; }
+		/**
+		 * @copydoc	RenderTexture::requiresTextureFlipping
+		 */
+		virtual bool requiresTextureFlipping() const { return false; }
+
+		/**
+		 * @copydoc	RenderTexture::getCustomAttribute
+		 */
 		virtual void getCustomAttribute(const String& name, void* pData) const;
 
 		/**

+ 30 - 5
BansheeD3D9RenderSystem/Include/BsD3D9RenderWindow.h

@@ -6,6 +6,9 @@
 
 namespace BansheeEngine 
 {
+	/**
+	 * @brief	Render window implementation for Windows.
+	 */
 	class BS_D3D9_EXPORT D3D9RenderWindow : public RenderWindow
 	{
 	public:
@@ -96,9 +99,24 @@ namespace BansheeEngine
 		 */
 		void _windowMovedOrResized();
 
-		HWND _getWindowHandle() const { return mHWnd; }				
+		/**
+		 * @brief	Gets internal Win32 window handle.
+		 */
+		HWND _getWindowHandle() const { return mHWnd; }
+
+		/**
+		 * @brief	Gets the DirectX 9 device object that manages this window.
+		 */
 		IDirect3DDevice9* _getD3D9Device() const;
+
+		/**
+		 * @brief	Gets the device that manages this window.
+		 */
 		D3D9Device* _getDevice() const;
+
+		/**
+		 * @brief	Sets the device that manages this window.
+		 */
 		void _setDevice(D3D9Device* device);
 
 		/**
@@ -121,14 +139,15 @@ namespace BansheeEngine
 		 */
 		bool _validateDevice();
 
-		void _adjustWindow(unsigned int clientWidth, unsigned int clientHeight, 
-			DWORD style, unsigned int* winWidth, unsigned int* winHeight);
-
+		
 	protected:
 		friend class D3D9RenderWindowManager;
 
-		D3D9RenderWindow (const RENDER_WINDOW_DESC& desc, HINSTANCE instance);
+		D3D9RenderWindow(const RENDER_WINDOW_DESC& desc, HINSTANCE instance);
 
+		/**
+		 * @brief	Updates window coordinates and size from actual values provided by Windows.
+		 */
 		void updateWindowRect();
 
 		/**
@@ -141,6 +160,12 @@ namespace BansheeEngine
 		 */
 		void destroy_internal();
 
+		/**
+		 * @brief	Calculates window size based on provided client area size and currently set window style. 
+		 */	
+		void getAdjustedWindowSize(UINT32 clientWidth, UINT32 clientHeight,
+			DWORD style, UINT32* winWidth, UINT32* winHeight);
+
 	protected:
 		HINSTANCE mInstance;
 		D3D9Device* mDevice;

+ 3 - 0
BansheeD3D9RenderSystem/Include/BsD3D9RenderWindowManager.h

@@ -5,6 +5,9 @@
 
 namespace BansheeEngine
 {
+	/**
+	 * @brief	Handles creation of windows for DirectX 9.
+	 */
 	class BS_D3D9_EXPORT D3D9RenderWindowManager : public RenderWindowManager
 	{
 	public:

+ 45 - 21
BansheeD3D9RenderSystem/Include/BsD3D9ResourceManager.h

@@ -4,57 +4,81 @@
 
 namespace BansheeEngine 
 {
+	/**
+	 * @brief	Types of resource creation policies.
+	 */
 	enum D3D9ResourceCreationPolicy
 	{
-		// Creates the rendering resource on the current active device that needs it.
-		// This policy should be used when video memory consumption should be minimized but
-		// it might cause some performance issues when using loader resource thread since
-		// a resource that was not created on specified device will be created on demand during
-		// the rendering process and might cause the FPS to drop down. 
+		/**
+		 *	Creates resources only on active device. Meaning those resources will be unavailable
+		 *	for other devices.
+		 */
 		RCP_CREATE_ON_ACTIVE_DEVICE,
 
-		// Create the rendering resource on every existing device. 		
-		// This policy should be used when working intensively with a background loader thread.
-		// In that case when multiple devices exist, the resource will be created on each device
-		// and will be ready to use in the core thread. 
-		// The draw back can be some video memory waste in case that each device render different
-		// scene and doesn't really need all the resources.
+		/**
+		 *	Creates resources on all devices making them available to all of them.
+		 */
 		RCP_CREATE_ON_ALL_DEVICES
 	};
 	
+	/**
+	 * @brief	Handles DirectX 9 resource life, notifying them
+	 *			about relevant device changes.
+	 */
 	class BS_D3D9_EXPORT D3D9ResourceManager
 	{
 	public:
 		D3D9ResourceManager();
 		~D3D9ResourceManager();
 
-		// Called immediately after the Direct3D device has been created.
+		/**
+		 * @brief	Called after the device has been created.
+		 */
 		void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
 
-		// Called before the Direct3D device is going to be destroyed.
+		/**
+		 * @brief	Called before the device is destroyed.
+		 */
 		void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
 
-		// Called immediately after the Direct3D device has entered a lost state.
+		/**
+		 * @brief	Called after the device has entered the lost state.
+		 */
 		void notifyOnDeviceLost(IDirect3DDevice9* d3d9Device);
 
-		// Called immediately after the Direct3D device has been reset.
+		/**
+		 * @brief	Called after the device has been reset.
+		 */
 		void notifyOnDeviceReset(IDirect3DDevice9* d3d9Device);
 
-		// Called when device state is changing. Access to any device should be locked.
-		// Relevant for multi thread application.
+		/**
+		 * @brief	Called when device state is changing. Access to any device should be locked.
+		 */
 		void lockDeviceAccess();
 
-		// Called when device state change completed. Access to any device is allowed.
-		// Relevant for multi thread application.
+		/**
+		 * @brief	Called when device state change completed. Access to any device is allowed.
+		 */
 		void unlockDeviceAccess();
 		
-		// Called when new resource created.
+		/**
+		 * @brief	Called when new resource is created.
+		 */
 		void _notifyResourceCreated(D3D9Resource* pResource);
 
-		// Called when resource is about to be destroyed.
+		/**
+		 * @brief	Called before resource is destroyed.
+		 */
 		void _notifyResourceDestroyed(D3D9Resource* pResource);
 
+		/**
+		 * @brief	Sets creation policy that specifies on what devices will resources be created on.
+		 */
 		void setCreationPolicy(D3D9ResourceCreationPolicy creationPolicy);
+
+		/**
+		 * @brief	Returns creation policy that specifies on what devices will resources be created on.
+		 */
 		D3D9ResourceCreationPolicy getCreationPolicy() const;
 		
 	protected:

+ 99 - 58
BansheeD3D9RenderSystem/Include/BsD3D9Texture.h

@@ -9,22 +9,22 @@
 
 namespace BansheeEngine 
 {
+	/**
+	 * @brief	DirectX 9 implementation of a texture.
+	 */
 	class BS_D3D9_EXPORT D3D9Texture : public Texture, public D3D9Resource
 	{
 	protected:
+		/**
+		 * @brief	Container for internal resources.
+		 */
 		struct TextureResources
 		{
-			/// 1D/2D normal texture pointer
 			IDirect3DTexture9* pNormTex;
-			/// cubic texture pointer
 			IDirect3DCubeTexture9* pCubeTex;
-			/// Volume texture
 			IDirect3DVolumeTexture9* pVolumeTex;
-			/// actual texture pointer
 			IDirect3DBaseTexture9* pBaseTex;
-			/// Optional multisample surface
 			IDirect3DSurface9* pMultisampleSurface;
-			/// Optional depth stencil surface
 			IDirect3DSurface9* pDepthStencilSurface;
 		};
 
@@ -36,37 +36,35 @@ namespace BansheeEngine
 		 */
 		bool isBindableAsShaderResource() const { return mIsBindableAsShaderResource; }
 
-		/// retrieves a pointer to the actual texture
-		IDirect3DBaseTexture9 *getTexture_internal();		
-		/// retrieves a pointer to the normal 1D/2D texture
-		IDirect3DTexture9 *getNormTexture_internal();
-		/// retrieves a pointer to the cube texture
-		IDirect3DCubeTexture9 *getCubeTexture_internal();
-
-		/** Indicates whether the hardware gamma is actually enabled and supported. 
-		@remarks
-			Because hardware gamma might not actually be supported, we need to 
-			ignore it sometimes. Because D3D doesn't encode sRGB in the format but
-			as a sampler state, and we don't want to change the original requested
-			hardware gamma flag (e.g. serialisation) we need another indicator.
-		*/
+		/**
+		 * @brief	Returns internal DirectX 9 texture object.
+		 */
+		IDirect3DBaseTexture9* getTexture_internal();	
+
+		/**
+		 * @brief	Returns internal DirectX 9 texture object pointing to a 1D or 2D texture.
+		 */
+		IDirect3DTexture9* getNormTexture_internal();
+
+		/**
+		 * @brief	Returns internal DirectX 9 texture object pointing to a cube texture.
+		 */
+		IDirect3DCubeTexture9* getCubeTexture_internal();
+
+		/**
+		 * @brief	Indicates whether the hardware gamma is enabled and supported.
+		 */
 		bool isHardwareGammaReadToBeUsed() const { return mHwGamma && mHwGammaReadSupported; }
 					
-		/// Will this texture need to be in the default pool?
-		bool useDefaultPool();
-
-		/** Return hardware pixel buffer for a surface. This buffer can then
-			be used to copy data from and to a particular level of the texture.
-			@param face 	Face number, in case of a cubemap texture. Must be 0
-							for other types of textures.
-                            For cubemaps, this is one of 
-                            +X (0), -X (1), +Y (2), -Y (3), +Z (4), -Z (5)
-			@param mipmap	Mipmap level. This goes from 0 for the first, largest
-							mipmap level to getNumMipmaps()-1 for the smallest.
-			@returns	A shared pointer to a hardware pixel buffer
-			@remarks	The buffer is invalidated when the resource is unloaded or destroyed.
-						Do not use it after the lifetime of the containing texture.
-		*/
+		/**
+		 * @brief	Returns a hardware pixel buffer for a certain face and level of the texture.
+		 * 
+		 * @param	face	Index of the texture face, if texture has more than one. Array index for
+		 *					texture arrays and a cube face for cube textures.
+		 * @param	mipmap	Index of the mip level. 0 being the largest mip level.
+		 *
+		 * @note	Cube face indices: +X (0), -X (1), +Y (2), -Y (3), +Z (4), -Z (5)
+		 */
 		PixelBufferPtr getBuffer(UINT32 face, UINT32 mipmap);
 
 		/**
@@ -130,64 +128,107 @@ namespace BansheeEngine
 		 */
 		void writeData(const PixelData& src, UINT32 mipLevel = 0, UINT32 face = 0, bool discardWholeBuffer = false);
 
-		/// internal method, create a blank normal 1D/2D texture		
+		/**
+		 * @brief	Returns true if the texture should be allocated in the default pool.
+		 */
+		bool useDefaultPool();
+
+		/**
+		 * @brief	Creates a DirectX object for blank normal 1D/2D texture.
+		 */
 		void createNormTex(IDirect3DDevice9* d3d9Device);
-		/// internal method, create a blank cube texture		
+
+		/**
+		 * @brief	Creates a DirectX object for blank cube texture.
+		 */
 		void createCubeTex(IDirect3DDevice9* d3d9Device);
-		/// internal method, create a blank cube texture		
+
+		/**
+		 * @brief	Creates a DirectX object for blank volume (3D) texture.
+		 */	
 		void createVolumeTex(IDirect3DDevice9* d3d9Device);
 
-		/// internal method, return a D3D pixel format for texture creation
+		/**
+		 * @brief	Selects a DirectX 9 pixel format depending on requested format
+		 *			and device capabilities.
+		 */
 		D3DFORMAT chooseD3DFormat(IDirect3DDevice9* d3d9Device);
 
-		/// @copydoc Resource::calculateSize
+		/**
+		 * @copydoc	Texture::calculateSize
+		 */
 		UINT32 calculateSize() const;
-		/// Creates this texture resources on the specified device.
+
+		/**
+		 * @brief	Creates internal resources for the texture for the specified device.
+		 */
 		void createInternalResources(IDirect3DDevice9* d3d9Device);
-		/// internal method, set Texture class final texture protected attributes
+
+		/**
+		 * @brief	Updates texture attributes with final attributes provided by the API after
+		 *			the texture has been created.
+		 */
 		void setFinalAttributes(IDirect3DDevice9* d3d9Device, TextureResources* textureResources, 
 			UINT32 width, UINT32 height, UINT32 depth, PixelFormat format);
-		/// internal method, return the best by hardware supported filter method
+
+		/**
+		 * @brief	Returns best texture filtering method.
+		 */
 		D3DTEXTUREFILTERTYPE getBestFilterMethod(IDirect3DDevice9* d3d9Device);
-		/// internal method, return true if the device/texture combination can use dynamic textures
+
+		/**
+		 * @brief	Returns if the specified combination of texture type, format and usage supports dynamic texture usage.
+		 */
 		bool canUseDynamicTextures(IDirect3DDevice9* d3d9Device, DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat);
-		/// internal method, return true if the device/texture combination can auto gen. mip maps
+
+		/**
+		 * @brief	Returns if the specified combination of texture type, format and usage supports automatic mipmap generation.
+		 */
 		bool canAutoGenMipmaps(IDirect3DDevice9* d3d9Device, DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat);
-		/// internal method, return true if the device/texture combination can use hardware gamma
+
+		/**
+		 * @brief	Returns if the specified combination of texture type, format and usage supports hardware gamma.
+		 */
 		bool canUseHardwareGammaCorrection(IDirect3DDevice9* d3d9Device, DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat, bool forwriting);
 
-		/// internal method, create D3D9HardwarePixelBuffers for every face and
-		/// mipmap level. This method must be called after the D3D texture object was created
+		/**
+		 * @brief	Creates a list of pixel buffers for all surfaces in the texture. This must be called after the texture
+		 *			has been created.
+		 */
 		void createSurfaceList(IDirect3DDevice9* d3d9Device, TextureResources* textureResources);
 	 
-		/// gets the texture resources attached to the given device.
+		/**
+		 * @brief	Retrieves texture resources for the device, or null if they don't exist.
+		 */
 		TextureResources* getTextureResources(IDirect3DDevice9* d3d9Device);
 
-		/// allocates new texture resources structure attached to the given device.
+		/**
+		 * @brief	Allocates a new set of texture resources for the device.
+		 */
 		TextureResources* allocateTextureResources(IDirect3DDevice9* d3d9Device);
 
-		/// frees the given texture resources.
+		/**
+		 * @brief	Frees all the given texture resources.
+		 */
 		void freeTextureResources(IDirect3DDevice9* d3d9Device, TextureResources* textureResources);
 
+		/**
+		 * @brief	Determines the pool in which to create the texture in.
+		 */
 		void determinePool();
 
 	protected:
-		/// Map between device to texture resources.
 		Map<IDirect3DDevice9*, TextureResources*> mMapDeviceToTextureResources;
 
-		/// Vector of pointers to subsurfaces
-		Vector<PixelBufferPtr>	mSurfaceList;
-		/// The memory pool being used
+		Vector<PixelBufferPtr> mSurfaceList;
+
 		D3DPOOL	mD3DPool;
-		// Dynamic textures?
 		bool mDynamicTextures;
 		bool mIsBindableAsShaderResource;
 
 		PixelBufferPtr mLockedBuffer;
 
-		/// Is hardware gamma supported (read)?
 		bool mHwGammaReadSupported;
-		/// Is hardware gamma supported (write)?
 		bool mHwGammaWriteSupported;
 		D3DMULTISAMPLE_TYPE mMultisampleType;
 		DWORD mMultisampleQuality;

+ 19 - 32
BansheeD3D9RenderSystem/Include/BsD3D9TextureManager.h

@@ -1,32 +1,4 @@
-/*
------------------------------------------------------------------------------
-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 __D3D9TEXTUREMANAGER_H__
-#define __D3D9TEXTUREMANAGER_H__
+#pragma once
 
 #include "BsD3D9Prerequisites.h"
 #include "BsD3D9Texture.h"
@@ -34,19 +6,34 @@ THE SOFTWARE.
 
 namespace BansheeEngine 
 {
+	/**
+	 * @brief	Handles creation of DirectX 9 textures.
+	 */
 	class BS_D3D9_EXPORT D3D9TextureManager : public TextureManager
 	{
 	public:
 		D3D9TextureManager();
 		~D3D9TextureManager();
 
-		/// @copydoc TextureManager::getNativeFormat
+		/**
+		 * @copydoc TextureManager::getNativeFormat
+		 */
 		PixelFormat getNativeFormat(TextureType ttype, PixelFormat format, int usage, bool hwGamma);
 
 	protected:	
+		/**
+		 * @copydoc TextureManager::createTextureImpl
+		 */
 		TexturePtr createTextureImpl();
+
+		/**
+		 * @copydoc TextureManager::createRenderTextureImpl
+		 */
 		RenderTexturePtr createRenderTextureImpl();
+
+		/**
+		 * @copydoc TextureManager::createMultiRenderTextureImpl
+		 */
 		MultiRenderTexturePtr createMultiRenderTextureImpl();
 	};
-}
-#endif
+}

+ 43 - 17
BansheeD3D9RenderSystem/Include/BsD3D9VertexBuffer.h

@@ -6,10 +6,15 @@
 
 namespace BansheeEngine 
 {
-    /// Specialisation of HardwareVertexBuffer for D3D9
+	/**
+	 * @brief	DirectX 9 implementation of a vertex buffer.
+	 */
     class BS_D3D9_EXPORT D3D9VertexBuffer : public VertexBuffer, public D3D9Resource
     {   
 	protected:
+		/**
+		 * @brief	Container for internal buffer resources.
+		 */
 		struct BufferResources
 		{
 			IDirect3DVertexBuffer9*	mBuffer;
@@ -21,9 +26,15 @@ namespace BansheeEngine
 
     public:
         ~D3D9VertexBuffer();
-        /** See HardwareBuffer. */
+
+		/**
+		 * @copydoc	VertexBuffer::readData
+		 */
         void readData(UINT32 offset, UINT32 length, void* dest);
-        /** See HardwareBuffer. */
+
+		/**
+		 * @copydoc	VertexBuffer::writeData
+		 */
         void writeData(UINT32 offset, UINT32 length, const void* source, BufferWriteType writeFlags = BufferWriteType::Normal);
 	
 		/**
@@ -46,12 +57,19 @@ namespace BansheeEngine
 		 */
 		virtual void notifyOnDeviceReset(IDirect3DDevice9* d3d9Device);
 
-		// Create the actual vertex buffer.
+		/**
+		 * @brief	Creates a DX9 vertex buffer object in the provided memory pool.
+		 */
 		void createBuffer(IDirect3DDevice9* d3d9Device, D3DPOOL pool);
 		
-        /// Get D3D9-specific vertex buffer
+		/**
+		 * @brief	Returns the DX9 vertex buffer object.
+		 */
         IDirect3DVertexBuffer9* getD3D9VertexBuffer();
 
+		/**
+		 * @copydoc	VertexBuffer::vertexColorReqRGBFlip
+		 */
 		virtual bool vertexColorReqRGBFlip() { return true; }
 
 	protected:	
@@ -59,26 +77,34 @@ namespace BansheeEngine
 
 		D3D9VertexBuffer(UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage, bool useSystemMem);
 	
-		/** See HardwareBuffer. */
-		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);		
-		/** See HardwareBuffer. */
-		void unlockImpl();			
-		// updates buffer resources from system memory buffer.
-		bool updateBufferResources(const UINT8* systemMemoryBuffer, BufferResources* bufferResources);		
-
 		/**
-		 * @copydoc VertexBuffer::initialize_internal()
+		 * @copydoc VertexBuffer::initialize_internal
 		 */
 		void initialize_internal();	
 		
 		/**
-		 * @copydoc VertexBuffer::destroy_internal()
+		 * @copydoc VertexBuffer::destroy_internal
 		 */
 		void destroy_internal();
 
+		/**
+		 * @copydoc	VertexBuffer::lockImpl
+		 */
+		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
+
+		/**
+		 * @copydoc	VertexBuffer::unlockImpl
+		 */
+		void unlockImpl();
+
+		/**
+		 * @brief	Updates buffer resources from cached system memory buffer.
+		 */
+		bool updateBufferResources(const UINT8* systemMemoryBuffer, BufferResources* bufferResources);		
+
 	protected:
-		Map<IDirect3DDevice9*, BufferResources*> mMapDeviceToBufferResources; // Map between device to buffer resources.
-		D3DVERTEXBUFFER_DESC mBufferDesc; // Buffer description.		
-		UINT8* mSystemMemoryBuffer; // Consistent system memory buffer for multiple devices support.
+		Map<IDirect3DDevice9*, BufferResources*> mMapDeviceToBufferResources;
+		D3DVERTEXBUFFER_DESC mBufferDesc;	
+		UINT8* mSystemMemoryBuffer;
     };
 }

+ 17 - 9
BansheeD3D9RenderSystem/Include/BsD3D9VertexDeclaration.h

@@ -6,19 +6,27 @@
 
 namespace BansheeEngine 
 { 
-    /** Specialisation of VertexDeclaration for D3D9 */
+	/**
+	 * @brief	DirectX 9 implementation of a vertex declaration.
+	 */
     class BS_D3D9_EXPORT D3D9VertexDeclaration : public VertexDeclaration, public D3D9Resource
     {
     public:
         ~D3D9VertexDeclaration();
         
-		// Called immediately after the Direct3D device has been created.
+		/**
+		 * @copydoc	D3D9Resource::notifyOnDeviceCreate
+		 */
 		virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
 
-		// Called before the Direct3D device is going to be destroyed.
+		/**
+		 * @copydoc	D3D9Resource::notifyOnDeviceDestroy
+		 */
 		virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
 
-        /** Gets the D3D9-specific vertex declaration. */
+		/**
+		 * @brief	Creates a DirectX 9 vertex declaration object.
+		 */
         IDirect3DVertexDeclaration9* getD3DVertexDeclaration();
 
 	protected:
@@ -26,17 +34,17 @@ namespace BansheeEngine
 
 		D3D9VertexDeclaration(const VertexDeclaration::VertexElementList& elements);
 
+		/**
+		 * @brief	Releases the internal DirectX 9 vertex declaration object.
+		 */
 		void releaseDeclaration();
 
 		/**
-		 * @copydoc VertexDeclaration::destroy_internal().
+		 * @copydoc	VertexDeclaration::destroy_internal
 		 */
 		void destroy_internal();
 
 	protected:        
-		typedef Map<IDirect3DDevice9*, IDirect3DVertexDeclaration9*>	DeviceToDeclarationMap;
-		typedef DeviceToDeclarationMap::iterator							DeviceToDeclarationIterator;
-
-		DeviceToDeclarationMap		mMapDeviceToDeclaration;
+		Map<IDirect3DDevice9*, IDirect3DVertexDeclaration9*> mMapDeviceToDeclaration;
     };
 }

+ 1 - 2
BansheeD3D9RenderSystem/Source/BsD3D9PixelBuffer.cpp

@@ -102,8 +102,7 @@ namespace BansheeEngine
 		}
 	}
 
-	void D3D9PixelBuffer::bind(IDirect3DDevice9* dev, IDirect3DSurface9* surface, bool writeGamma, 
-		UINT32 multisampleCount, const String& srcName, IDirect3DBaseTexture9* mipTex)
+	void D3D9PixelBuffer::bind(IDirect3DDevice9* dev, IDirect3DSurface9* surface, IDirect3DBaseTexture9* mipTex)
 	{
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 

+ 107 - 212
BansheeD3D9RenderSystem/Source/BsD3D9RenderSystem.cpp

@@ -29,43 +29,19 @@
 #include "BsD3D9QueryManager.h"
 #include "BsDebug.h"
 
-#define FLOAT2DWORD(f) *((DWORD*)&f)
-
-// Formats to try, in decreasing order of preference
-D3DFORMAT ddDepthStencilFormats[]={
-	D3DFMT_D24FS8,
-	D3DFMT_D24S8,
-	D3DFMT_D24X4S4,
-	D3DFMT_D24X8,
-	D3DFMT_D15S1,
-	D3DFMT_D16,
-	D3DFMT_D32
-};
-#define NDSFORMATS (sizeof(ddDepthStencilFormats)/sizeof(D3DFORMAT))
-
 namespace BansheeEngine 
 {
-	D3D9RenderSystem* D3D9RenderSystem::msD3D9RenderSystem = NULL;
+	D3D9RenderSystem* D3D9RenderSystem::msD3D9RenderSystem = nullptr;
 
-	D3D9RenderSystem::D3D9RenderSystem( HINSTANCE hInstance )
+	D3D9RenderSystem::D3D9RenderSystem(HINSTANCE hInstance)
 		: mTexStageDesc(nullptr), mNumTexStages(0), mCurrentDrawOperation(DOT_TRIANGLE_LIST), 
 		mViewportLeft(0), mViewportTop(0), mViewportWidth(0), mViewportHeight(0),
-		mIsFrameInProgress(false), mRestoreFrameOnReset(false)
+		mIsFrameInProgress(false), mRestoreFrameOnReset(false), mhInstance(hInstance),
+		mpD3D(nullptr), mDriverList(nullptr), mActiveD3DDriver(nullptr), mHLSLProgramFactory(nullptr),
+		mDeviceManager(nullptr), mResourceManager(nullptr)
 	{
-		// update singleton access pointer.
 		msD3D9RenderSystem = this;
 
-		// set the instance being passed 
-		mhInstance = hInstance;
-
-		// set pointers to NULL
-		mpD3D = NULL;		
-		mDriverList = NULL;
-		mActiveD3DDriver = NULL;	
-		mHLSLProgramFactory = NULL;		
-		mDeviceManager = NULL;	
-		mResourceManager = nullptr;	
-
 		mScissorRect.left = 0;
 		mScissorRect.right = 1280;
 		mScissorRect.top = 0;
@@ -256,7 +232,7 @@ namespace BansheeEngine
 		// This solves such an errors when working with the Debug runtime -
 		// "Direct3D9: (ERROR) :Stage 1 - Texture coordinate index in the stage must be equal to the stage index when programmable vertex pipeline is used".
 		for (unsigned int nStage=0; nStage < 8; ++nStage)
-			__SetTextureStageState(nStage, D3DTSS_TEXCOORDINDEX, nStage);
+			setTextureStageState(nStage, D3DTSS_TEXCOORDINDEX, nStage);
 
 		mRenderStats.numGpuProgramBinds++;
 
@@ -493,11 +469,11 @@ namespace BansheeEngine
 				// Set gamma now too
 				if (dt->isHardwareGammaReadToBeUsed())
 				{
-					__SetSamplerState(static_cast<DWORD>(unit), D3DSAMP_SRGBTEXTURE, TRUE);
+					setSamplerState(static_cast<DWORD>(unit), D3DSAMP_SRGBTEXTURE, TRUE);
 				}
 				else
 				{
-					__SetSamplerState(static_cast<DWORD>(unit), D3DSAMP_SRGBTEXTURE, FALSE);
+					setSamplerState(static_cast<DWORD>(unit), D3DSAMP_SRGBTEXTURE, FALSE);
 				}
 
 				mRenderStats.numTextureBinds++;
@@ -518,7 +494,7 @@ namespace BansheeEngine
 				mRenderStats.numTextureBinds++;
 			}
 
-			hr = __SetTextureStageState(static_cast<DWORD>(unit), D3DTSS_COLOROP, D3DTOP_DISABLE);
+			hr = setTextureStageState(static_cast<DWORD>(unit), D3DTSS_COLOROP, D3DTOP_DISABLE);
 			if( hr != S_OK )
 			{
 				String str = "Unable to disable texture '" + toString(unit) + "' in D3D9";
@@ -648,7 +624,7 @@ namespace BansheeEngine
 		if (mCurrentCapabilities->hasCapability(RSC_MIPMAP_LOD_BIAS))
 		{
 			// ugh - have to pass float data through DWORD with no conversion
-			HRESULT hr = __SetSamplerState(static_cast<DWORD>(unit), D3DSAMP_MIPMAPLODBIAS, 
+			HRESULT hr = setSamplerState(static_cast<DWORD>(unit), D3DSAMP_MIPMAPLODBIAS, 
 				*(DWORD*)&bias);
 			if(FAILED(hr))
 				BS_EXCEPT(RenderingAPIException, "Unable to set texture mipmap bias");
@@ -661,11 +637,11 @@ namespace BansheeEngine
 		THROW_IF_NOT_CORE_THREAD;
 
 		HRESULT hr;
-		if( FAILED( hr = __SetSamplerState( static_cast<DWORD>(stage), D3DSAMP_ADDRESSU, D3D9Mappings::get(uvw.u, mDeviceManager->getActiveDevice()->getD3D9DeviceCaps()) ) ) )
+		if( FAILED( hr = setSamplerState( static_cast<DWORD>(stage), D3DSAMP_ADDRESSU, D3D9Mappings::get(uvw.u, mDeviceManager->getActiveDevice()->getD3D9DeviceCaps()) ) ) )
 			BS_EXCEPT(RenderingAPIException, "Failed to set texture addressing mode for U" );
-		if( FAILED( hr = __SetSamplerState( static_cast<DWORD>(stage), D3DSAMP_ADDRESSV, D3D9Mappings::get(uvw.v, mDeviceManager->getActiveDevice()->getD3D9DeviceCaps()) ) ) )
+		if( FAILED( hr = setSamplerState( static_cast<DWORD>(stage), D3DSAMP_ADDRESSV, D3D9Mappings::get(uvw.v, mDeviceManager->getActiveDevice()->getD3D9DeviceCaps()) ) ) )
 			BS_EXCEPT(RenderingAPIException, "Failed to set texture addressing mode for V");
-		if( FAILED( hr = __SetSamplerState( static_cast<DWORD>(stage), D3DSAMP_ADDRESSW, D3D9Mappings::get(uvw.w, mDeviceManager->getActiveDevice()->getD3D9DeviceCaps()) ) ) )
+		if( FAILED( hr = setSamplerState( static_cast<DWORD>(stage), D3DSAMP_ADDRESSW, D3D9Mappings::get(uvw.w, mDeviceManager->getActiveDevice()->getD3D9DeviceCaps()) ) ) )
 			BS_EXCEPT(RenderingAPIException, "Failed to set texture addressing mode for W");
 	}
 
@@ -674,7 +650,7 @@ namespace BansheeEngine
 		THROW_IF_NOT_CORE_THREAD;
 
 		HRESULT hr;
-		if( FAILED( hr = __SetSamplerState( static_cast<DWORD>(stage), D3DSAMP_BORDERCOLOR, colour.getAsBGRA()) ) )
+		if( FAILED( hr = setSamplerState( static_cast<DWORD>(stage), D3DSAMP_BORDERCOLOR, colour.getAsBGRA()) ) )
 			BS_EXCEPT(RenderingAPIException, "Failed to set texture border colour");
 	}
 
@@ -685,24 +661,24 @@ namespace BansheeEngine
 		HRESULT hr;
 		if( sourceFactor == BF_ONE && destFactor == BF_ZERO)
 		{
-			if (FAILED(hr = __SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE)))
+			if (FAILED(hr = setRenderState(D3DRS_ALPHABLENDENABLE, FALSE)))
 				BS_EXCEPT(RenderingAPIException, "Failed to set alpha blending option");
 		}
 		else
 		{
-			if (FAILED(hr = __SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE)))
+			if (FAILED(hr = setRenderState(D3DRS_ALPHABLENDENABLE, TRUE)))
 				BS_EXCEPT(RenderingAPIException, "Failed to set alpha blending option");
-			if (FAILED(hr = __SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, FALSE)))
+			if (FAILED(hr = setRenderState(D3DRS_SEPARATEALPHABLENDENABLE, FALSE)))
 				BS_EXCEPT(RenderingAPIException, "Failed to set separate alpha blending option");
-			if( FAILED( hr = __SetRenderState( D3DRS_SRCBLEND, D3D9Mappings::get(sourceFactor) ) ) )
+			if( FAILED( hr = setRenderState( D3DRS_SRCBLEND, D3D9Mappings::get(sourceFactor) ) ) )
 				BS_EXCEPT(RenderingAPIException, "Failed to set source blend");
-			if( FAILED( hr = __SetRenderState( D3DRS_DESTBLEND, D3D9Mappings::get(destFactor) ) ) )
+			if( FAILED( hr = setRenderState( D3DRS_DESTBLEND, D3D9Mappings::get(destFactor) ) ) )
 				BS_EXCEPT(RenderingAPIException, "Failed to set destination blend");
 		}
 
-		if (FAILED(hr = __SetRenderState(D3DRS_BLENDOP, D3D9Mappings::get(op))))
+		if (FAILED(hr = setRenderState(D3DRS_BLENDOP, D3D9Mappings::get(op))))
 			BS_EXCEPT(RenderingAPIException, "Failed to set scene blending operation option");
-		if (FAILED(hr = __SetRenderState(D3DRS_BLENDOPALPHA, D3D9Mappings::get(op))))
+		if (FAILED(hr = setRenderState(D3DRS_BLENDOPALPHA, D3D9Mappings::get(op))))
 			BS_EXCEPT(RenderingAPIException, "Failed to set scene blending operation option");
 	}
 
@@ -715,28 +691,28 @@ namespace BansheeEngine
 		if( sourceFactor == BF_ONE && destFactor == BF_ZERO && 
 			sourceFactorAlpha == BF_ONE && destFactorAlpha == BF_ZERO)
 		{
-			if (FAILED(hr = __SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE)))
+			if (FAILED(hr = setRenderState(D3DRS_ALPHABLENDENABLE, FALSE)))
 				BS_EXCEPT(RenderingAPIException, "Failed to set alpha blending option");
 		}
 		else
 		{
-			if (FAILED(hr = __SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE)))
+			if (FAILED(hr = setRenderState(D3DRS_ALPHABLENDENABLE, TRUE)))
 				BS_EXCEPT(RenderingAPIException, "Failed to set alpha blending option");
-			if (FAILED(hr = __SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE)))
+			if (FAILED(hr = setRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE)))
 				BS_EXCEPT(RenderingAPIException, "Failed to set separate alpha blending option");
-			if( FAILED( hr = __SetRenderState( D3DRS_SRCBLEND, D3D9Mappings::get(sourceFactor) ) ) )
+			if( FAILED( hr = setRenderState( D3DRS_SRCBLEND, D3D9Mappings::get(sourceFactor) ) ) )
 				BS_EXCEPT(RenderingAPIException, "Failed to set source blend");
-			if( FAILED( hr = __SetRenderState( D3DRS_DESTBLEND, D3D9Mappings::get(destFactor) ) ) )
+			if( FAILED( hr = setRenderState( D3DRS_DESTBLEND, D3D9Mappings::get(destFactor) ) ) )
 				BS_EXCEPT(RenderingAPIException, "Failed to set destination blend");
-			if( FAILED( hr = __SetRenderState( D3DRS_SRCBLENDALPHA, D3D9Mappings::get(sourceFactorAlpha) ) ) )
+			if( FAILED( hr = setRenderState( D3DRS_SRCBLENDALPHA, D3D9Mappings::get(sourceFactorAlpha) ) ) )
 				BS_EXCEPT(RenderingAPIException, "Failed to set alpha source blend");
-			if( FAILED( hr = __SetRenderState( D3DRS_DESTBLENDALPHA, D3D9Mappings::get(destFactorAlpha) ) ) )
+			if( FAILED( hr = setRenderState( D3DRS_DESTBLENDALPHA, D3D9Mappings::get(destFactorAlpha) ) ) )
 				BS_EXCEPT(RenderingAPIException, "Failed to set alpha destination blend");
 		}
 
-		if (FAILED(hr = __SetRenderState(D3DRS_BLENDOP, D3D9Mappings::get(op))))
+		if (FAILED(hr = setRenderState(D3DRS_BLENDOP, D3D9Mappings::get(op))))
 			BS_EXCEPT(RenderingAPIException, "Failed to set scene blending operation option");
-		if (FAILED(hr = __SetRenderState(D3DRS_BLENDOPALPHA, D3D9Mappings::get(alphaOp))))
+		if (FAILED(hr = setRenderState(D3DRS_BLENDOPALPHA, D3D9Mappings::get(alphaOp))))
 			BS_EXCEPT(RenderingAPIException, "Failed to set alpha scene blending operation option");
 	}
 
@@ -748,18 +724,18 @@ namespace BansheeEngine
 
 		if (func != CMPF_ALWAYS_PASS)
 		{
-			if( FAILED( hr = __SetRenderState( D3DRS_ALPHATESTENABLE,  TRUE ) ) )
+			if( FAILED( hr = setRenderState( D3DRS_ALPHATESTENABLE,  TRUE ) ) )
 				BS_EXCEPT(RenderingAPIException, "Failed to enable alpha testing");
 		}
 		else
 		{
-			if( FAILED( hr = __SetRenderState( D3DRS_ALPHATESTENABLE,  FALSE ) ) )
+			if( FAILED( hr = setRenderState( D3DRS_ALPHATESTENABLE,  FALSE ) ) )
 				BS_EXCEPT(RenderingAPIException, "Failed to disable alpha testing");
 		}
 		// Set always just be sure
-		if( FAILED( hr = __SetRenderState( D3DRS_ALPHAFUNC, D3D9Mappings::get(func) ) ) )
+		if( FAILED( hr = setRenderState( D3DRS_ALPHAFUNC, D3D9Mappings::get(func) ) ) )
 			BS_EXCEPT(RenderingAPIException, "Failed to set alpha reject function");
-		if( FAILED( hr = __SetRenderState( D3DRS_ALPHAREF, value ) ) )
+		if( FAILED( hr = setRenderState( D3DRS_ALPHAREF, value ) ) )
 			BS_EXCEPT(RenderingAPIException, "Failed to set render state D3DRS_ALPHAREF");
 	}
 
@@ -778,12 +754,12 @@ namespace BansheeEngine
 			{
 				if (enable)
 				{
-					if( FAILED( hr = __SetRenderState( D3DRS_ADAPTIVETESS_Y,  (D3DFORMAT)MAKEFOURCC('A', 'T', 'O', 'C') ) ) )
+					if( FAILED( hr = setRenderState( D3DRS_ADAPTIVETESS_Y,  (D3DFORMAT)MAKEFOURCC('A', 'T', 'O', 'C') ) ) )
 						BS_EXCEPT(RenderingAPIException, "Failed to set alpha to coverage option");
 				}
 				else
 				{
-					if( FAILED( hr = __SetRenderState( D3DRS_ADAPTIVETESS_Y,  D3DFMT_UNKNOWN ) ) )
+					if( FAILED( hr = setRenderState( D3DRS_ADAPTIVETESS_Y,  D3DFMT_UNKNOWN ) ) )
 						BS_EXCEPT(RenderingAPIException, "Failed to set alpha to coverage option");
 				}
 
@@ -792,13 +768,13 @@ namespace BansheeEngine
 			{
 				if (enable)
 				{
-					if( FAILED( hr = __SetRenderState( D3DRS_POINTSIZE,  MAKEFOURCC('A','2','M','1') ) ) )
+					if( FAILED( hr = setRenderState( D3DRS_POINTSIZE,  MAKEFOURCC('A','2','M','1') ) ) )
 						BS_EXCEPT(RenderingAPIException, "Failed to set alpha to coverage option");
 				}
 				else
 				{
 					// discovered this through trial and error, seems to work
-					if( FAILED( hr = __SetRenderState( D3DRS_POINTSIZE,  MAKEFOURCC('A','2','M','0') ) ) )
+					if( FAILED( hr = setRenderState( D3DRS_POINTSIZE,  MAKEFOURCC('A','2','M','0') ) ) )
 						BS_EXCEPT(RenderingAPIException, "Failed to set alpha to coverage option");
 				}
 			}
@@ -814,20 +790,11 @@ namespace BansheeEngine
 		mCullingMode = mode;
 		HRESULT hr;
 
-		if( FAILED (hr = __SetRenderState(D3DRS_CULLMODE, 
+		if( FAILED (hr = setRenderState(D3DRS_CULLMODE, 
 			D3D9Mappings::get(mode, false))) )
 			BS_EXCEPT(RenderingAPIException, "Failed to set culling mode");
 	}
 
-	void D3D9RenderSystem::setDepthBufferParams(bool depthTest, bool depthWrite, CompareFunction depthFunction)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		setDepthBufferCheckEnabled( depthTest );
-		setDepthBufferWriteEnabled( depthWrite );
-		setDepthBufferFunction( depthFunction );
-	}
-
 	void D3D9RenderSystem::setDepthBufferCheckEnabled(bool enabled)
 	{
 		THROW_IF_NOT_CORE_THREAD;
@@ -835,9 +802,9 @@ namespace BansheeEngine
 		HRESULT hr;
 
 		if( enabled )
-			hr = __SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
+			hr = setRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
 		else
-			hr = __SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
+			hr = setRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
 
 		if(FAILED(hr))
 			BS_EXCEPT(RenderingAPIException, "Error setting depth buffer test state");
@@ -849,7 +816,7 @@ namespace BansheeEngine
 
 		HRESULT hr;
 
-		if( FAILED( hr = __SetRenderState( D3DRS_ZWRITEENABLE, enabled ) ) )
+		if( FAILED( hr = setRenderState( D3DRS_ZWRITEENABLE, enabled ) ) )
 			BS_EXCEPT(RenderingAPIException, "Error setting depth buffer write state");
 	}
 
@@ -858,7 +825,7 @@ namespace BansheeEngine
 		THROW_IF_NOT_CORE_THREAD;
 
 		HRESULT hr;
-		if( FAILED( hr = __SetRenderState( D3DRS_ZFUNC, D3D9Mappings::get(func) ) ) )
+		if( FAILED( hr = setRenderState( D3DRS_ZFUNC, D3D9Mappings::get(func) ) ) )
 			BS_EXCEPT(RenderingAPIException, "Error setting depth buffer test function");
 	}
 
@@ -872,7 +839,7 @@ namespace BansheeEngine
 			// D3D also expresses the constant bias as an absolute value, rather than 
 			// relative to minimum depth unit, so scale to fit
 			constantBias = -constantBias / 250000.0f;
-			HRESULT hr = __SetRenderState(D3DRS_DEPTHBIAS, FLOAT2DWORD(constantBias));
+			HRESULT hr = setRenderState(D3DRS_DEPTHBIAS, *((DWORD*)&constantBias));
 			if (FAILED(hr))
 				BS_EXCEPT(RenderingAPIException, "Error setting constant depth bias");
 		}
@@ -881,7 +848,7 @@ namespace BansheeEngine
 		{
 			// Negate bias since D3D is backward
 			slopeScaleBias = -slopeScaleBias;
-			HRESULT hr = __SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, FLOAT2DWORD(slopeScaleBias));
+			HRESULT hr = setRenderState(D3DRS_SLOPESCALEDEPTHBIAS, *((DWORD*)&slopeScaleBias));
 			if (FAILED(hr))
 				BS_EXCEPT(RenderingAPIException, "Error setting slope scale depth bias");
 		}
@@ -903,7 +870,7 @@ namespace BansheeEngine
 		if (alpha)
 			val |= D3DCOLORWRITEENABLE_ALPHA;
 
-		HRESULT hr = __SetRenderState(D3DRS_COLORWRITEENABLE, val); 
+		HRESULT hr = setRenderState(D3DRS_COLORWRITEENABLE, val); 
 		if (FAILED(hr))
 			BS_EXCEPT(RenderingAPIException, "Error setting colour write enable flags");
 	}
@@ -912,7 +879,7 @@ namespace BansheeEngine
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
-		HRESULT hr = __SetRenderState(D3DRS_FILLMODE, D3D9Mappings::get(level));
+		HRESULT hr = setRenderState(D3DRS_FILLMODE, D3D9Mappings::get(level));
 		if (FAILED(hr))
 			BS_EXCEPT(RenderingAPIException, "Error setting polygon mode.");
 	}
@@ -922,20 +889,20 @@ namespace BansheeEngine
 		THROW_IF_NOT_CORE_THREAD;
 
 		// Allow stencilling
-		HRESULT hr = __SetRenderState(D3DRS_STENCILENABLE, enabled);
+		HRESULT hr = setRenderState(D3DRS_STENCILENABLE, enabled);
 		if (FAILED(hr))
 			BS_EXCEPT(RenderingAPIException, "Error enabling / disabling stencilling.");
 
 		if (mCurrentCapabilities->hasCapability(RSC_TWO_SIDED_STENCIL))
 		{
-			hr = __SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, TRUE);
+			hr = setRenderState(D3DRS_TWOSIDEDSTENCILMODE, TRUE);
 
 			if (FAILED(hr))
 				BS_EXCEPT(RenderingAPIException, "Error setting 2-sided stencil mode.");
 		}
 		else
 		{
-			hr = __SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, FALSE);
+			hr = setRenderState(D3DRS_TWOSIDEDSTENCILMODE, FALSE);
 
 			if (FAILED(hr))
 				BS_EXCEPT(RenderingAPIException, "Error setting 1-sided stencil mode.");
@@ -952,34 +919,34 @@ namespace BansheeEngine
 		if (ccw)
 		{
 			// fail op
-			hr = __SetRenderState(D3DRS_CCW_STENCILFAIL, D3D9Mappings::get(stencilFailOp));
+			hr = setRenderState(D3DRS_CCW_STENCILFAIL, D3D9Mappings::get(stencilFailOp));
 			if (FAILED(hr))
 				BS_EXCEPT(RenderingAPIException, "Error setting stencil fail operation (ccw).");
 
 			// depth fail op
-			hr = __SetRenderState(D3DRS_CCW_STENCILZFAIL, D3D9Mappings::get(depthFailOp));
+			hr = setRenderState(D3DRS_CCW_STENCILZFAIL, D3D9Mappings::get(depthFailOp));
 			if (FAILED(hr))
 				BS_EXCEPT(RenderingAPIException, "Error setting stencil depth fail operation (ccw).");
 
 			// pass op
-			hr = __SetRenderState(D3DRS_CCW_STENCILPASS, D3D9Mappings::get(passOp));
+			hr = setRenderState(D3DRS_CCW_STENCILPASS, D3D9Mappings::get(passOp));
 			if (FAILED(hr))
 				BS_EXCEPT(RenderingAPIException, "Error setting stencil pass operation (ccw).");
 		}
 		else
 		{
 			// fail op
-			hr = __SetRenderState(D3DRS_STENCILFAIL, D3D9Mappings::get(stencilFailOp, true));
+			hr = setRenderState(D3DRS_STENCILFAIL, D3D9Mappings::get(stencilFailOp, true));
 			if (FAILED(hr))
 				BS_EXCEPT(RenderingAPIException, "Error setting stencil fail operation (cw).");
 
 			// depth fail op
-			hr = __SetRenderState(D3DRS_STENCILZFAIL, D3D9Mappings::get(depthFailOp, true));
+			hr = setRenderState(D3DRS_STENCILZFAIL, D3D9Mappings::get(depthFailOp, true));
 			if (FAILED(hr))
 				BS_EXCEPT(RenderingAPIException, "Error setting stencil depth fail operation (cw).");
 
 			// pass op
-			hr = __SetRenderState(D3DRS_STENCILPASS, D3D9Mappings::get(passOp, true));
+			hr = setRenderState(D3DRS_STENCILPASS, D3D9Mappings::get(passOp, true));
 			if (FAILED(hr))
 				BS_EXCEPT(RenderingAPIException, "Error setting stencil pass operation (cw).");
 		}
@@ -990,9 +957,9 @@ namespace BansheeEngine
 		HRESULT hr;
 		
 		if(ccw)
-			hr = __SetRenderState(D3DRS_CCW_STENCILFUNC, D3D9Mappings::get(func));
+			hr = setRenderState(D3DRS_CCW_STENCILFUNC, D3D9Mappings::get(func));
 		else
-			hr = __SetRenderState(D3DRS_STENCILFUNC, D3D9Mappings::get(func));
+			hr = setRenderState(D3DRS_STENCILFUNC, D3D9Mappings::get(func));
 
 		if (FAILED(hr))
 			BS_EXCEPT(RenderingAPIException, "Error setting stencil buffer test function.");
@@ -1000,7 +967,7 @@ namespace BansheeEngine
 
 	void D3D9RenderSystem::setStencilBufferReadMask(UINT32 mask)
 	{
-		HRESULT hr = __SetRenderState(D3DRS_STENCILMASK, mask);
+		HRESULT hr = setRenderState(D3DRS_STENCILMASK, mask);
 
 		if (FAILED(hr))
 			BS_EXCEPT(RenderingAPIException, "Error setting stencil buffer mask.");
@@ -1008,7 +975,7 @@ namespace BansheeEngine
 
 	void D3D9RenderSystem::setStencilBufferWriteMask(UINT32 mask)
 	{
-		HRESULT hr = __SetRenderState(D3DRS_STENCILWRITEMASK, mask);
+		HRESULT hr = setRenderState(D3DRS_STENCILWRITEMASK, mask);
 
 		if (FAILED(hr))
 			BS_EXCEPT(RenderingAPIException, "Error setting stencil buffer write mask.");
@@ -1018,7 +985,7 @@ namespace BansheeEngine
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
-		HRESULT hr = __SetRenderState(D3DRS_STENCILREF, refValue);
+		HRESULT hr = setRenderState(D3DRS_STENCILREF, refValue);
 		if (FAILED(hr))
 			BS_EXCEPT(RenderingAPIException, "Error setting stencil buffer reference value.");
 	}
@@ -1029,7 +996,7 @@ namespace BansheeEngine
 
 		HRESULT hr;
 		D3D9Mappings::D3DTexType texType = mTexStageDesc[unit].texType;
-		hr = __SetSamplerState( static_cast<DWORD>(unit), D3D9Mappings::get(ftype), 
+		hr = setSamplerState( static_cast<DWORD>(unit), D3D9Mappings::get(ftype), 
 			D3D9Mappings::get(ftype, filter, mDeviceManager->getActiveDevice()->getD3D9DeviceCaps(), texType));
 
 		if (FAILED(hr))
@@ -1044,8 +1011,8 @@ namespace BansheeEngine
 		if (static_cast<DWORD>(maxAnisotropy) > mDeviceManager->getActiveDevice()->getD3D9DeviceCaps().MaxAnisotropy)
 			maxAnisotropy = mDeviceManager->getActiveDevice()->getD3D9DeviceCaps().MaxAnisotropy;
 
-		if (_getCurrentAnisotropy(unit) != maxAnisotropy)
-			__SetSamplerState( static_cast<DWORD>(unit), D3DSAMP_MAXANISOTROPY, maxAnisotropy );
+		if (getCurrentAnisotropy(unit) != maxAnisotropy)
+			setSamplerState( static_cast<DWORD>(unit), D3DSAMP_MAXANISOTROPY, maxAnisotropy );
 	}
 
 	void D3D9RenderSystem::setRenderTarget(RenderTargetPtr target)
@@ -1141,7 +1108,7 @@ namespace BansheeEngine
 			BS_EXCEPT(RenderingAPIException, "Failed to set viewport.");
 
 		// Set sRGB write mode
-		__SetRenderState(D3DRS_SRGBWRITEENABLE, target->isHwGammaEnabled());
+		setRenderState(D3DRS_SRGBWRITEENABLE, target->isHwGammaEnabled());
 	}
 
 	void D3D9RenderSystem::beginFrame()
@@ -1297,7 +1264,7 @@ namespace BansheeEngine
 		HRESULT hr;
 		if (enable)
 		{
-			if (FAILED(hr = __SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE)))
+			if (FAILED(hr = setRenderState(D3DRS_SCISSORTESTENABLE, TRUE)))
 			{
 				BS_EXCEPT(RenderingAPIException, "Unable to enable scissor rendering state; " + getErrorDescription(hr));
 			}
@@ -1309,7 +1276,7 @@ namespace BansheeEngine
 		}
 		else
 		{
-			if (FAILED(hr = __SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE)))
+			if (FAILED(hr = setRenderState(D3DRS_SCISSORTESTENABLE, FALSE)))
 			{
 				BS_EXCEPT(RenderingAPIException, "Unable to disable scissor rendering state; " + getErrorDescription(hr));
 			}
@@ -1321,14 +1288,14 @@ namespace BansheeEngine
 		HRESULT hr;
 		if(enable)
 		{
-			if (FAILED(hr = __SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE)))
+			if (FAILED(hr = setRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE)))
 			{
 				BS_EXCEPT(RenderingAPIException, "Unable to enable multisample antialiasing. Error description: " + getErrorDescription(hr));
 			}
 		}
 		else
 		{
-			if (FAILED(hr = __SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, FALSE)))
+			if (FAILED(hr = setRenderState(D3DRS_MULTISAMPLEANTIALIAS, FALSE)))
 			{
 				BS_EXCEPT(RenderingAPIException, "Unable to disable multisample antialiasing. Error description: " + getErrorDescription(hr));
 			}
@@ -1340,14 +1307,14 @@ namespace BansheeEngine
 		HRESULT hr;
 		if(enable)
 		{
-			if (FAILED(hr = __SetRenderState(D3DRS_ANTIALIASEDLINEENABLE, TRUE)))
+			if (FAILED(hr = setRenderState(D3DRS_ANTIALIASEDLINEENABLE, TRUE)))
 			{
 				BS_EXCEPT(RenderingAPIException, "Unable to enable line antialiasing. Error description: " + getErrorDescription(hr));
 			}
 		}
 		else
 		{
-			if (FAILED(hr = __SetRenderState(D3DRS_ANTIALIASEDLINEENABLE, FALSE)))
+			if (FAILED(hr = setRenderState(D3DRS_ANTIALIASEDLINEENABLE, FALSE)))
 			{
 				BS_EXCEPT(RenderingAPIException, "Unable to disable line antialiasing. Error description: " + getErrorDescription(hr));
 			}
@@ -1430,14 +1397,7 @@ namespace BansheeEngine
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
-		IDirect3D9* pDirect3D9 = msD3D9RenderSystem->mpD3D;
-
-		if (pDirect3D9 == NULL)
-		{
-			BS_EXCEPT(InvalidParametersException, "Direct3D9 interface is NULL !!!");
-		}
-
-		return pDirect3D9;
+		return msD3D9RenderSystem->mpD3D;
 	}
 
 	UINT D3D9RenderSystem::getResourceCreationDeviceCount()
@@ -1455,7 +1415,7 @@ namespace BansheeEngine
 			return msD3D9RenderSystem->mDeviceManager->getDeviceCount();
 		}
 
-		BS_EXCEPT(InvalidParametersException, "Invalid resource creation policy !!!" );
+		BS_EXCEPT(InvalidParametersException, "Invalid resource creation policy.");
 
 		return 0;
 	}
@@ -1477,7 +1437,7 @@ namespace BansheeEngine
 		}
 		else
 		{
-			BS_EXCEPT(InvalidParametersException, "Invalid resource creation policy !!!" );
+			BS_EXCEPT(InvalidParametersException, "Invalid resource creation policy.");
 		}
 
 		return d3d9Device;
@@ -1492,10 +1452,8 @@ namespace BansheeEngine
 
 		d3d9Device = activeDevice->getD3D9Device();
 
-		if (d3d9Device == NULL)
-		{
-			BS_EXCEPT(InvalidParametersException, "Current d3d9 device is NULL !!!" );
-		}
+		if (d3d9Device == nullptr)
+			BS_EXCEPT(InvalidParametersException, "Current d3d9 device is null.");
 
 		return d3d9Device;
 	}	
@@ -1601,28 +1559,10 @@ namespace BansheeEngine
 		return D3DPT_TRIANGLELIST;
 	}
 
-	bool D3D9RenderSystem::_checkMultiSampleQuality(D3DMULTISAMPLE_TYPE type, DWORD *outQuality, D3DFORMAT format, 
-		UINT adapterNum, D3DDEVTYPE deviceType, BOOL fullScreen)
-	{
-		HRESULT hr;
-		hr = mpD3D->CheckDeviceMultiSampleType( 
-			adapterNum, 
-			deviceType, 
-			format, 
-			fullScreen, 
-			type, 
-			outQuality);
-
-		if (SUCCEEDED(hr))
-			return true;
-		else
-			return false;
-	}
-
 	RenderSystemCapabilities* D3D9RenderSystem::updateRenderSystemCapabilities(D3D9RenderWindow* renderWindow)
 	{			
 		RenderSystemCapabilities* rsc = mCurrentCapabilities;
-		if (rsc == NULL)
+		if (rsc == nullptr)
 			rsc = bs_new<RenderSystemCapabilities>();
 
 		rsc->setDriverVersion(mDriverVersion);
@@ -1661,7 +1601,7 @@ namespace BansheeEngine
 			// Check for hardware stencil support
 			d3d9Device->GetDepthStencilSurface(&pSurf);
 
-			if (pSurf != NULL)
+			if (pSurf != nullptr)
 			{
 				D3DSURFACE_DESC surfDesc;
 
@@ -1769,8 +1709,8 @@ namespace BansheeEngine
 		rsc->setCapability(RSC_TEXTURE_COMPRESSION);
 		rsc->setCapability(RSC_TEXTURE_COMPRESSION_DXT);
 
-		convertVertexShaderCaps(rsc);
-		convertPixelShaderCaps(rsc);
+		updateVertexShaderCaps(rsc);
+		updatePixelShaderCaps(rsc);
 
 		// Adapter details
 		const D3DADAPTER_IDENTIFIER9& adapterID = mActiveD3DDriver->getAdapterIdentifier();
@@ -1858,19 +1798,32 @@ namespace BansheeEngine
 		}
 
 
-		if (mCurrentCapabilities == NULL)
+		if (mCurrentCapabilities == nullptr)
 		{		
 			mCurrentCapabilities = rsc;
 			mCurrentCapabilities->addShaderProfile("hlsl");
 			mCurrentCapabilities->addShaderProfile("cg");
 
-			initialiseFromRenderSystemCapabilities(mCurrentCapabilities);
+			if (mCurrentCapabilities->isShaderProfileSupported("hlsl"))
+				GpuProgramManager::instance().addFactory(mHLSLProgramFactory);
+
+			mNumTexStages = mCurrentCapabilities->getNumCombinedTextureUnits();
+			mTexStageDesc = bs_newN<sD3DTextureStageDesc>(mNumTexStages);
+
+			// set stages desc. to defaults
+			for (UINT32 n = 0; n < mNumTexStages; n++)
+			{
+				mTexStageDesc[n].coordIndex = 0;
+				mTexStageDesc[n].texType = D3D9Mappings::D3D_TEX_TYPE_NORMAL;
+				mTexStageDesc[n].pTex = 0;
+				mTexStageDesc[n].pVertexTex = 0;
+			}
 		}
 
 		return rsc;
 	}
 
-	void D3D9RenderSystem::convertVertexShaderCaps(RenderSystemCapabilities* rsc) const
+	void D3D9RenderSystem::updateVertexShaderCaps(RenderSystemCapabilities* rsc) const
 	{
 		UINT16 major = 0xFF;
 		UINT16 minor = 0xFF;
@@ -1986,7 +1939,7 @@ namespace BansheeEngine
 		}
 	}
 
-	void D3D9RenderSystem::convertPixelShaderCaps(RenderSystemCapabilities* rsc) const
+	void D3D9RenderSystem::updatePixelShaderCaps(RenderSystemCapabilities* rsc) const
 	{
 		UINT16 major = 0xFF;
 		UINT16 minor = 0xFF;
@@ -2126,30 +2079,6 @@ namespace BansheeEngine
 		}
 	}
 
-	void D3D9RenderSystem::initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps)
-	{
-		if (caps->getRenderSystemName() != getName())
-		{
-			BS_EXCEPT(InvalidParametersException, 
-				"Trying to initialize D3D9RenderSystem from RenderSystemCapabilities that do not support Direct3D9");
-		}
-
-		if (caps->isShaderProfileSupported("hlsl"))
-			GpuProgramManager::instance().addFactory(mHLSLProgramFactory);
-
-		mNumTexStages = caps->getNumCombinedTextureUnits();
-		mTexStageDesc = bs_newN<sD3DTextureStageDesc>(mNumTexStages);
-
-		// set stages desc. to defaults
-		for (UINT32 n = 0; n < mNumTexStages; n++)
-		{
-			mTexStageDesc[n].coordIndex = 0;
-			mTexStageDesc[n].texType = D3D9Mappings::D3D_TEX_TYPE_NORMAL;
-			mTexStageDesc[n].pTex = 0;
-			mTexStageDesc[n].pVertexTex = 0;
-		}
-	}
-
 	bool D3D9RenderSystem::checkTextureFilteringSupported(TextureType ttype, PixelFormat format, int usage)
 	{
 		// Gets D3D format
@@ -2226,7 +2155,7 @@ namespace BansheeEngine
 	{
 		DWORD prev;
 		getActiveD3D9Device()->GetRenderState(D3DRS_CLIPPLANEENABLE, &prev);
-		__SetRenderState(D3DRS_CLIPPLANEENABLE, enable?
+		setRenderState(D3DRS_CLIPPLANEENABLE, enable?
 			(prev | (1 << index)) : (prev & ~(1 << index)));
 	}
 
@@ -2332,7 +2261,7 @@ namespace BansheeEngine
 				deviceDriver->getAdapterNumber(), 
 				D3DDEVTYPE_HAL, 
 				d3dPixelFormat, 
-				fullScreen, 
+				!fullScreen, 
 				*outMultisampleType, 
 				&outQuality);
 
@@ -2378,11 +2307,6 @@ namespace BansheeEngine
 		} // while !ok
 	}
 
-	RenderSystemCapabilities* D3D9RenderSystem::createRenderSystemCapabilities() const
-	{
-		return mCurrentCapabilities;
-	}
-
 	void D3D9RenderSystem::setClipPlanesImpl(const PlaneList& clipPlanes)
 	{
 		size_t i;
@@ -2412,61 +2336,32 @@ namespace BansheeEngine
 			mask |= (1 << i);
 		}
 
-		hr = __SetRenderState(D3DRS_CLIPPLANEENABLE, mask);
+		hr = setRenderState(D3DRS_CLIPPLANEENABLE, mask);
 		if (FAILED(hr))
 		{
 			BS_EXCEPT(RenderingAPIException, "Unable to set render state for clip planes");
 		}
 	}
 
-	HRESULT D3D9RenderSystem::__SetRenderState(D3DRENDERSTATETYPE state, DWORD value)
+	HRESULT D3D9RenderSystem::setRenderState(D3DRENDERSTATETYPE state, DWORD value)
 	{
-		HRESULT hr;
-		DWORD oldVal;
-
-		if ( FAILED( hr = getActiveD3D9Device()->GetRenderState(state, &oldVal) ) )
-			return hr;
-		if ( oldVal == value )
-			return D3D_OK;
-		else
-			return getActiveD3D9Device()->SetRenderState(state, value);
+		return getActiveD3D9Device()->SetRenderState(state, value);
 	}
 
-	HRESULT D3D9RenderSystem::__SetSamplerState(DWORD sampler, D3DSAMPLERSTATETYPE type, DWORD value)
+	HRESULT D3D9RenderSystem::setSamplerState(DWORD sampler, D3DSAMPLERSTATETYPE type, DWORD value)
 	{
-		HRESULT hr;
-		DWORD oldVal;
-
-		if ( FAILED( hr = getActiveD3D9Device()->GetSamplerState(sampler, type, &oldVal) ) )
-			return hr;
-		if ( oldVal == value )
-			return D3D_OK;
-		else
-			return getActiveD3D9Device()->SetSamplerState(sampler, type, value);
+		return getActiveD3D9Device()->SetSamplerState(sampler, type, value);
 	}
 
-	HRESULT D3D9RenderSystem::__SetTextureStageState(DWORD stage, D3DTEXTURESTAGESTATETYPE type, DWORD value)
+	HRESULT D3D9RenderSystem::setTextureStageState(DWORD stage, D3DTEXTURESTAGESTATETYPE type, DWORD value)
 	{
-		HRESULT hr;
-		DWORD oldVal;
-
-		// can only set fixed-function texture stage state
 		if (stage < 8)
-		{
-			if ( FAILED( hr = getActiveD3D9Device()->GetTextureStageState(stage, type, &oldVal) ) )
-				return hr;
-			if ( oldVal == value )
-				return D3D_OK;
-			else
-				return getActiveD3D9Device()->SetTextureStageState(stage, type, value);
-		}
+			return getActiveD3D9Device()->SetTextureStageState(stage, type, value);
 		else
-		{
 			return D3D_OK;
-		}
 	}
 
-	DWORD D3D9RenderSystem::_getCurrentAnisotropy(UINT32 unit)
+	DWORD D3D9RenderSystem::getCurrentAnisotropy(UINT32 unit)
 	{
 		DWORD oldVal;
 		getActiveD3D9Device()->GetSamplerState(static_cast<DWORD>(unit), D3DSAMP_MAXANISOTROPY, &oldVal);

+ 5 - 9
BansheeD3D9RenderSystem/Source/BsD3D9RenderWindow.cpp

@@ -163,7 +163,7 @@ namespace BansheeEngine
 				dwStyle = mWindowedStyle;
 				dwStyleEx = mWindowedStyleEx;
 
-				_adjustWindow(mDesc.videoMode.getWidth(), mDesc.videoMode.getHeight(), dwStyle, &winWidth, &winHeight);
+				getAdjustedWindowSize(mDesc.videoMode.getWidth(), mDesc.videoMode.getHeight(), dwStyle, &winWidth, &winHeight);
 
 				if (!mDesc.outerDimensions)
 				{
@@ -311,7 +311,7 @@ namespace BansheeEngine
 		mHeight = height;
 
 		unsigned int winWidth, winHeight;
-		_adjustWindow(mWidth, mHeight, mStyle, &winWidth, &winHeight);
+		getAdjustedWindowSize(mWidth, mHeight, mStyle, &winWidth, &winHeight);
 
 		// Deal with centering when switching down to smaller resolution
 		HMONITOR hMonitor = MonitorFromWindow(mHWnd, MONITOR_DEFAULTTONEAREST);
@@ -386,7 +386,7 @@ namespace BansheeEngine
 			mHeight = height;
 
 			unsigned int winWidth, winHeight;
-			_adjustWindow(width, height, mStyle, &winWidth, &winHeight);
+			getAdjustedWindowSize(width, height, mStyle, &winWidth, &winHeight);
 
 			SetWindowPos(mHWnd, 0, 0, 0, winWidth, winHeight,
 				SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
@@ -489,20 +489,17 @@ namespace BansheeEngine
 	/* 						D3D9 IMPLEMENTATION SPECIFIC                    */
 	/************************************************************************/
 
-	void D3D9RenderWindow::_adjustWindow(unsigned int clientWidth, unsigned int clientHeight, 
-		DWORD style, unsigned int* winWidth, unsigned int* winHeight)
+	void D3D9RenderWindow::getAdjustedWindowSize(UINT32 clientWidth, UINT32 clientHeight,
+		DWORD style, UINT32* winWidth, UINT32* winHeight)
 	{
-		// NB only call this for non full screen
 		RECT rc;
 		SetRect(&rc, 0, 0, clientWidth, clientHeight);
 		AdjustWindowRect(&rc, style, false);
 		*winWidth = rc.right - rc.left;
 		*winHeight = rc.bottom - rc.top;
 
-		// adjust to monitor
 		HMONITOR hMonitor = MonitorFromWindow(mHWnd, MONITOR_DEFAULTTONEAREST);
 
-		// Get monitor info	
 		MONITORINFO monitorInfo;
 
 		memset(&monitorInfo, 0, sizeof(MONITORINFO));
@@ -516,7 +513,6 @@ namespace BansheeEngine
 			*winWidth = maxW;
 		if (*winHeight > (unsigned int)maxH)
 			*winHeight = maxH;
-
 	}
 	
 	void D3D9RenderWindow::_buildPresentParameters(D3DPRESENT_PARAMETERS* presentParams) const

+ 5 - 9
BansheeD3D9RenderSystem/Source/BsD3D9Texture.cpp

@@ -747,7 +747,7 @@ namespace BansheeEngine
 		HRESULT hr = d3d9Device->GetDirect3D(&pD3D);
 		if (FAILED(hr))
 		{
-			BS_EXCEPT(InvalidParametersException, "GetDirect3D failed !!!");
+			BS_EXCEPT(InvalidParametersException, "GetDirect3D failed.");
 		}
 
 		if (pD3D != nullptr)
@@ -833,8 +833,7 @@ namespace BansheeEngine
 
 			D3D9PixelBuffer* currPixelBuffer = static_cast<D3D9PixelBuffer*>(mSurfaceList[0].get());
 
-			currPixelBuffer->bind(d3d9Device, textureResources->pMultisampleSurface,
-				mHwGammaWriteSupported, mMultisampleCount, "", textureResources->pBaseTex);
+			currPixelBuffer->bind(d3d9Device, textureResources->pMultisampleSurface, textureResources->pBaseTex);
 		}
 		else if((mUsage & TU_DEPTHSTENCIL) != 0 && (mMultisampleType != D3DMULTISAMPLE_NONE))
 		{
@@ -843,8 +842,7 @@ namespace BansheeEngine
 
 			D3D9PixelBuffer* currPixelBuffer = static_cast<D3D9PixelBuffer*>(mSurfaceList[0].get());
 
-			currPixelBuffer->bind(d3d9Device, textureResources->pDepthStencilSurface,
-				mHwGammaWriteSupported, mMultisampleCount, "", textureResources->pBaseTex);
+			currPixelBuffer->bind(d3d9Device, textureResources->pDepthStencilSurface, textureResources->pBaseTex);
 		}
 		else
 		{
@@ -870,8 +868,7 @@ namespace BansheeEngine
 
 					D3D9PixelBuffer* currPixelBuffer = static_cast<D3D9PixelBuffer*>(mSurfaceList[mip].get());
 
-					currPixelBuffer->bind(d3d9Device, surface,
-						mHwGammaWriteSupported, mMultisampleCount, "", textureResources->pBaseTex);
+					currPixelBuffer->bind(d3d9Device, surface, textureResources->pBaseTex);
 
 					surface->Release();			
 				}
@@ -890,8 +887,7 @@ namespace BansheeEngine
 						UINT32 idx = face*(mNumMipmaps + 1) + mip;
 						D3D9PixelBuffer* currPixelBuffer = static_cast<D3D9PixelBuffer*>(mSurfaceList[idx].get());
 
-						currPixelBuffer->bind(d3d9Device, surface,
-							mHwGammaWriteSupported, mMultisampleCount, "", textureResources->pBaseTex);
+						currPixelBuffer->bind(d3d9Device, surface, textureResources->pBaseTex);
 
 						surface->Release();				
 					}				

+ 0 - 27
BansheeD3D9RenderSystem/Source/BsD3D9TextureManager.cpp

@@ -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.
------------------------------------------------------------------------------
-*/
 #include "BsD3D9TextureManager.h"
 #include "BsD3D9Texture.h"
 #include "BsD3D9RenderTexture.h"

+ 3 - 30
BansheeD3D9RenderSystem/Source/BsD3D9VertexDeclaration.cpp

@@ -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.
------------------------------------------------------------------------------
-*/
 #include "BsD3D9VertexDeclaration.h"
 #include "BsD3D9Mappings.h"
 #include "BsException.h"
@@ -56,7 +29,7 @@ namespace BansheeEngine
 	{
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
-		DeviceToDeclarationIterator it = mMapDeviceToDeclaration.find(d3d9Device);
+		auto it = mMapDeviceToDeclaration.find(d3d9Device);
 
 		if (it != mMapDeviceToDeclaration.end())	
 		{
@@ -68,7 +41,7 @@ namespace BansheeEngine
     IDirect3DVertexDeclaration9* D3D9VertexDeclaration::getD3DVertexDeclaration()
     {
 		IDirect3DDevice9* pCurDevice   = D3D9RenderSystem::getActiveD3D9Device();
-		DeviceToDeclarationIterator it = mMapDeviceToDeclaration.find(pCurDevice);
+		auto it = mMapDeviceToDeclaration.find(pCurDevice);
 		IDirect3DVertexDeclaration9* lpVertDecl = NULL;
 
 		// Case we have to create the declaration for this device.
@@ -130,7 +103,7 @@ namespace BansheeEngine
 	{
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
-		DeviceToDeclarationIterator it = mMapDeviceToDeclaration.begin();
+		auto it = mMapDeviceToDeclaration.begin();
 
 		while (it != mMapDeviceToDeclaration.end())
 		{

+ 1 - 1
BansheeEditorExec/BsEditorExec.cpp

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