Prechádzať zdrojové kódy

Bunch more methods ported to use render system context

Marko Pintera 13 rokov pred
rodič
commit
aa4ba9a93f

+ 53 - 63
CamelotD3D9Renderer/Include/CmD3D9RenderSystem.h

@@ -171,7 +171,17 @@ namespace CamelotEngine
 		ZBufferHash mZBufferHash;		
 
 	protected:
-		void setClipPlanesImpl(const PlaneList& clipPlanes);		
+		void setClipPlanesImpl(const PlaneList& clipPlanes);	
+
+		/// @copydoc RenderSystem::createMultiRenderTarget
+		virtual MultiRenderTarget * createMultiRenderTarget_internal(const String & name);
+
+		/**
+         * Set current render target to target, enabling its GL context if needed
+         */
+		void setRenderTarget_internal(RenderTarget *target);
+
+		String getErrorDescription_internal( long errorNumber ) const;
 	public:
 		// constructor
 		D3D9RenderSystem( HINSTANCE hInstance );
@@ -180,59 +190,59 @@ namespace CamelotEngine
 
 		virtual void initConfigOptions();
 		
-		/**
-         * Set current render target to target, enabling its GL context if needed
-         */
-		void setRenderTarget(RenderTarget *target);
-		
-		/// @copydoc RenderSystem::createMultiRenderTarget
-		virtual MultiRenderTarget * createMultiRenderTarget(const String & name);
-
-		String getErrorDescription( long errorNumber ) const;
 		const String& getName() const;
 		void shutdown();
-		void destroyRenderTarget(const String& name);
 		VertexElementType getColorVertexElementType() const;
-		void setStencilCheckEnabled(bool enabled);
-        void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 
+		void setStencilCheckEnabled_internal(bool enabled);
+        void setStencilBufferParams_internal(CompareFunction func = CMPF_ALWAYS_PASS, 
             UINT32 refValue = 0, UINT32 mask = 0xFFFFFFFF, 
             StencilOperation stencilFailOp = SOP_KEEP, 
             StencilOperation depthFailOp = SOP_KEEP,
             StencilOperation passOp = SOP_KEEP, 
             bool twoSidedOperation = false);
 
+		void startUp_internal();
+		void createRenderWindow_internal(const String &name, unsigned int width, unsigned int height, 
+			bool fullScreen, const NameValuePairList& miscParams, AsyncOp& asyncOp);
+		void destroyRenderTarget_internal(const String& name);
+
+		void bindGpuProgram_internal(GpuProgramRef prg);
+		void unbindGpuProgram_internal(GpuProgramType gptype);
+		void bindGpuProgramParameters_internal(GpuProgramType gptype, 
+			GpuProgramParametersSharedPtr params, UINT16 variabilityMask);
+
 		// Low-level overridden members, mainly for internal use
-		void setPointParameters(float size, bool attenuationEnabled, 
+		void setPointParameters_internal(float size, bool attenuationEnabled, 
 			float constant, float linear, float quadratic, float minSize, float maxSize);
-		void setTexture(size_t unit, bool enabled, const TexturePtr &texPtr);
-		void setVertexTexture(size_t unit, const TexturePtr& tex);
-		void disableTextureUnit(size_t texUnit);
-        void setTextureAddressingMode(size_t stage, const SamplerState::UVWAddressingMode& uvw);
-        void setTextureBorderColor(size_t stage, const Color& colour);
-		void setTextureMipmapBias(size_t unit, float bias);
-		void setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
-		void setSeparateSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
-		void setAlphaRejectSettings( CompareFunction func, unsigned char value, bool alphaToCoverage );
-		void setViewport(const Viewport& vp);		
-		void beginFrame();
-		void endFrame();		
-		void setCullingMode( CullingMode mode );
-		void setDepthBufferParams( bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL );
-		void setDepthBufferCheckEnabled( bool enabled = true );
-		void setColorBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
-		void setDepthBufferWriteEnabled(bool enabled = true);
-		void setDepthBufferFunction( CompareFunction func = CMPF_LESS_EQUAL );
-		void setDepthBias(float constantBias, float slopeScaleBias);
-		void _convertProjectionMatrix(const Matrix4& matrix, Matrix4& dest, bool forGpuProgram = false);
-		void setPolygonMode(PolygonMode level);
-        void setTextureFiltering(size_t unit, FilterType ftype, FilterOptions filter);
-		void setTextureAnisotropy(size_t unit, unsigned int maxAnisotropy);
-		void setVertexDeclaration(VertexDeclarationPtr decl);
-		void setVertexBufferBinding(VertexBufferBinding* binding);
-        void render(const RenderOperation& op);
-
-        void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600);
-        void clearFrameBuffer(unsigned int buffers, 
+		void setTexture_internal(size_t unit, bool enabled, const TexturePtr &texPtr);
+		void setVertexTexture_internal(size_t unit, const TexturePtr& tex);
+		void disableTextureUnit_internal(size_t texUnit);
+        void setTextureAddressingMode_internal(size_t stage, const SamplerState::UVWAddressingMode& uvw);
+        void setTextureBorderColor_internal(size_t stage, const Color& colour);
+		void setTextureMipmapBias_internal(size_t unit, float bias);
+		void setSceneBlending_internal( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
+		void setSeparateSceneBlending_internal( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
+		void setAlphaRejectSettings_internal( CompareFunction func, unsigned char value, bool alphaToCoverage );
+		void setViewport_internal(const Viewport& vp);		
+		void beginFrame_internal();
+		void endFrame_internal();		
+		void setCullingMode_internal( CullingMode mode );
+		void setDepthBufferParams_internal( bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL );
+		void setDepthBufferCheckEnabled_internal( bool enabled = true );
+		void setColorBufferWriteEnabled_internal(bool red, bool green, bool blue, bool alpha);
+		void setDepthBufferWriteEnabled_internal(bool enabled = true);
+		void setDepthBufferFunction_internal( CompareFunction func = CMPF_LESS_EQUAL );
+		void setDepthBias_internal(float constantBias, float slopeScaleBias);
+		void convertProjectionMatrix(const Matrix4& matrix, Matrix4& dest, bool forGpuProgram = false);
+		void setPolygonMode_internal(PolygonMode level);
+        void setTextureFiltering_internal(size_t unit, FilterType ftype, FilterOptions filter);
+		void setTextureAnisotropy_internal(size_t unit, unsigned int maxAnisotropy);
+		void setVertexDeclaration_internal(VertexDeclarationPtr decl);
+		void setVertexBufferBinding_internal(VertexBufferBinding* binding);
+        void render_internal(const RenderOperation& op);
+
+        void setScissorTest_internal(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600);
+        void clearFrameBuffer_internal(unsigned int buffers, 
             const Color& colour = Color::Black, 
             float depth = 1.0f, unsigned short stencil = 0);
 		void setClipPlane (UINT16 index, float A, float B, float C, float D);
@@ -278,26 +288,6 @@ namespace CamelotEngine
 		void determineFSAASettings(IDirect3DDevice9* d3d9Device, size_t fsaa, const String& fsaaHint, D3DFORMAT d3dPixelFormat, 
 			bool fullScreen, D3DMULTISAMPLE_TYPE *outMultisampleType, DWORD *outMultisampleQuality);
 
-		/// @copydoc RenderSystem::getDisplayMonitorCount
-		unsigned int getDisplayMonitorCount() const;
-		
-		/************************************************************************/
-		/* 							INTERNAL CALLBACKS                     		*/
-		/************************************************************************/
-	protected:
-		void startUp_internal();
-
-		void createRenderWindow_internal(const String &name, unsigned int width, unsigned int height, 
-			bool fullScreen, const NameValuePairList& miscParams, AsyncOp& asyncOp);
-
-
-        void bindGpuProgram_internal(GpuProgramRef prg);
-
-        void unbindGpuProgram_internal(GpuProgramType gptype);
-
-		void bindGpuProgramParameters_internal(GpuProgramType gptype, 
-			GpuProgramParametersSharedPtr params, UINT16 variabilityMask);
-
 	protected:	
 		/// Notify when a device has been lost.
 		void notifyOnDeviceLost(D3D9Device* device);

+ 1 - 1
CamelotD3D9Renderer/Source/CmD3D9HLSLProgram.cpp

@@ -543,7 +543,7 @@ namespace CamelotEngine {
 		String hlslProfile = GpuProgramManager::instance().gpuProgProfileToRSSpecificProfile(mProfile);
 
 		RenderSystem* rs = CamelotEngine::RenderSystemManager::getActive();
-		return rs->getCapabilities()->isShaderProfileSupported(hlslProfile);
+		return rs->getCapabilities_internal()->isShaderProfileSupported(hlslProfile);
     }
     //-----------------------------------------------------------------------
     GpuProgramParametersSharedPtr D3D9HLSLProgram::createParameters(void)

+ 2 - 2
CamelotD3D9Renderer/Source/CmD3D9HardwarePixelBuffer.cpp

@@ -942,7 +942,7 @@ void D3D9HardwarePixelBuffer::updateRenderTexture(bool writeGamma, UINT32 fsaa,
 
 		mRenderTexture = new D3D9RenderTexture(name, this, writeGamma, fsaa);		
 
-		CamelotEngine::RenderSystemManager::getActive()->attachRenderTarget(*mRenderTexture);
+		CamelotEngine::RenderSystemManager::getActive()->attachRenderTarget_internal(*mRenderTexture);
 	}
 }
 //-----------------------------------------------------------------------------    
@@ -950,7 +950,7 @@ void D3D9HardwarePixelBuffer::destroyRenderTexture()
 {
 	if (mRenderTexture != NULL)
 	{
-		CamelotEngine::RenderSystemManager::getActive()->destroyRenderTarget(mRenderTexture->getName());
+		CamelotEngine::RenderSystemManager::getActive()->destroyRenderTarget_internal(mRenderTexture->getName());
 		mRenderTexture = NULL;
 	}
 }

+ 1 - 1
CamelotD3D9Renderer/Source/CmD3D9MultiRenderTarget.cpp

@@ -70,7 +70,7 @@ namespace CamelotEngine
 				CM_EXCEPT(InvalidParametersException, "MultiRenderTarget surfaces are not of same size");
 			}
 
-			if (!CamelotEngine::RenderSystemManager::getActive()->getCapabilities()->hasCapability(RSC_MRT_DIFFERENT_BIT_DEPTHS)
+			if (!CamelotEngine::RenderSystemManager::getActive()->getCapabilities_internal()->hasCapability(RSC_MRT_DIFFERENT_BIT_DEPTHS)
 				&& (PixelUtil::getNumElemBits(mRenderTargets[y]->getFormat()) != 
 				PixelUtil::getNumElemBits(buffer->getFormat())))
 			{

+ 56 - 62
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -1044,16 +1044,16 @@ namespace CamelotEngine
 		return true;		
 	}
 	//-----------------------------------------------------------------------
-	MultiRenderTarget * D3D9RenderSystem::createMultiRenderTarget(const String & name)
+	MultiRenderTarget * D3D9RenderSystem::createMultiRenderTarget_internal(const String & name)
 	{
 		MultiRenderTarget *retval;
 		retval = new D3D9MultiRenderTarget(name);
-		attachRenderTarget(*retval);
+		attachRenderTarget_internal(*retval);
 
 		return retval;
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::destroyRenderTarget(const String& name)
+	void D3D9RenderSystem::destroyRenderTarget_internal(const String& name)
 	{		
 		D3D9RenderWindow* renderWindow = NULL;
 
@@ -1072,11 +1072,11 @@ namespace CamelotEngine
 		
 
 		// Do the real removal
-		RenderSystem::destroyRenderTarget(name);	
+		RenderSystem::destroyRenderTarget_internal(name);	
 	}
 
 	//---------------------------------------------------------------------
-	String D3D9RenderSystem::getErrorDescription( long errorNumber ) const
+	String D3D9RenderSystem::getErrorDescription_internal( long errorNumber ) const
 	{
 		const String errMsg = DXGetErrorDescription( errorNumber );
 		return errMsg;
@@ -1087,7 +1087,7 @@ namespace CamelotEngine
 		return VET_COLOUR_ARGB;
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::_convertProjectionMatrix(const Matrix4& matrix,
+	void D3D9RenderSystem::convertProjectionMatrix(const Matrix4& matrix,
 		Matrix4& dest, bool forGpuProgram)
 	{
 		dest = matrix;
@@ -1108,7 +1108,7 @@ namespace CamelotEngine
 		}
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setPointParameters(float size, 
+	void D3D9RenderSystem::setPointParameters_internal(float size, 
 		bool attenuationEnabled, float constant, float linear, float quadratic,
 		float minSize, float maxSize)
 	{
@@ -1134,7 +1134,7 @@ namespace CamelotEngine
 
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setTexture( size_t stage, bool enabled, const TexturePtr& tex )
+	void D3D9RenderSystem::setTexture_internal( size_t stage, bool enabled, const TexturePtr& tex )
 	{
 		HRESULT hr;
 		D3D9TexturePtr dt = std::static_pointer_cast<D3D9Texture>(tex);
@@ -1192,7 +1192,7 @@ namespace CamelotEngine
 		}
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setVertexTexture(size_t stage, const TexturePtr& tex)
+	void D3D9RenderSystem::setVertexTexture_internal(size_t stage, const TexturePtr& tex)
 	{
 		if (tex == nullptr)
 		{
@@ -1233,15 +1233,15 @@ namespace CamelotEngine
 
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::disableTextureUnit(size_t texUnit)
+	void D3D9RenderSystem::disableTextureUnit_internal(size_t texUnit)
 	{
-		RenderSystem::disableTextureUnit(texUnit);
+		RenderSystem::disableTextureUnit_internal(texUnit);
 		// also disable vertex texture unit
 		static TexturePtr nullPtr;
-		setVertexTexture(texUnit, nullPtr);
+		setVertexTexture_internal(texUnit, nullPtr);
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setTextureMipmapBias(size_t unit, float bias)
+	void D3D9RenderSystem::setTextureMipmapBias_internal(size_t unit, float bias)
 	{
 		if (mCurrentCapabilities->hasCapability(RSC_MIPMAP_LOD_BIAS))
 		{
@@ -1254,7 +1254,7 @@ namespace CamelotEngine
 		}
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setTextureAddressingMode( size_t stage, 
+	void D3D9RenderSystem::setTextureAddressingMode_internal( size_t stage, 
 		const SamplerState::UVWAddressingMode& uvw )
 	{
 		HRESULT hr;
@@ -1266,7 +1266,7 @@ namespace CamelotEngine
 			CM_EXCEPT(RenderingAPIException, "Failed to set texture addressing mode for W");
 	}
 	//-----------------------------------------------------------------------------
-	void D3D9RenderSystem::setTextureBorderColor(size_t stage,
+	void D3D9RenderSystem::setTextureBorderColor_internal(size_t stage,
 		const Color& colour)
 	{
 		HRESULT hr;
@@ -1274,7 +1274,7 @@ namespace CamelotEngine
 			CM_EXCEPT(RenderingAPIException, "Failed to set texture border colour");
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op )
+	void D3D9RenderSystem::setSceneBlending_internal( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op )
 	{
 		HRESULT hr;
 		if( sourceFactor == SBF_ONE && destFactor == SBF_ZERO)
@@ -1300,7 +1300,7 @@ namespace CamelotEngine
 			CM_EXCEPT(RenderingAPIException, "Failed to set scene blending operation option");
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setSeparateSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, 
+	void D3D9RenderSystem::setSeparateSceneBlending_internal( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, 
 		SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp )
 	{
 		HRESULT hr;
@@ -1332,7 +1332,7 @@ namespace CamelotEngine
 			CM_EXCEPT(RenderingAPIException, "Failed to set alpha scene blending operation option");
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setAlphaRejectSettings( CompareFunction func, unsigned char value, bool alphaToCoverage )
+	void D3D9RenderSystem::setAlphaRejectSettings_internal( CompareFunction func, unsigned char value, bool alphaToCoverage )
 	{
 		HRESULT hr;
 		bool a2c = false;
@@ -1357,10 +1357,10 @@ namespace CamelotEngine
 			CM_EXCEPT(RenderingAPIException, "Failed to set render state D3DRS_ALPHAREF");
 
 		// Alpha to coverage
-		if (getCapabilities()->hasCapability(RSC_ALPHA_TO_COVERAGE))
+		if (getCapabilities_internal()->hasCapability(RSC_ALPHA_TO_COVERAGE))
 		{
 			// Vendor-specific hacks on renderstate, gotta love 'em
-			if (getCapabilities()->getVendor() == GPU_NVIDIA)
+			if (getCapabilities_internal()->getVendor() == GPU_NVIDIA)
 			{
 				if (a2c)
 				{
@@ -1374,7 +1374,7 @@ namespace CamelotEngine
 				}
 
 			}
-			else if ((getCapabilities()->getVendor() == GPU_ATI))
+			else if ((getCapabilities_internal()->getVendor() == GPU_ATI))
 			{
 				if (a2c)
 				{
@@ -1394,7 +1394,7 @@ namespace CamelotEngine
 
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setCullingMode( CullingMode mode )
+	void D3D9RenderSystem::setCullingMode_internal( CullingMode mode )
 	{
 		mCullingMode = mode;
 		HRESULT hr;
@@ -1406,14 +1406,14 @@ namespace CamelotEngine
 			CM_EXCEPT(RenderingAPIException, "Failed to set culling mode");
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setDepthBufferParams( bool depthTest, bool depthWrite, CompareFunction depthFunction )
+	void D3D9RenderSystem::setDepthBufferParams_internal( bool depthTest, bool depthWrite, CompareFunction depthFunction )
 	{
-		setDepthBufferCheckEnabled( depthTest );
-		setDepthBufferWriteEnabled( depthWrite );
-		setDepthBufferFunction( depthFunction );
+		setDepthBufferCheckEnabled_internal( depthTest );
+		setDepthBufferWriteEnabled_internal( depthWrite );
+		setDepthBufferFunction_internal( depthFunction );
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setDepthBufferCheckEnabled( bool enabled )
+	void D3D9RenderSystem::setDepthBufferCheckEnabled_internal( bool enabled )
 	{
 		HRESULT hr;
 
@@ -1426,7 +1426,7 @@ namespace CamelotEngine
 			CM_EXCEPT(RenderingAPIException, "Error setting depth buffer test state");
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setDepthBufferWriteEnabled( bool enabled )
+	void D3D9RenderSystem::setDepthBufferWriteEnabled_internal( bool enabled )
 	{
 		HRESULT hr;
 
@@ -1434,14 +1434,14 @@ namespace CamelotEngine
 			CM_EXCEPT(RenderingAPIException, "Error setting depth buffer write state");
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setDepthBufferFunction( CompareFunction func )
+	void D3D9RenderSystem::setDepthBufferFunction_internal( CompareFunction func )
 	{
 		HRESULT hr;
 		if( FAILED( hr = __SetRenderState( D3DRS_ZFUNC, D3D9Mappings::get(func) ) ) )
 			CM_EXCEPT(RenderingAPIException, "Error setting depth buffer test function");
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setDepthBias(float constantBias, float slopeScaleBias)
+	void D3D9RenderSystem::setDepthBias_internal(float constantBias, float slopeScaleBias)
 	{
 
 		if ((mDeviceManager->getActiveDevice()->getD3D9DeviceCaps().RasterCaps & D3DPRASTERCAPS_DEPTHBIAS) != 0)
@@ -1467,7 +1467,7 @@ namespace CamelotEngine
 
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setColorBufferWriteEnabled(bool red, bool green, 
+	void D3D9RenderSystem::setColorBufferWriteEnabled_internal(bool red, bool green, 
 		bool blue, bool alpha)
 	{
 		DWORD val = 0;
@@ -1484,14 +1484,14 @@ namespace CamelotEngine
 			CM_EXCEPT(RenderingAPIException, "Error setting colour write enable flags");
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setPolygonMode(PolygonMode level)
+	void D3D9RenderSystem::setPolygonMode_internal(PolygonMode level)
 	{
 		HRESULT hr = __SetRenderState(D3DRS_FILLMODE, D3D9Mappings::get(level));
 		if (FAILED(hr))
 			CM_EXCEPT(RenderingAPIException, "Error setting polygon mode.");
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setStencilCheckEnabled(bool enabled)
+	void D3D9RenderSystem::setStencilCheckEnabled_internal(bool enabled)
 	{
 		// Allow stencilling
 		HRESULT hr = __SetRenderState(D3DRS_STENCILENABLE, enabled);
@@ -1499,7 +1499,7 @@ namespace CamelotEngine
 			CM_EXCEPT(RenderingAPIException, "Error enabling / disabling stencilling.");
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setStencilBufferParams(CompareFunction func, 
+	void D3D9RenderSystem::setStencilBufferParams_internal(CompareFunction func, 
 		UINT32 refValue, UINT32 mask, StencilOperation stencilFailOp, 
 		StencilOperation depthFailOp, StencilOperation passOp, 
 		bool twoSidedOperation)
@@ -1575,7 +1575,7 @@ namespace CamelotEngine
 			CM_EXCEPT(RenderingAPIException, "Error setting stencil pass operation.");
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setTextureFiltering(size_t unit, FilterType ftype, 
+	void D3D9RenderSystem::setTextureFiltering_internal(size_t unit, FilterType ftype, 
 		FilterOptions filter)
 	{
 		HRESULT hr;
@@ -1593,7 +1593,7 @@ namespace CamelotEngine
 		return oldVal;
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setTextureAnisotropy(size_t unit, unsigned int maxAnisotropy)
+	void D3D9RenderSystem::setTextureAnisotropy_internal(size_t unit, unsigned int maxAnisotropy)
 	{
 		if (static_cast<DWORD>(maxAnisotropy) > mDeviceManager->getActiveDevice()->getD3D9DeviceCaps().MaxAnisotropy)
 			maxAnisotropy = mDeviceManager->getActiveDevice()->getD3D9DeviceCaps().MaxAnisotropy;
@@ -1649,7 +1649,7 @@ namespace CamelotEngine
 		}
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setRenderTarget(RenderTarget *target)
+	void D3D9RenderSystem::setRenderTarget_internal(RenderTarget *target)
 	{
 		mActiveRenderTarget = target;
 
@@ -1715,7 +1715,7 @@ namespace CamelotEngine
 		}
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setViewport(const Viewport& vp)
+	void D3D9RenderSystem::setViewport_internal(const Viewport& vp)
 	{
 		mActiveViewport = vp;
 
@@ -1725,9 +1725,9 @@ namespace CamelotEngine
 
 		// Set render target
 		RenderTarget* target = vp.getTarget();
-		setRenderTarget(target);
+		setRenderTarget_internal(target);
 
-		setCullingMode( mCullingMode );
+		setCullingMode_internal( mCullingMode );
 
 		// set viewport dimensions
 		d3dvp.X = vp.getActualLeft();
@@ -1751,7 +1751,7 @@ namespace CamelotEngine
 		__SetRenderState(D3DRS_SRGBWRITEENABLE, target->isHardwareGammaEnabled());
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::beginFrame()
+	void D3D9RenderSystem::beginFrame_internal()
 	{
 		HRESULT hr;
 
@@ -1770,7 +1770,7 @@ namespace CamelotEngine
  		mDeviceManager->getActiveDevice()->clearDeviceStreams();
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::endFrame()
+	void D3D9RenderSystem::endFrame_internal()
 	{
 		HRESULT hr;
 		if( FAILED( hr = getActiveD3D9Device()->EndScene() ) )
@@ -1803,7 +1803,7 @@ namespace CamelotEngine
 		return zBufferIdentifier;
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setVertexDeclaration(VertexDeclarationPtr decl)
+	void D3D9RenderSystem::setVertexDeclaration_internal(VertexDeclarationPtr decl)
 	{
 		HRESULT hr;
 
@@ -1817,7 +1817,7 @@ namespace CamelotEngine
 
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setVertexBufferBinding(VertexBufferBinding* binding)
+	void D3D9RenderSystem::setVertexBufferBinding_internal(VertexBufferBinding* binding)
 	{
 		HRESULT hr;
 
@@ -1869,7 +1869,7 @@ namespace CamelotEngine
 
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::render(const RenderOperation& op)
+	void D3D9RenderSystem::render_internal(const RenderOperation& op)
 	{
 		// Exit immediately if there is nothing to render
 		// This caused a problem on FireGL 8800
@@ -1877,13 +1877,13 @@ namespace CamelotEngine
 			return;
 
 		// Call super class
-		RenderSystem::render(op);
+		RenderSystem::render_internal(op);
 
 		// To think about: possibly remove setVertexDeclaration and 
 		// setVertexBufferBinding from RenderSystem since the sequence is
 		// a bit too D3D9-specific?
-		setVertexDeclaration(op.vertexData->vertexDeclaration);
-		setVertexBufferBinding(op.vertexData->vertexBufferBinding);
+		setVertexDeclaration_internal(op.vertexData->vertexDeclaration);
+		setVertexBufferBinding_internal(op.vertexData->vertexBufferBinding);
 
 		// Determine rendering operation
 		D3DPRIMITIVETYPE primType = D3DPT_TRIANGLELIST;
@@ -2009,7 +2009,7 @@ namespace CamelotEngine
 		}
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setScissorTest(bool enabled, size_t left, size_t top, size_t right,
+	void D3D9RenderSystem::setScissorTest_internal(bool enabled, size_t left, size_t top, size_t right,
 		size_t bottom)
 	{
 		HRESULT hr;
@@ -2017,7 +2017,7 @@ namespace CamelotEngine
 		{
 			if (FAILED(hr = __SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE)))
 			{
-				CM_EXCEPT(RenderingAPIException, "Unable to enable scissor rendering state; " + getErrorDescription(hr));
+				CM_EXCEPT(RenderingAPIException, "Unable to enable scissor rendering state; " + getErrorDescription_internal(hr));
 			}
 			RECT rect;
 			rect.left = static_cast<LONG>(left);
@@ -2026,19 +2026,19 @@ namespace CamelotEngine
 			rect.right = static_cast<LONG>(right);
 			if (FAILED(hr = getActiveD3D9Device()->SetScissorRect(&rect)))
 			{
-				CM_EXCEPT(RenderingAPIException, "Unable to set scissor rectangle; " + getErrorDescription(hr));
+				CM_EXCEPT(RenderingAPIException, "Unable to set scissor rectangle; " + getErrorDescription_internal(hr));
 			}
 		}
 		else
 		{
 			if (FAILED(hr = __SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE)))
 			{
-				CM_EXCEPT(RenderingAPIException, "Unable to disable scissor rendering state; " + getErrorDescription(hr));
+				CM_EXCEPT(RenderingAPIException, "Unable to disable scissor rendering state; " + getErrorDescription_internal(hr));
 			}
 		}
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::clearFrameBuffer(unsigned int buffers, 
+	void D3D9RenderSystem::clearFrameBuffer_internal(unsigned int buffers, 
 		const Color& colour, float depth, unsigned short stencil)
 	{
 		DWORD flags = 0;
@@ -2339,12 +2339,6 @@ namespace CamelotEngine
 		return mCurrentCapabilities;
 	}
 
-	//---------------------------------------------------------------------
-	unsigned int D3D9RenderSystem::getDisplayMonitorCount() const
-	{
-		return mpD3D->GetAdapterCount();
-	}
-
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::notifyOnDeviceLost(D3D9Device* device)
 	{	
@@ -2366,7 +2360,7 @@ namespace CamelotEngine
 
 		// Reset the texture stages, they will need to be rebound
 		for (size_t i = 0; i < CM_MAX_TEXTURE_LAYERS; ++i)
-			setTexture(i, false, TexturePtr());
+			setTexture_internal(i, false, TexturePtr());
 	}
 	
 	//---------------------------------------------------------------------
@@ -2636,7 +2630,7 @@ namespace CamelotEngine
 
 		updateRenderSystemCapabilities(renderWindow);
 
-		attachRenderTarget( *renderWindow );
+		attachRenderTarget_internal( *renderWindow );
 
 		asyncOp.completeOperation(static_cast<RenderWindow*>(renderWindow));
 	}	
@@ -2726,7 +2720,7 @@ namespace CamelotEngine
 
 						const SamplerState& samplerState = params->getSamplerState(i->second.physicalIndex);
 
-						setTextureUnitSettings(logicalIndex, texture.getInternalPtr(), samplerState);
+						setTextureUnitSettings_internal(logicalIndex, texture.getInternalPtr(), samplerState);
 					}
 				}
 		}

+ 20 - 20
CamelotForwardRenderer/Source/CmForwardRenderer.cpp

@@ -31,8 +31,8 @@ namespace CamelotEngine
 		RenderSystem* renderSystem = RenderSystemManager::getActive();
 
 		// TODO - No point in setting these each frame?
-		renderSystem->setInvertVertexWinding(false);
-		renderSystem->setDepthBufferParams();
+		renderSystem->setInvertVertexWinding_internal(false);
+		renderSystem->setDepthBufferParams_internal();
 
 		const vector<CameraPtr>::type& allCameras = gSceneManager().getAllCameras();
 		for(auto iter = allCameras.begin(); iter != allCameras.end(); ++iter)
@@ -48,15 +48,15 @@ namespace CamelotEngine
 		vector<RenderablePtr>::type allRenderables = gSceneManager().getVisibleRenderables(camera);
 
 		RenderSystem* renderSystem = RenderSystemManager::getActive();
-		renderSystem->setViewport(*camera->getViewport());
+		renderSystem->setViewport_internal(*camera->getViewport());
 
 		Matrix4 projMatrixCstm = camera->getProjectionMatrix();
 		Matrix4 viewMatrixCstm = camera->getViewMatrix();
 
 		Matrix4 viewProjMatrix = projMatrixCstm * viewMatrixCstm;
 
-		renderSystem->clearFrameBuffer(FBT_COLOUR | FBT_DEPTH, Color::Blue);
-		renderSystem->beginFrame();
+		renderSystem->clearFrameBuffer_internal(FBT_COLOUR | FBT_DEPTH, Color::Blue);
+		renderSystem->beginFrame_internal();
 
 		// TODO - sort renderables by material/pass/parameters to minimize state changes
 		for(auto iter = allRenderables.begin(); iter != allRenderables.end(); ++iter)
@@ -76,16 +76,16 @@ namespace CamelotEngine
 			// (or should we just ignore such missing parameters?)
 			material->setMat4("matViewProjection", viewProjMatrix);
 
-			for(int i = 0; i < material->getNumPasses(); i++)
+			for(UINT32 i = 0; i < material->getNumPasses(); i++)
 			{
 				setPass(material->getPass(i));
 				setPassParameters(material->getPassParameters(i));
 
-				renderSystem->render(mesh->getRenderOperation());
+				renderSystem->render_internal(mesh->getRenderOperation());
 			}
 		}
 
-		renderSystem->endFrame();
+		renderSystem->endFrame_internal();
 
 		// TODO - Sort renderables
 		// Render them
@@ -138,7 +138,7 @@ namespace CamelotEngine
 		// Set scene blending
 		if ( pass->hasSeparateSceneBlending( ) )
 		{
-			renderSystem->setSeparateSceneBlending(
+			renderSystem->setSeparateSceneBlending_internal(
 				pass->getSourceBlendFactor(), pass->getDestBlendFactor(),
 				pass->getSourceBlendFactorAlpha(), pass->getDestBlendFactorAlpha(),
 				pass->getSceneBlendingOperation(), 
@@ -148,20 +148,20 @@ namespace CamelotEngine
 		{
 			if(pass->hasSeparateSceneBlendingOperations( ) )
 			{
-				renderSystem->setSeparateSceneBlending(
+				renderSystem->setSeparateSceneBlending_internal(
 					pass->getSourceBlendFactor(), pass->getDestBlendFactor(),
 					pass->getSourceBlendFactor(), pass->getDestBlendFactor(),
 					pass->getSceneBlendingOperation(), pass->getSceneBlendingOperationAlpha() );
 			}
 			else
 			{
-				renderSystem->setSceneBlending(
+				renderSystem->setSceneBlending_internal(
 					pass->getSourceBlendFactor(), pass->getDestBlendFactor(), pass->getSceneBlendingOperation() );
 			}
 		}
 
 		// Set point parameters
-		renderSystem->setPointParameters(
+		renderSystem->setPointParameters_internal(
 			pass->getPointSize(),
 			false, 
 			false, 
@@ -178,25 +178,25 @@ namespace CamelotEngine
 
 		// Set up non-texture related material settings
 		// Depth buffer settings
-		renderSystem->setDepthBufferFunction(pass->getDepthFunction());
-		renderSystem->setDepthBufferCheckEnabled(pass->getDepthCheckEnabled());
-		renderSystem->setDepthBufferWriteEnabled(pass->getDepthWriteEnabled());
-		renderSystem->setDepthBias(pass->getDepthBiasConstant(), pass->getDepthBiasSlopeScale());
+		renderSystem->setDepthBufferFunction_internal(pass->getDepthFunction());
+		renderSystem->setDepthBufferCheckEnabled_internal(pass->getDepthCheckEnabled());
+		renderSystem->setDepthBufferWriteEnabled_internal(pass->getDepthWriteEnabled());
+		renderSystem->setDepthBias_internal(pass->getDepthBiasConstant(), pass->getDepthBiasSlopeScale());
 
 		// Alpha-reject settings
-		renderSystem->setAlphaRejectSettings(
+		renderSystem->setAlphaRejectSettings_internal(
 			pass->getAlphaRejectFunction(), pass->getAlphaRejectValue(), pass->isAlphaToCoverageEnabled());
 
 		// Set colour write mode
 		// Right now we only use on/off, not per-channel
 		bool colWrite = pass->getColourWriteEnabled();
-		renderSystem->setColorBufferWriteEnabled(colWrite, colWrite, colWrite, colWrite);
+		renderSystem->setColorBufferWriteEnabled_internal(colWrite, colWrite, colWrite, colWrite);
 
 		// Culling mode
-		renderSystem->setCullingMode(pass->getCullingMode());
+		renderSystem->setCullingMode_internal(pass->getCullingMode());
 
 		// Polygon mode
-		renderSystem->setPolygonMode(pass->getPolygonMode());
+		renderSystem->setPolygonMode_internal(pass->getPolygonMode());
 	}
 
 	void ForwardRenderer::setPassParameters(PassParametersPtr params)

+ 64 - 57
CamelotGLRenderer/Include/CmGLRenderSystem.h

@@ -127,21 +127,18 @@ namespace CamelotEngine {
 
 		UINT16 mActiveTextureUnit;
 
-		/************************************************************************/
-		/* 							INTERNAL CALLBACKS                     		*/
-		/************************************************************************/
-	protected:
-        void startUp_internal();
-
-		void createRenderWindow_internal(const String &name, unsigned int width, unsigned int height, 
-			bool fullScreen, const NameValuePairList& miscParams, AsyncOp& asyncOp);
-
-        void bindGpuProgram_internal(GpuProgramRef prg);
-        void unbindGpuProgram_internal(GpuProgramType gptype);
-		void bindGpuProgramParameters_internal(GpuProgramType gptype, GpuProgramParametersSharedPtr params, UINT16 mask);
 	protected:
 		void setClipPlanesImpl(const PlaneList& clipPlanes);
 		bool activateGLTextureUnit(size_t unit);
+
+		/// @copydoc RenderSystem::createMultiRenderTarget
+		virtual MultiRenderTarget * createMultiRenderTarget_internal(const String & name); 
+		
+        /** See
+          RenderSystem
+         */
+        String getErrorDescription_internal(long errorNumber) const;
+
     public:
         // Default constructor / destructor
         GLRenderSystem();
@@ -158,18 +155,6 @@ namespace CamelotEngine {
           RenderSystem
          */
         void shutdown(void);
-        
-		/// @copydoc RenderSystem::createMultiRenderTarget
-		virtual MultiRenderTarget * createMultiRenderTarget(const String & name); 
-		
-        /** See
-          RenderSystem
-         */
-        void destroyRenderWindow(RenderWindow* pWin);
-        /** See
-          RenderSystem
-         */
-        String getErrorDescription(long errorNumber) const;
 
         /** See
           RenderSystem
@@ -182,32 +167,57 @@ namespace CamelotEngine {
         /** See
           RenderSystem
          */
-		void setPointParameters(float size, bool attenuationEnabled, 
+		void startUp_internal();
+		/** See
+          RenderSystem
+         */
+		void createRenderWindow_internal(const String &name, unsigned int width, unsigned int height, 
+			bool fullScreen, const NameValuePairList& miscParams, AsyncOp& asyncOp);
+        /** See
+          RenderSystem
+         */
+        void destroyRenderWindow_internal(RenderWindow* pWin);
+		/** See
+          RenderSystem
+         */
+		void bindGpuProgram_internal(GpuProgramRef prg);
+        /** See
+          RenderSystem
+         */
+		void unbindGpuProgram_internal(GpuProgramType gptype);
+		/** See
+          RenderSystem
+         */
+		void bindGpuProgramParameters_internal(GpuProgramType gptype, GpuProgramParametersSharedPtr params, UINT16 mask);
+        /** See
+          RenderSystem
+         */
+		void setPointParameters_internal(float size, bool attenuationEnabled, 
 			float constant, float linear, float quadratic, float minSize, float maxSize);
 		/** See
           RenderSystem
          */
-        void setTexture(size_t unit, bool enabled, const TexturePtr &tex);
+        void setTexture_internal(size_t unit, bool enabled, const TexturePtr &tex);
         /** See
           RenderSystem
          */
-        void setTextureAddressingMode(size_t stage, const SamplerState::UVWAddressingMode& uvw);
+        void setTextureAddressingMode_internal(size_t stage, const SamplerState::UVWAddressingMode& uvw);
         /** See
           RenderSystem
          */
-        void setTextureBorderColor(size_t stage, const Color& colour);
+        void setTextureBorderColor_internal(size_t stage, const Color& colour);
 		/** See
 		  RenderSystem
 		 */
-		void setTextureMipmapBias(size_t unit, float bias);
+		void setTextureMipmapBias_internal(size_t unit, float bias);
         /** See
           RenderSystem
          */
-        void setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
+        void setSceneBlending_internal(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
         /** See
           RenderSystem
          */
-		void setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
+		void setSeparateSceneBlending_internal(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
         /** See
           RenderSystem
          */
@@ -219,51 +229,51 @@ namespace CamelotEngine {
 		/** See
           RenderSystem
          */
-        void setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage);
+        void setAlphaRejectSettings_internal(CompareFunction func, unsigned char value, bool alphaToCoverage);
         /** See
           RenderSystem
          */
-        void setViewport(const Viewport& vp);
+        void setViewport_internal(const Viewport& vp);
         /** See
           RenderSystem
          */
-        void beginFrame(void);
+        void beginFrame_internal(void);
         /** See
           RenderSystem
          */
-        void endFrame(void);
+        void endFrame_internal(void);
         /** See
           RenderSystem
          */
-        void setCullingMode(CullingMode mode);
+        void setCullingMode_internal(CullingMode mode);
         /** See
           RenderSystem
          */
-        void setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
+        void setDepthBufferParams_internal(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
         /** See
           RenderSystem
          */
-        void setDepthBufferCheckEnabled(bool enabled = true);
+        void setDepthBufferCheckEnabled_internal(bool enabled = true);
         /** See
           RenderSystem
          */
-        void setDepthBufferWriteEnabled(bool enabled = true);
+        void setDepthBufferWriteEnabled_internal(bool enabled = true);
         /** See
           RenderSystem
          */
-        void setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
+        void setDepthBufferFunction_internal(CompareFunction func = CMPF_LESS_EQUAL);
         /** See
           RenderSystem
          */
-        void setDepthBias(float constantBias, float slopeScaleBias);
+        void setDepthBias_internal(float constantBias, float slopeScaleBias);
         /** See
           RenderSystem
          */
-        void setColorBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
+        void setColorBufferWriteEnabled_internal(bool red, bool green, bool blue, bool alpha);
         /** See
           RenderSystem
          */
-        void _convertProjectionMatrix(const Matrix4& matrix,
+        void convertProjectionMatrix(const Matrix4& matrix,
             Matrix4& dest, bool forGpuProgram = false);
         /** See
           RenderSystem
@@ -276,15 +286,15 @@ namespace CamelotEngine {
         /** See
           RenderSystem
          */
-        void setPolygonMode(PolygonMode level);
+        void setPolygonMode_internal(PolygonMode level);
         /** See
           RenderSystem
          */
-        void setStencilCheckEnabled(bool enabled);
+        void setStencilCheckEnabled_internal(bool enabled);
         /** See
           RenderSystem.
          */
-        void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 
+        void setStencilBufferParams_internal(CompareFunction func = CMPF_ALWAYS_PASS, 
             UINT32 refValue = 0, UINT32 mask = 0xFFFFFFFF, 
             StencilOperation stencilFailOp = SOP_KEEP, 
             StencilOperation depthFailOp = SOP_KEEP,
@@ -293,23 +303,23 @@ namespace CamelotEngine {
         /** See
           RenderSystem
          */
-        void setTextureFiltering(size_t unit, FilterType ftype, FilterOptions filter);
+        void setTextureFiltering_internal(size_t unit, FilterType ftype, FilterOptions filter);
         /** See
           RenderSystem
          */
-		void setTextureAnisotropy(size_t unit, unsigned int maxAnisotropy);
+		void setTextureAnisotropy_internal(size_t unit, unsigned int maxAnisotropy);
         /** See
           RenderSystem
          */
-		void setVertexDeclaration(VertexDeclarationPtr decl);
+		void setVertexDeclaration_internal(VertexDeclarationPtr decl);
         /** See
           RenderSystem
          */
-		void setVertexBufferBinding(VertexBufferBinding* binding);
+		void setVertexBufferBinding_internal(VertexBufferBinding* binding);
         /** See
           RenderSystem
          */
-        void render(const RenderOperation& op);
+        void render_internal(const RenderOperation& op);
         /** See
           RenderSystem
          */
@@ -318,8 +328,8 @@ namespace CamelotEngine {
         /** See
           RenderSystem
          */
-        void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600) ;
-        void clearFrameBuffer(unsigned int buffers, 
+        void setScissorTest_internal(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600) ;
+        void clearFrameBuffer_internal(unsigned int buffers, 
             const Color& colour = Color::Black, 
             float depth = 1.0f, unsigned short stencil = 0);
         float getHorizontalTexelOffset(void);
@@ -341,7 +351,7 @@ namespace CamelotEngine {
         /**
          * Set current render target to target, enabling its GL context if needed
          */
-        void setRenderTarget(RenderTarget *target);
+        void setRenderTarget_internal(RenderTarget *target);
         /** Unregister a render target->context mapping. If the context of target 
             is the current context, change the context to the main context so it
             can be destroyed safely. 
@@ -352,9 +362,6 @@ namespace CamelotEngine {
         void _unregisterContext(GLContext *context);
 		/** Returns the main context */
 		GLContext* _getMainContext() {return mMainContext;} 
-
-		/// @copydoc RenderSystem::getDisplayMonitorCount
-		unsigned int getDisplayMonitorCount() const;
     };
 }
 #endif

+ 1 - 1
CamelotGLRenderer/Source/CmGLFrameBufferObject.cpp

@@ -123,7 +123,7 @@ namespace CamelotEngine {
         size_t height = mColour[0].buffer->getHeight();
         GLuint format = mColour[0].buffer->getGLFormat();
         PixelFormat ogreFormat = mColour[0].buffer->getFormat();
-        UINT16 maxSupportedMRTs = CamelotEngine::RenderSystemManager::getActive()->getCapabilities()->getNumMultiRenderTargets();
+        UINT16 maxSupportedMRTs = CamelotEngine::RenderSystemManager::getActive()->getCapabilities_internal()->getNumMultiRenderTargets();
 
 		// Bind simple buffer to add colour attachments
 		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFB);

+ 1 - 1
CamelotGLRenderer/Source/CmGLHardwareBufferManager.cpp

@@ -66,7 +66,7 @@ namespace CamelotEngine {
 		// Win32 machines with ATI GPU are having issues glMapBuffer, looks like buffer corruption
 		// disable for now until we figure out where the problem lies			
 #	if CM_PLATFORM == CM_PLATFORM_WIN32
-		if (CamelotEngine::RenderSystemManager::getActive()->getCapabilities()->getVendor() == GPU_ATI) 
+		if (CamelotEngine::RenderSystemManager::getActive()->getCapabilities_internal()->getVendor() == GPU_ATI) 
 		{
 			mMapBufferThreshold = 0xffffffffUL  /* maximum unsigned long value */;
 		}

+ 3 - 3
CamelotGLRenderer/Source/CmGLHardwarePixelBuffer.cpp

@@ -266,7 +266,7 @@ GLTextureBuffer::GLTextureBuffer(const String &baseName, GLenum target, GLuint i
             surface.zoffset = zoffset;
             RenderTexture *trt = GLRTTManager::instance().createRenderTexture(name, surface, writeGamma, fsaa);
             mSliceTRT.push_back(trt);
-            CamelotEngine::RenderSystemManager::getActive()->attachRenderTarget(*mSliceTRT[zoffset]);
+            CamelotEngine::RenderSystemManager::getActive()->attachRenderTarget_internal(*mSliceTRT[zoffset]);
         }
 	}
 }
@@ -278,7 +278,7 @@ GLTextureBuffer::~GLTextureBuffer()
         // was deleted by the user.
         for (SliceTRT::const_iterator it = mSliceTRT.begin(); it != mSliceTRT.end(); ++it)
         {
-			CamelotEngine::RenderSystemManager::getActive()->destroyRenderTarget((*it)->getName());
+			CamelotEngine::RenderSystemManager::getActive()->destroyRenderTarget_internal((*it)->getName());
         }
 	}
 }
@@ -577,7 +577,7 @@ void GLTextureBuffer::blitFromTexture(GLTextureBuffer *src, const Box &srcBox, c
 
 	// Important to disable all other texture units
 	RenderSystem* rsys = CamelotEngine::RenderSystemManager::getActive();
-	rsys->disableTextureUnitsFrom(0);
+	rsys->disableTextureUnitsFrom_internal(0);
 	if (GLEW_VERSION_1_2)
 	{
 		glActiveTextureARB(GL_TEXTURE0);

+ 1 - 1
CamelotGLRenderer/Source/CmGLPixelFormat.cpp

@@ -373,7 +373,7 @@ namespace CamelotEngine  {
     //-----------------------------------------------------------------------------    
     size_t GLPixelUtil::optionalPO2(size_t value)
     {
-        const RenderSystemCapabilities *caps = CamelotEngine::RenderSystemManager::getActive()->getCapabilities();
+        const RenderSystemCapabilities *caps = CamelotEngine::RenderSystemManager::getActive()->getCapabilities_internal();
         if(caps->hasCapability(RSC_NON_POWER_OF_2_TEXTURES))
             return value;
         else

+ 46 - 52
CamelotGLRenderer/Source/CmGLRenderSystem.cpp

@@ -896,15 +896,15 @@ namespace CamelotEngine {
 
 
 	//-----------------------------------------------------------------------
-	MultiRenderTarget * GLRenderSystem::createMultiRenderTarget(const String & name)
+	MultiRenderTarget * GLRenderSystem::createMultiRenderTarget_internal(const String & name)
 	{
 		MultiRenderTarget *retval = GLRTTManager::instancePtr()->createMultiRenderTarget(name);
-		attachRenderTarget( *retval );
+		attachRenderTarget_internal( *retval );
 		return retval;
 	}
 
 	//-----------------------------------------------------------------------
-	void GLRenderSystem::destroyRenderWindow(RenderWindow* pWin)
+	void GLRenderSystem::destroyRenderWindow_internal(RenderWindow* pWin)
 	{
 		// Find it to remove from list
 		RenderTargetMap::iterator i = mRenderTargets.begin();
@@ -933,7 +933,7 @@ namespace CamelotEngine {
 		}
 	}
 	//-----------------------------------------------------------------------------
-	void GLRenderSystem::setPointParameters(float size, 
+	void GLRenderSystem::setPointParameters_internal(float size, 
 		bool attenuationEnabled, float constant, float linear, float quadratic,
 		float minSize, float maxSize)
 	{
@@ -1003,7 +1003,7 @@ namespace CamelotEngine {
 		
 	}
 	//-----------------------------------------------------------------------------
-	void GLRenderSystem::setTexture(size_t stage, bool enabled, const TexturePtr &texPtr)
+	void GLRenderSystem::setTexture_internal(size_t stage, bool enabled, const TexturePtr &texPtr)
 	{
 		GLTexturePtr tex = std::static_pointer_cast<GLTexture>(texPtr);
 
@@ -1078,7 +1078,7 @@ namespace CamelotEngine {
 
 	}
 	//-----------------------------------------------------------------------------
-	void GLRenderSystem::setTextureAddressingMode(size_t stage, const SamplerState::UVWAddressingMode& uvw)
+	void GLRenderSystem::setTextureAddressingMode_internal(size_t stage, const SamplerState::UVWAddressingMode& uvw)
 	{
 		if (!activateGLTextureUnit(stage))
 			return;
@@ -1091,7 +1091,7 @@ namespace CamelotEngine {
 		activateGLTextureUnit(0);
 	}
 	//-----------------------------------------------------------------------------
-	void GLRenderSystem::setTextureBorderColor(size_t stage, const Color& colour)
+	void GLRenderSystem::setTextureBorderColor_internal(size_t stage, const Color& colour)
 	{
 		GLfloat border[4] = { colour.r, colour.g, colour.b, colour.a };
 		if (activateGLTextureUnit(stage))
@@ -1101,7 +1101,7 @@ namespace CamelotEngine {
 	}
 	}
 	//-----------------------------------------------------------------------------
-	void GLRenderSystem::setTextureMipmapBias(size_t stage, float bias)
+	void GLRenderSystem::setTextureMipmapBias_internal(size_t stage, float bias)
 	{
 		if (mCurrentCapabilities->hasCapability(RSC_MIPMAP_LOD_BIAS))
 		{
@@ -1143,7 +1143,7 @@ namespace CamelotEngine {
 		return GL_ONE;
 	}
 
-	void GLRenderSystem::setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op )
+	void GLRenderSystem::setSceneBlending_internal(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op )
 	{
 		GLint sourceBlend = getBlendMode(sourceFactor);
 		GLint destBlend = getBlendMode(destFactor);
@@ -1187,7 +1187,7 @@ namespace CamelotEngine {
 		}
 	}
 	//-----------------------------------------------------------------------------
-	void GLRenderSystem::setSeparateSceneBlending(
+	void GLRenderSystem::setSeparateSceneBlending_internal(
 		SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, 
 		SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha,
 		SceneBlendOperation op, SceneBlendOperation alphaOp )
@@ -1256,7 +1256,7 @@ namespace CamelotEngine {
 		}
 	}
 	//-----------------------------------------------------------------------------
-	void GLRenderSystem::setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage)
+	void GLRenderSystem::setAlphaRejectSettings_internal(CompareFunction func, unsigned char value, bool alphaToCoverage)
 	{
 		bool a2c = false;
 		static bool lasta2c = false;
@@ -1272,7 +1272,7 @@ namespace CamelotEngine {
 			glAlphaFunc(convertCompareFunction(func), value / 255.0f);
 		}
 
-		if (a2c != lasta2c && getCapabilities()->hasCapability(RSC_ALPHA_TO_COVERAGE))
+		if (a2c != lasta2c && getCapabilities_internal()->hasCapability(RSC_ALPHA_TO_COVERAGE))
 		{
 			if (a2c)
 				glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE);
@@ -1284,11 +1284,11 @@ namespace CamelotEngine {
 
 	}
 	//-----------------------------------------------------------------------------
-	void GLRenderSystem::setViewport(const Viewport& vp)
+	void GLRenderSystem::setViewport_internal(const Viewport& vp)
 	{
 		RenderTarget* target;
 		target = vp.getTarget();
-		setRenderTarget(target);
+		setRenderTarget_internal(target);
 		mActiveViewport = vp;
 
 		GLsizei x, y, w, h;
@@ -1310,14 +1310,14 @@ namespace CamelotEngine {
 	}
 
 	//-----------------------------------------------------------------------------
-	void GLRenderSystem::beginFrame(void)
+	void GLRenderSystem::beginFrame_internal(void)
 	{
 		// Activate the viewport clipping
 		glEnable(GL_SCISSOR_TEST);
 	}
 
 	//-----------------------------------------------------------------------------
-	void GLRenderSystem::endFrame(void)
+	void GLRenderSystem::endFrame_internal(void)
 	{
 		// Deactivate the viewport clipping.
 		glDisable(GL_SCISSOR_TEST);
@@ -1329,7 +1329,7 @@ namespace CamelotEngine {
 	}
 
 	//-----------------------------------------------------------------------------
-	void GLRenderSystem::setCullingMode(CullingMode mode)
+	void GLRenderSystem::setCullingMode_internal(CullingMode mode)
 	{
 		mCullingMode = mode;
 		// NB: Because two-sided stencil API dependence of the front face, we must
@@ -1376,14 +1376,14 @@ namespace CamelotEngine {
 		glCullFace( cullMode );
 	}
 	//-----------------------------------------------------------------------------
-	void GLRenderSystem::setDepthBufferParams(bool depthTest, bool depthWrite, CompareFunction depthFunction)
+	void GLRenderSystem::setDepthBufferParams_internal(bool depthTest, bool depthWrite, CompareFunction depthFunction)
 	{
-		setDepthBufferCheckEnabled(depthTest);
-		setDepthBufferWriteEnabled(depthWrite);
-		setDepthBufferFunction(depthFunction);
+		setDepthBufferCheckEnabled_internal(depthTest);
+		setDepthBufferWriteEnabled_internal(depthWrite);
+		setDepthBufferFunction_internal(depthFunction);
 	}
 	//-----------------------------------------------------------------------------
-	void GLRenderSystem::setDepthBufferCheckEnabled(bool enabled)
+	void GLRenderSystem::setDepthBufferCheckEnabled_internal(bool enabled)
 	{
 		if (enabled)
 		{
@@ -1396,7 +1396,7 @@ namespace CamelotEngine {
 		}
 	}
 	//-----------------------------------------------------------------------------
-	void GLRenderSystem::setDepthBufferWriteEnabled(bool enabled)
+	void GLRenderSystem::setDepthBufferWriteEnabled_internal(bool enabled)
 	{
 		GLboolean flag = enabled ? GL_TRUE : GL_FALSE;
 		glDepthMask( flag );  
@@ -1404,12 +1404,12 @@ namespace CamelotEngine {
 		mDepthWrite = enabled;
 	}
 	//-----------------------------------------------------------------------------
-	void GLRenderSystem::setDepthBufferFunction(CompareFunction func)
+	void GLRenderSystem::setDepthBufferFunction_internal(CompareFunction func)
 	{
 		glDepthFunc(convertCompareFunction(func));
 	}
 	//-----------------------------------------------------------------------------
-	void GLRenderSystem::setDepthBias(float constantBias, float slopeScaleBias)
+	void GLRenderSystem::setDepthBias_internal(float constantBias, float slopeScaleBias)
 	{
 		if (constantBias != 0 || slopeScaleBias != 0)
 		{
@@ -1426,7 +1426,7 @@ namespace CamelotEngine {
 		}
 	}
 	//-----------------------------------------------------------------------------
-	void GLRenderSystem::setColorBufferWriteEnabled(bool red, bool green, bool blue, bool alpha)
+	void GLRenderSystem::setColorBufferWriteEnabled_internal(bool red, bool green, bool blue, bool alpha)
 	{
 		glColorMask(red, green, blue, alpha);
 		// record this
@@ -1436,7 +1436,7 @@ namespace CamelotEngine {
 		mColourWrite[3] = alpha;
 	}
 	//-----------------------------------------------------------------------------
-    String GLRenderSystem::getErrorDescription(long errCode) const
+    String GLRenderSystem::getErrorDescription_internal(long errCode) const
     {
         const GLubyte *errString = gluErrorString (errCode);
 		return (errString != 0) ? String((const char*) errString) : StringUtil::BLANK;
@@ -1447,14 +1447,14 @@ namespace CamelotEngine {
 		return VET_COLOUR_ABGR;
 	}
 
-	void GLRenderSystem::_convertProjectionMatrix(const Matrix4& matrix,
+	void GLRenderSystem::convertProjectionMatrix(const Matrix4& matrix,
 		Matrix4& dest, bool forGpuProgram)
 	{
 		// no any conversion request for OpenGL
 		dest = matrix;
 	}
 	//---------------------------------------------------------------------
-	void GLRenderSystem::setPolygonMode(PolygonMode level)
+	void GLRenderSystem::setPolygonMode_internal(PolygonMode level)
 	{
 		GLenum glmode;
 		switch(level)
@@ -1473,7 +1473,7 @@ namespace CamelotEngine {
 		glPolygonMode(GL_FRONT_AND_BACK, glmode);
 	}
 	//---------------------------------------------------------------------
-	void GLRenderSystem::setStencilCheckEnabled(bool enabled)
+	void GLRenderSystem::setStencilCheckEnabled_internal(bool enabled)
 	{
 		if (enabled)
 		{
@@ -1485,7 +1485,7 @@ namespace CamelotEngine {
 		}
 	}
 	//---------------------------------------------------------------------
-	void GLRenderSystem::setStencilBufferParams(CompareFunction func, 
+	void GLRenderSystem::setStencilBufferParams_internal(CompareFunction func, 
 		UINT32 refValue, UINT32 mask, StencilOperation stencilFailOp, 
 		StencilOperation depthFailOp, StencilOperation passOp, 
 		bool twoSidedOperation)
@@ -1648,7 +1648,7 @@ namespace CamelotEngine {
 
 	}
 	//---------------------------------------------------------------------
-	void GLRenderSystem::setTextureFiltering(size_t unit, 
+	void GLRenderSystem::setTextureFiltering_internal(size_t unit, 
 		FilterType ftype, FilterOptions fo)
 	{
 		if (!activateGLTextureUnit(unit))
@@ -1703,7 +1703,7 @@ namespace CamelotEngine {
 		return curAniso ? curAniso : 1;
 	}
 	//---------------------------------------------------------------------
-	void GLRenderSystem::setTextureAnisotropy(size_t unit, unsigned int maxAnisotropy)
+	void GLRenderSystem::setTextureAnisotropy_internal(size_t unit, unsigned int maxAnisotropy)
 	{
 		if (!mCurrentCapabilities->hasCapability(RSC_ANISOTROPY))
 			return;
@@ -1722,21 +1722,21 @@ namespace CamelotEngine {
 		activateGLTextureUnit(0);
 	}
 	//---------------------------------------------------------------------
-	void GLRenderSystem::setVertexDeclaration(VertexDeclarationPtr decl)
+	void GLRenderSystem::setVertexDeclaration_internal(VertexDeclarationPtr decl)
 	{
 	}
 	//---------------------------------------------------------------------
-	void GLRenderSystem::setVertexBufferBinding(VertexBufferBinding* binding)
+	void GLRenderSystem::setVertexBufferBinding_internal(VertexBufferBinding* binding)
 	{
 	}
 	//---------------------------------------------------------------------
-	void GLRenderSystem::render(const RenderOperation& op)
+	void GLRenderSystem::render_internal(const RenderOperation& op)
 	{
 		// Call super class
-		RenderSystem::render(op);
+		RenderSystem::render_internal(op);
 
 		void* pBufferData = 0;
-		bool multitexturing = (getCapabilities()->getNumTextureUnits() > 1);
+		bool multitexturing = (getCapabilities_internal()->getNumTextureUnits() > 1);
 
 
         const VertexDeclaration::VertexElementList& decl = 
@@ -2031,7 +2031,7 @@ namespace CamelotEngine {
 		glPopMatrix();
 	}
 	//---------------------------------------------------------------------
-	void GLRenderSystem::setScissorTest(bool enabled, size_t left, 
+	void GLRenderSystem::setScissorTest_internal(bool enabled, size_t left, 
 		size_t top, size_t right, size_t bottom)
 	{
 		// If request texture flipping, use "upper-left", otherwise use "lower-left"
@@ -2069,7 +2069,7 @@ namespace CamelotEngine {
 		}
 	}
 	//---------------------------------------------------------------------
-	void GLRenderSystem::clearFrameBuffer(unsigned int buffers, 
+	void GLRenderSystem::clearFrameBuffer_internal(unsigned int buffers, 
 		const Color& colour, float depth, unsigned short stencil)
 	{
 		bool colourMask = !mColourWrite[0] || !mColourWrite[1] 
@@ -2210,7 +2210,7 @@ namespace CamelotEngine {
 		mCurrentLights = 0;
 
 		// Disable textures
-		disableTextureUnitsFrom(0);
+		disableTextureUnitsFrom_internal(0);
 
 		// It's ready for switching
 		if (mCurrentContext)
@@ -2242,7 +2242,7 @@ namespace CamelotEngine {
 
 	}
 	//---------------------------------------------------------------------
-	void GLRenderSystem::setRenderTarget(RenderTarget *target)
+	void GLRenderSystem::setRenderTarget_internal(RenderTarget *target)
 	{
 		// Unbind frame buffer object
 		if(mActiveRenderTarget)
@@ -2312,7 +2312,7 @@ namespace CamelotEngine {
 	{
 		if (mActiveTextureUnit != unit)
 		{
-			if (GLEW_VERSION_1_2 && unit < getCapabilities()->getNumTextureUnits())
+			if (GLEW_VERSION_1_2 && unit < getCapabilities_internal()->getNumTextureUnits())
 			{
 				glActiveTextureARB(GL_TEXTURE0 + unit);
 				mActiveTextureUnit = unit;
@@ -2334,12 +2334,6 @@ namespace CamelotEngine {
 		}
 	}
 
-	//---------------------------------------------------------------------
-	unsigned int GLRenderSystem::getDisplayMonitorCount() const
-	{
-		return mGLSupport->getDisplayMonitorCount();
-	}
-
 	/************************************************************************/
 	/* 							INTERNAL CALLBACKS                     		*/
 	/************************************************************************/
@@ -2365,7 +2359,7 @@ namespace CamelotEngine {
 		RenderWindow* win = mGLSupport->newWindow(name, width, height, 
 			fullScreen, &miscParams);
 
-		attachRenderTarget( *win );
+		attachRenderTarget_internal( *win );
 
 		if (!mGLInitialised) 
 		{                
@@ -2496,11 +2490,11 @@ namespace CamelotEngine {
 					|| def.constType == GCT_SAMPLER2DSHADOW || def.constType == GCT_SAMPLER3D || def.constType == GCT_SAMPLER1DSHADOW)
 				{
 					TextureRef curTexture = params->getTexture(def.physicalIndex);
-					setTexture(def.physicalIndex, true, curTexture.getInternalPtr());
+					setTexture_internal(def.physicalIndex, true, curTexture.getInternalPtr());
 
 					const SamplerState& samplerState = params->getSamplerState(def.physicalIndex);
 
-					setTextureUnitSettings(def.physicalIndex, curTexture.getInternalPtr(), samplerState);
+					setTextureUnitSettings_internal(def.physicalIndex, curTexture.getInternalPtr(), samplerState);
 				}
 			}
 		}

+ 2 - 2
CamelotGLRenderer/Source/CmGLTexture.cpp

@@ -125,7 +125,7 @@ namespace CamelotEngine {
 		
 		// If we can do automip generation and the user desires this, do so
 		mMipmapsHardwareGenerated = 
-			CamelotEngine::RenderSystemManager::getActive()->getCapabilities()->hasCapability(RSC_AUTOMIPMAP);
+			CamelotEngine::RenderSystemManager::getActive()->getCapabilities_internal()->hasCapability(RSC_AUTOMIPMAP);
 		// NVIDIA 175.16 drivers break hardware mip generation for non-compressed
 		// textures - disable until fixed
 		// Leave hardware gen on compressed textures since that's the only way we
@@ -134,7 +134,7 @@ namespace CamelotEngine {
 		// problem yet and in fact software generation appears to cause a crash 
 		// in some cases which I've yet to track down
 #if CM_PLATFORM != CM_PLATFORM_APPLE
-		if (CamelotEngine::RenderSystemManager::getActive()->getCapabilities()->getVendor() == GPU_NVIDIA
+		if (CamelotEngine::RenderSystemManager::getActive()->getCapabilities_internal()->getVendor() == GPU_NVIDIA
 			&& !PixelUtil::isCompressed(mFormat))
 		{
 			mMipmapsHardwareGenerated = false;

+ 1 - 1
CamelotGLRenderer/Source/CmGLTextureManager.cpp

@@ -84,7 +84,7 @@ namespace CamelotEngine {
 	PixelFormat GLTextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage)
 	{
 		// Adjust requested parameters to capabilities
-        const RenderSystemCapabilities *caps = CamelotEngine::RenderSystemManager::getActive()->getCapabilities();
+        const RenderSystemCapabilities *caps = CamelotEngine::RenderSystemManager::getActive()->getCapabilities_internal();
 
 		// Check compressed texture support
 		// if a compressed format not supported, revert to PF_A8R8G8B8

+ 158 - 119
CamelotRenderer/Include/CmRenderSystem.h

@@ -143,6 +143,10 @@ namespace CamelotEngine
 		 * 			By default an automatically created primary render context is used.
 		 */
 		void startUp();
+		virtual void startUp_internal();
+
+		// TODO - Classes below (shutdown to getErrorDescription) are not yet thread safe
+
 
 		/** Shutdown the renderer and cleanup resources.
 		*/
@@ -345,44 +349,19 @@ namespace CamelotEngine
 		*/
 		RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height, 
 			bool fullScreen, const NameValuePairList *miscParams = 0);
-		
-		/**	Create a MultiRenderTarget, which is a render target that renders to multiple RenderTextures
-		at once. Surfaces can be bound and unbound at will.
-		This fails if mCapabilities->getNumMultiRenderTargets() is smaller than 2.
+		virtual void createRenderWindow_internal(const String &name, unsigned int width, unsigned int height, 
+			bool fullScreen, const NameValuePairList& miscParams, AsyncOp& asyncOp) = 0;
+
+		/** Attaches the passed render target to the render system.
 		*/
-		virtual MultiRenderTarget * createMultiRenderTarget(const String & name) = 0; 
+		virtual void attachRenderTarget_internal( RenderTarget &target );
 
 		/** Destroys a render window */
-		virtual void destroyRenderWindow(const String& name);
+		virtual void destroyRenderWindow_internal(const String& name);
 		/** Destroys a render texture */
-		virtual void destroyRenderTexture(const String& name);
+		virtual void destroyRenderTexture_internal(const String& name);
 		/** Destroys a render target of any sort */
-		virtual void destroyRenderTarget(const String& name);
-
-		/** Attaches the passed render target to the render system.
-		*/
-		virtual void attachRenderTarget( RenderTarget &target );
-		/** Returns a pointer to the render target with the passed name, or NULL if that
-		render target cannot be found.
-		*/
-		virtual RenderTarget * getRenderTarget( const String &name );
-		/** Detaches the render target with the passed name from the render system and
-		returns a pointer to it.
-		@note
-		If the render target cannot be found, NULL is returned.
-		*/
-		virtual RenderTarget * detachRenderTarget( const String &name );
-
-		/// Iterator over RenderTargets
-		typedef CamelotEngine::RenderTargetMap::iterator RenderTargetIterator;
-
-		/** Returns a specialised MapIterator over all render targets attached to the RenderSystem. */
-		virtual RenderTargetIterator getRenderTargetIterator(void) {
-			return mRenderTargets.begin();
-		}
-		/** Returns a description of an error code.
-		*/
-		virtual String getErrorDescription(long errorNumber) const = 0;
+		virtual void destroyRenderTarget_internal(const String& name);
 
 		/** Defines whether or now fullscreen render windows wait for the vertical blank before flipping buffers.
 		@remarks
@@ -398,10 +377,12 @@ namespace CamelotEngine
 		enabled If true, the system waits for vertical blanks - quality over speed. If false it doesn't - speed over quality.
 		*/
 		void setWaitForVerticalBlank(bool enabled);
+		void setWaitForVerticalBlank_internal(bool enabled);
 
 		/** Returns true if the system is synchronising frames with the monitor vertical blank.
 		*/
 		bool getWaitForVerticalBlank(void) const;
+		bool getWaitForVerticalBlank_internal(void) const;
 
 		// ------------------------------------------------------------------------
 		//                     Internal Rendering Access
@@ -414,11 +395,14 @@ namespace CamelotEngine
 		only sets those settings which are different from the current settings for this
 		unit, thus minimising render state changes.
 		*/
-		virtual void setTextureUnitSettings(size_t texUnit, const TexturePtr& texture, const SamplerState& tl);
+		void setTextureUnitSettings(size_t texUnit, const TexturePtr& texture, const SamplerState& samplerState);
+		virtual void setTextureUnitSettings_internal(size_t texUnit, const TexturePtr& texture, const SamplerState& samplerState);
 		/** Turns off a texture unit. */
-		virtual void disableTextureUnit(size_t texUnit);
+		void disableTextureUnit(size_t texUnit);
+		virtual void disableTextureUnit_internal(size_t texUnit);
 		/** Disables all texture units from the given unit upwards */
-		virtual void disableTextureUnitsFrom(size_t texUnit);
+		void disableTextureUnitsFrom(size_t texUnit);
+		virtual void disableTextureUnitsFrom_internal(size_t texUnit);
 
 		/** Sets the size of points and how they are attenuated with distance.
 		@remarks
@@ -430,7 +414,9 @@ namespace CamelotEngine
 		you would set constant to 1, and linear and quadratic to 0. A
 		standard perspective attenuation would be 0, 1, 0 respectively.
 		*/
-		virtual void setPointParameters(float size, bool attenuationEnabled, 
+		void setPointParameters(float size, bool attenuationEnabled, 
+			float constant, float linear, float quadratic, float minSize, float maxSize);
+		virtual void setPointParameters_internal(float size, bool attenuationEnabled, 
 			float constant, float linear, float quadratic, float minSize, float maxSize) = 0;
 
 
@@ -446,7 +432,9 @@ namespace CamelotEngine
 		@param enabled Boolean to turn the unit on/off
 		@param texPtr Pointer to the texture to use.
 		*/
-		virtual void setTexture(size_t unit, bool enabled, 
+		void setTexture(size_t unit, bool enabled, 
+			const TexturePtr &texPtr);
+		virtual void setTexture_internal(size_t unit, bool enabled, 
 			const TexturePtr &texPtr) = 0;
 
 		/** Binds a texture to a vertex sampler.
@@ -458,7 +446,8 @@ namespace CamelotEngine
 		fragment units; calling this method will throw an exception.
 		@see RenderSystemCapabilites::getVertexTextureUnitsShared
 		*/
-		virtual void setVertexTexture(size_t unit, const TexturePtr& tex);
+		void setVertexTexture(size_t unit, const TexturePtr& tex);
+		virtual void setVertexTexture_internal(size_t unit, const TexturePtr& tex);
 
 		/** Sets the filtering options for a given texture unit.
 		@param unit The texture unit to set the filtering options for
@@ -466,7 +455,9 @@ namespace CamelotEngine
 		@param magFilter The filter used when a texture is magnified
 		@param mipFilter The filter used between mipmap levels, FO_NONE disables mipmapping
 		*/
-		virtual void setTextureFiltering(size_t unit, FilterOptions minFilter,
+		void setTextureFiltering(size_t unit, FilterOptions minFilter,
+			FilterOptions magFilter, FilterOptions mipFilter);
+		virtual void setTextureFiltering_internal(size_t unit, FilterOptions minFilter,
 			FilterOptions magFilter, FilterOptions mipFilter);
 
 		/** Sets a single filter for a given texture unit.
@@ -474,16 +465,20 @@ namespace CamelotEngine
 		@param ftype The filter type
 		@param filter The filter to be used
 		*/
-		virtual void setTextureFiltering(size_t unit, FilterType ftype, FilterOptions filter) = 0;
+		void setTextureFiltering(size_t unit, FilterType ftype, FilterOptions filter);
+		virtual void setTextureFiltering_internal(size_t unit, FilterType ftype, FilterOptions filter) = 0;
 
 		/** Sets the maximal anisotropy for the specified texture unit.*/
-		virtual void setTextureAnisotropy(size_t unit, unsigned int maxAnisotropy) = 0;
+		void setTextureAnisotropy(size_t unit, unsigned int maxAnisotropy);
+		virtual void setTextureAnisotropy_internal(size_t unit, unsigned int maxAnisotropy) = 0;
 
 		/** Sets the texture addressing mode for a texture unit.*/
-		virtual void setTextureAddressingMode(size_t unit, const SamplerState::UVWAddressingMode& uvw) = 0;
+		void setTextureAddressingMode(size_t unit, const SamplerState::UVWAddressingMode& uvw);
+		virtual void setTextureAddressingMode_internal(size_t unit, const SamplerState::UVWAddressingMode& uvw) = 0;
 
 		/** Sets the texture border color for a texture unit.*/
-		virtual void setTextureBorderColor(size_t unit, const Color& colour) = 0;
+		void setTextureBorderColor(size_t unit, const Color& color);
+		virtual void setTextureBorderColor_internal(size_t unit, const Color& color) = 0;
 
 		/** Sets the mipmap bias value for a given texture unit.
 		@remarks
@@ -493,7 +488,8 @@ namespace CamelotEngine
 		of levels, so +1 forces the mipmaps to one smaller level.
 		@note Only does something if render system has capability RSC_MIPMAP_LOD_BIAS.
 		*/
-		virtual void setTextureMipmapBias(size_t unit, float bias) = 0;
+		void setTextureMipmapBias(size_t unit, float bias);
+		virtual void setTextureMipmapBias_internal(size_t unit, float bias) = 0;
 
 		/** Sets the global blending factors for combining subsequent renders with the existing frame contents.
 		The result of the blending operation is:</p>
@@ -505,7 +501,8 @@ namespace CamelotEngine
 		@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
 		*/
-		virtual void setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op = SBO_ADD) = 0;
+		void setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op = SBO_ADD);
+		virtual void setSceneBlending_internal(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op = SBO_ADD) = 0;
 
 		/** Sets the global blending factors for combining subsequent renders with the existing frame contents.
 		The result of the blending operation is:</p>
@@ -519,7 +516,9 @@ namespace CamelotEngine
 		@param op The blend operation mode for combining pixels
 		@param alphaOp The blend operation mode for combining pixel alpha values
 		*/
-		virtual void setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, 
+		void setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, 
+			SceneBlendFactor destFactorAlpha, SceneBlendOperation op = SBO_ADD, SceneBlendOperation alphaOp = SBO_ADD);
+		virtual void setSeparateSceneBlending_internal(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, 
 			SceneBlendFactor destFactorAlpha, SceneBlendOperation op = SBO_ADD, SceneBlendOperation alphaOp = SBO_ADD) = 0;
 
 		/** Sets the global alpha rejection approach for future renders.
@@ -528,18 +527,21 @@ namespace CamelotEngine
 		@param val The value to compare each pixels alpha value to (0-255)
 		@param alphaToCoverage Whether to enable alpha to coverage, if supported
 		*/
-		virtual void setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage) = 0;
+		void setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage);
+		virtual void setAlphaRejectSettings_internal(CompareFunction func, unsigned char value, bool alphaToCoverage) = 0;
 
 		/**
 		* Signifies the beginning of a frame, i.e. the start of rendering on a single viewport. Will occur
 		* several times per complete frame if multiple viewports exist.
 		*/
-		virtual void beginFrame(void) = 0;
+		void beginFrame(void);
+		virtual void beginFrame_internal(void) = 0;
 		
 		/**
 		* Ends rendering of a frame to the current viewport.
 		*/
-		virtual void endFrame(void) = 0;
+		void endFrame(void);
+		virtual void endFrame_internal(void) = 0;
 		/**
 		Sets the provided viewport as the active one for future
 		rendering operations. This viewport is aware of it's own
@@ -547,9 +549,10 @@ namespace CamelotEngine
 
 		@param target Viewport to render to.
 		*/
-		virtual void setViewport(const Viewport& vp) = 0;
+		void setViewport(const Viewport& vp);
+		virtual void setViewport_internal(const Viewport& vp) = 0;
 		/** Get the current active viewport for rendering. */
-		virtual Viewport getViewport(void);
+		virtual Viewport getViewport_internal(void);
 
 		/** 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
@@ -562,8 +565,10 @@ namespace CamelotEngine
 		You may wish to use the CULL_NONE option for mesh data that you cull yourself where the vertex
 		winding is uncertain.
 		*/
-		virtual void setCullingMode(CullingMode mode) = 0;
+		void setCullingMode(CullingMode mode);
+		virtual void setCullingMode_internal(CullingMode mode) = 0;
 
+		CullingMode getCullingMode_internal(void) const;
 		virtual CullingMode getCullingMode(void) const;
 
 		/** Sets the mode of operation for depth buffer tests from this point onwards.
@@ -579,18 +584,23 @@ namespace CamelotEngine
 		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.
 		*/
-		virtual void setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL) = 0;
+		void setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
+		virtual void setDepthBufferParams_internal(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL) = 0;
 
 		/** 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.
 		*/
-		virtual void setDepthBufferCheckEnabled(bool enabled = true) = 0;
+		void setDepthBufferCheckEnabled(bool enabled = true);
+		virtual void setDepthBufferCheckEnabled_internal(bool enabled = true) = 0;
+
 		/** 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.
 		*/
-		virtual void setDepthBufferWriteEnabled(bool enabled = true) = 0;
+		void setDepthBufferWriteEnabled(bool enabled = true);
+		virtual void setDepthBufferWriteEnabled_internal(bool enabled = true) = 0;
+
 		/** 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
@@ -598,7 +608,9 @@ namespace CamelotEngine
 		@param  func The comparison between the new depth and the existing depth which must return true
 		for the new pixel to be written.
 		*/
-		virtual void setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL) = 0;
+		void setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
+		virtual void setDepthBufferFunction_internal(CompareFunction func = CMPF_LESS_EQUAL) = 0;
+
 		/** 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
@@ -606,7 +618,9 @@ namespace CamelotEngine
 		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. */
-		virtual void setColorBufferWriteEnabled(bool red, bool green, bool blue, bool alpha) = 0;
+		void setColorBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
+		virtual void setColorBufferWriteEnabled_internal(bool red, bool green, bool blue, bool alpha) = 0;
+
 		/** 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
@@ -629,12 +643,12 @@ namespace CamelotEngine
 		cards.
 
 		*/
-		virtual void setDepthBias(float constantBias, float slopeScaleBias = 0.0f) = 0;
-
-		
+		void setDepthBias(float constantBias, float slopeScaleBias = 0.0f);
+		virtual void setDepthBias_internal(float constantBias, float slopeScaleBias = 0.0f) = 0;
 
 		/** Sets how to rasterise triangles, as points, wireframe or solid polys. */
-		virtual void setPolygonMode(PolygonMode level) = 0;
+		void setPolygonMode(PolygonMode level);
+		virtual void setPolygonMode_internal(PolygonMode level) = 0;
 
 		/** Turns stencil buffer checking on or off. 
 		@remarks
@@ -642,7 +656,8 @@ namespace CamelotEngine
 		buffer) can be turned on or off using this method. By default, stencilling is
 		disabled.
 		*/
-		virtual void setStencilCheckEnabled(bool enabled) = 0;
+		void setStencilCheckEnabled(bool enabled);
+		virtual void setStencilCheckEnabled_internal(bool enabled) = 0;
 		/** Determines if this system supports hardware accelerated stencil buffer. 
 		@remarks
 		Note that the lack of this function doesn't mean you can't do stencilling, but
@@ -695,19 +710,24 @@ namespace CamelotEngine
 		(you'll have to turn off culling) then these parameters will apply for front faces, 
 		and the inverse of them will happen for back faces (keep remains the same).
 		*/
-		virtual void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 
+		void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 
 			UINT32 refValue = 0, UINT32 mask = 0xFFFFFFFF, 
 			StencilOperation stencilFailOp = SOP_KEEP, 
 			StencilOperation depthFailOp = SOP_KEEP,
 			StencilOperation passOp = SOP_KEEP, 
-			bool twoSidedOperation = false) = 0;
-
+			bool twoSidedOperation = false);
 
+		virtual void setStencilBufferParams_internal(CompareFunction func = CMPF_ALWAYS_PASS, 
+			UINT32 refValue = 0, UINT32 mask = 0xFFFFFFFF, 
+			StencilOperation stencilFailOp = SOP_KEEP, 
+			StencilOperation depthFailOp = SOP_KEEP,
+			StencilOperation passOp = SOP_KEEP, 
+			bool twoSidedOperation = false) = 0;
 
 		/** Sets the current vertex declaration, ie the source of vertex data. */
-		virtual void setVertexDeclaration(VertexDeclarationPtr decl) = 0;
+		virtual void setVertexDeclaration_internal(VertexDeclarationPtr decl) = 0;
 		/** Sets the current vertex buffer binding state. */
-		virtual void setVertexBufferBinding(VertexBufferBinding* binding) = 0;
+		virtual void setVertexBufferBinding_internal(VertexBufferBinding* binding) = 0;
 
 		/**
 		Render something to the active viewport.
@@ -721,21 +741,23 @@ namespace CamelotEngine
 		@param op A rendering operation instance, which contains
 		details of the operation to be performed.
 		*/
-		virtual void render(const RenderOperation& op);
+		void render(const RenderOperation& op);
+		virtual void render_internal(const RenderOperation& op);
 
 		/** Gets the capabilities of the render system. */
-		const RenderSystemCapabilities* getCapabilities(void) const { return mCurrentCapabilities; }
+		const RenderSystemCapabilities* getCapabilities_internal(void) const { return mCurrentCapabilities; }
 
 
 		/** Returns the driver version.
 		*/
-		virtual const DriverVersion& getDriverVersion(void) const { return mDriverVersion; }
+		virtual const DriverVersion& getDriverVersion_internal(void) const { return mDriverVersion; }
 
 		/** Binds a given GpuProgram (but not the parameters). 
 		@remarks Only one GpuProgram of each type can be bound at once, binding another
 		one will simply replace the existing one.
 		*/
 		void bindGpuProgram(GpuProgramRef prg);
+		virtual void bindGpuProgram_internal(GpuProgramRef prg);
 
 		/** Bind Gpu program parameters.
 		@param gptype The type of program to bind the parameters to
@@ -744,28 +766,35 @@ namespace CamelotEngine
 		*/
 		void bindGpuProgramParameters(GpuProgramType gptype, 
 			GpuProgramParametersSharedPtr params, UINT16 variabilityMask);
+		virtual void bindGpuProgramParameters_internal(GpuProgramType gptype, 
+			GpuProgramParametersSharedPtr params, UINT16 variabilityMask) = 0;
 
 		/** Unbinds GpuPrograms of a given GpuProgramType.
 		@remarks
 		This returns the pipeline to fixed-function processing for this type.
 		*/
 		void unbindGpuProgram(GpuProgramType gptype);
+		virtual void unbindGpuProgram_internal(GpuProgramType gptype);
 
 		/** Returns whether or not a Gpu program of the given type is currently bound. */
 		virtual bool isGpuProgramBound(GpuProgramType gptype);
 
 		/** Sets the user clipping region.
 		*/
-		virtual void setClipPlanes(const PlaneList& clipPlanes);
+		void setClipPlanes(const PlaneList& clipPlanes);
+		virtual void setClipPlanes_internal(const PlaneList& clipPlanes);
 
 		/** Add a user clipping plane. */
-		virtual void addClipPlane (const Plane &p);
+		void addClipPlane(const Plane &p);
+		virtual void addClipPlane_internal (const Plane &p);
 		/** Add a user clipping plane. */
-		virtual void addClipPlane (float A, float B, float C, float D);
+		void addClipPlane(float A, float B, float C, float D);
+		virtual void addClipPlane_internal (float A, float B, float C, float D);
 
 		/** Clears the user clipping region.
 		*/
-		virtual void resetClipPlanes();
+		void resetClipPlanes();
+		virtual void resetClipPlanes_internal();
 
 		/** Internal method for swapping all the buffers on all render targets,
 		if _updateAllRenderTargets was called with a 'false' parameter. */
@@ -774,12 +803,14 @@ namespace CamelotEngine
 
 		/** Sets whether or not vertex windings set should be inverted; this can be important
 		for rendering reflections. */
-		virtual void setInvertVertexWinding(bool invert);
+		void setInvertVertexWinding(bool invert);
+		virtual void setInvertVertexWinding_internal(bool invert);
 
 		/** Indicates whether or not the vertex windings set will be inverted for the current render (e.g. reflections)
 		@see RenderSystem::setInvertVertexWinding
 		*/
-		virtual bool getInvertVertexWinding(void) const;
+		bool getInvertVertexWinding(void) const;
+		virtual bool getInvertVertexWinding_internal(void) const;
 
 		/** Sets the 'scissor region' ie the region of the target in which rendering can take place.
 		@remarks
@@ -792,7 +823,9 @@ namespace CamelotEngine
 		@param left, top, right, bottom The location of the corners of the rectangle, expressed in
 		<i>pixels</i>.
 		*/
-		virtual void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, 
+		void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, 
+			size_t right = 800, size_t bottom = 600);
+		virtual void setScissorTest_internal(bool enabled, size_t left = 0, size_t top = 0, 
 			size_t right = 800, size_t bottom = 600) = 0;
 
 		/** Clears one or more frame buffers on the active render target. 
@@ -802,35 +835,23 @@ namespace CamelotEngine
 		@param depth The value to initialise the depth buffer with, if enabled
 		@param stencil The value to initialise the stencil buffer with, if enabled.
 		*/
-		virtual void clearFrameBuffer(unsigned int buffers, 
-			const Color& colour = Color::Black, 
+		void clearFrameBuffer(unsigned int buffers, 
+			const Color& color = Color::Black, 
+			float depth = 1.0f, unsigned short stencil = 0);
+		virtual void clearFrameBuffer_internal(unsigned int buffers, 
+			const Color& color = Color::Black, 
 			float depth = 1.0f, unsigned short stencil = 0) = 0;
 
 		/**
          * Set current render target to target, enabling its device context if needed
          */
-        virtual void setRenderTarget(RenderTarget *target) = 0;
-
-		/**
-		* Gets the number of display monitors.
-		@see Root::getDisplayMonitorCount
-		*/
-		virtual unsigned int getDisplayMonitorCount() const = 0;
+		void setRenderTarget(RenderTarget *target);
+        virtual void setRenderTarget_internal(RenderTarget *target) = 0;
 
 		/************************************************************************/
 		/* 								UTILITY METHODS                    		*/
 		/************************************************************************/
 
-		/** Generates a packed data version of the passed in ColourValue suitable for
-		use as with this RenderSystem.
-		@remarks
-		Since different render systems have different colour data formats (eg
-		RGBA for GL, ARGB for D3D) this method allows you to use 1 method for all.
-		@param colour The colour to convert
-		@param pDest Pointer to location to put the result.
-		*/
-		virtual void convertColorValue(const Color& colour, UINT32* pDest);
-
 		/** Get the native VertexElementType for a compact 32-bit colour value
 		for this rendersystem.
 		*/
@@ -842,7 +863,7 @@ namespace CamelotEngine
 		projection matrix, this method allows each to implement their own correctly and pass
 		back a generic Camelot matrix for storage in the engine.
 		*/
-		virtual void _convertProjectionMatrix(const Matrix4& matrix,
+		virtual void convertProjectionMatrix(const Matrix4& matrix,
 			Matrix4& dest, bool forGpuProgram = false) = 0;
 
 		/** Returns the horizontal texel offset value required for mapping 
@@ -886,22 +907,6 @@ namespace CamelotEngine
 		@see Renderable::getUseIdentityView, Renderable::getUseIdentityProjection
 		*/
 		virtual float getMaximumDepthInputValue(void) = 0;
-
-		/************************************************************************/
-		/* 							INTERNAL CALLBACKS                     		*/
-		/************************************************************************/
-	protected:
-		virtual void startUp_internal();
-
-		virtual void createRenderWindow_internal(const String &name, unsigned int width, unsigned int height, 
-			bool fullScreen, const NameValuePairList& miscParams, AsyncOp& asyncOp) = 0;
-
-		virtual void bindGpuProgram_internal(GpuProgramRef prg);
-
-		virtual void unbindGpuProgram_internal(GpuProgramType gptype);
-
-		virtual void bindGpuProgramParameters_internal(GpuProgramType gptype, 
-			GpuProgramParametersSharedPtr params, UINT16 variabilityMask) = 0;
 		/************************************************************************/
 		/* 						INTERNAL DATA & METHODS                      	*/
 		/************************************************************************/
@@ -922,7 +927,7 @@ namespace CamelotEngine
 
 		CullingMode mCullingMode;
 
-		bool mVSync;
+		bool mVsync;
 		unsigned int mVSyncInterval;
 
 		bool mInvertVertexWinding;
@@ -951,6 +956,27 @@ namespace CamelotEngine
 		/** Initialize the render system from the capabilities*/
 		virtual void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary) = 0;
 
+		/**	Create a MultiRenderTarget, which is a render target that renders to multiple RenderTextures
+		at once. Surfaces can be bound and unbound at will.
+		This fails if mCapabilities->getNumMultiRenderTargets() is smaller than 2.
+		*/
+		virtual MultiRenderTarget * createMultiRenderTarget_internal(const String & name) = 0; 
+
+		/** Returns a pointer to the render target with the passed name, or NULL if that
+		render target cannot be found.
+		*/
+		virtual RenderTarget * getRenderTarget_internal( const String &name );
+		/** Detaches the render target with the passed name from the render system and
+		returns a pointer to it.
+		@note
+		If the render target cannot be found, NULL is returned.
+		*/
+		virtual RenderTarget * detachRenderTarget_internal( const String &name );
+
+		/** Returns a description of an error code.
+		*/
+		virtual String getErrorDescription_internal(long errorNumber) const = 0;
+
 		DriverVersion mDriverVersion;
 
 		/************************************************************************/
@@ -984,10 +1010,16 @@ namespace CamelotEngine
 		CM_THREAD_TYPE* mRenderThread;
 #endif
 
+		// Context on which all resource commands are queued
 		mutable RenderSystemContextPtr mResourceContext;
+		// Primary context created when the render system is first started up
 		RenderSystemContextPtr mPrimaryContext;
+		// Currently active context. All new commands will be executed on this context.
 		mutable RenderSystemContextPtr mActiveContext;
 
+		// Context that is currently being executed
+		RenderSystemContextPtr mExecutingContext;
+
 		vector<RenderSystemContextPtr>::type mRenderSystemContexts;
 		boost::signal<void()> PreRenderThreadUpdateCallback;
 		boost::signal<void()> PostRenderThreadUpdateCallback;
@@ -1024,11 +1056,11 @@ namespace CamelotEngine
 		void submitToGpu(RenderSystemContextPtr context, bool blockUntilComplete);
 
 		/**
-		 * @brief	Sets an active context on which all subsequent RenderSystem calls will be executed on.
-		 * 			
-		 * @note	context must not be null.
+		 * @brief	Gets the currently active render system object.
+		 *
+		 * @return	The active context.
 		 */
-		void setActiveContext(RenderSystemContextPtr context);
+		RenderSystemContextPtr getActiveContext() const;
 
 	public:
 		/**
@@ -1046,6 +1078,13 @@ namespace CamelotEngine
 		 */
 		RenderSystemContextPtr createRenderSystemContext();
 
+		/**
+		 * @brief	Sets an active context on which all subsequent RenderSystem calls will be executed on.
+		 * 			
+		 * @note	context must not be null.
+		 */
+		void setActiveContext(RenderSystemContextPtr context);
+
 		/**
 		 * @brief	Callback that is called from the render thread before it starts processing
 		 * 			deferred render commands.

+ 6 - 0
CamelotRenderer/Include/CmRenderSystemContext.h

@@ -2,6 +2,7 @@
 
 #include "CmPrerequisites.h"
 #include "CmAsyncOp.h"
+#include "CmCommon.h"
 #include "boost/function.hpp"
 
 namespace CamelotEngine
@@ -121,5 +122,10 @@ namespace CamelotEngine
 		// TODO - This is actually a clumsy way of keeping state. Better and more generic way would be to
 		// search through all commands for a specific state change and find what it is.
 		bool waitForVerticalBlank;
+		CullingMode cullingMode;
+		bool vertexProgramBound;
+        bool geometryProgramBound;
+		bool fragmentProgramBound;
+		bool invertVertexWinding;
 	};
 }

+ 2 - 2
CamelotRenderer/Source/CmCamera.cpp

@@ -497,9 +497,9 @@ namespace CamelotEngine {
 
 		RenderSystem* renderSystem = CamelotEngine::RenderSystemManager::getActive();
 		// API specific
-		renderSystem->_convertProjectionMatrix(mProjMatrix, mProjMatrixRS);
+		renderSystem->convertProjectionMatrix(mProjMatrix, mProjMatrixRS);
 		// API specific for Gpu Programs
-		renderSystem->_convertProjectionMatrix(mProjMatrix, mProjMatrixRSDepth, true);
+		renderSystem->convertProjectionMatrix(mProjMatrix, mProjMatrixRSDepth, true);
 
 
 		// Calculate bounding box (local)

+ 1 - 1
CamelotRenderer/Source/CmGpuProgram.cpp

@@ -86,7 +86,7 @@ namespace CamelotEngine
             return false;
 
 		RenderSystem* rs = CamelotEngine::RenderSystemManager::getActive();
-		return rs->getCapabilities()->isShaderProfileSupported(mSyntaxCode);
+		return rs->getCapabilities_internal()->isShaderProfileSupported(mSyntaxCode);
     }
 	//-----------------------------------------------------------------------------
 	bool GpuProgram::isRequiredCapabilitiesSupported(void) const

+ 3 - 3
CamelotRenderer/Source/CmGpuProgramManager.cpp

@@ -71,7 +71,7 @@ namespace CamelotEngine {
 			RenderSystem* rs = CamelotEngine::RenderSystemManager::getActive();
 
 			// Get the supported syntaxed from RenderSystemCapabilities 
-			return rs->getCapabilities()->getSupportedShaderProfiles();
+			return rs->getCapabilities_internal()->getSupportedShaderProfiles();
         }
 
     //---------------------------------------------------------------------------
@@ -81,7 +81,7 @@ namespace CamelotEngine {
 			RenderSystem* rs = CamelotEngine::RenderSystemManager::getActive();
 
 			// Get the supported syntaxed from RenderSystemCapabilities 
-			return rs->getCapabilities()->isShaderProfileSupported(syntaxCode);
+			return rs->getCapabilities_internal()->isShaderProfileSupported(syntaxCode);
 		}
 
 	//---------------------------------------------------------------------------
@@ -90,7 +90,7 @@ namespace CamelotEngine {
 		// Use the current render system
 		RenderSystem* rs = CamelotEngine::RenderSystemManager::getActive();
 
-		return  rs->getCapabilities()->gpuProgProfileToRSSpecificProfile(gpuProgProfile);
+		return  rs->getCapabilities_internal()->gpuProgProfileToRSSpecificProfile(gpuProgProfile);
 	}
 	//-----------------------------------------------------------------------------
 	GpuProgramParametersSharedPtr GpuProgramManager::createParameters(void)

+ 410 - 128
CamelotRenderer/Source/CmRenderSystem.cpp

@@ -52,7 +52,7 @@ namespace CamelotEngine {
         // This means CULL clockwise vertices, i.e. front of poly is counter-clockwise
         // This makes it the same as OpenGL and other right-handed systems
         , mCullingMode(CULL_CLOCKWISE)
-        , mVSync(true)
+		, mVsync(false)
 		, mVSyncInterval(1)
         , mInvertVertexWinding(false)
         , mDisabledTexUnitsFrom(0)
@@ -85,11 +85,38 @@ namespace CamelotEngine {
 		initRenderThread(); // TODO - Move render thread to the outside of the RS
 
 		{
-			CM_LOCK_MUTEX(mResourceContextMutex)
-				mResourceContext->queueCommand(boost::bind(&RenderSystem::startUp_internal, this));
+			CM_LOCK_MUTEX(mResourceContextMutex);
+			mResourceContext->queueCommand(boost::bind(&RenderSystem::startUp_internal, this));
 		}
 	}
 	//-----------------------------------------------------------------------
+	void RenderSystem::startUp_internal()
+	{
+		mVertexProgramBound = false;
+		mGeometryProgramBound = false;
+		mFragmentProgramBound = false;
+	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::shutdown(void)
+	{
+		// Remove all the render targets.
+		// (destroy primary target last since others may depend on it)
+		RenderTarget* primary = 0;
+		for (RenderTargetMap::iterator it = mRenderTargets.begin(); it != mRenderTargets.end(); ++it)
+		{
+			if (!primary && it->second->isPrimary())
+				primary = it->second;
+			else
+				delete it->second;
+		}
+		delete primary;
+		mRenderTargets.clear();
+
+		mPrioritisedRenderTargets.clear();
+
+		shutdownRenderThread();
+	}
+	//-----------------------------------------------------------------------
 	void RenderSystem::swapAllRenderTargetBuffers(bool waitForVSync)
 	{
 		CM_LOCK_MUTEX(mActiveContextMutex);
@@ -127,23 +154,23 @@ namespace CamelotEngine {
 		return op.getReturnValue<RenderWindow*>();
 	}
     //---------------------------------------------------------------------------------------------
-    void RenderSystem::destroyRenderWindow(const String& name)
+    void RenderSystem::destroyRenderWindow_internal(const String& name)
     {
-        destroyRenderTarget(name);
+        destroyRenderTarget_internal(name);
     }
     //---------------------------------------------------------------------------------------------
-    void RenderSystem::destroyRenderTexture(const String& name)
+    void RenderSystem::destroyRenderTexture_internal(const String& name)
     {
-        destroyRenderTarget(name);
+        destroyRenderTarget_internal(name);
     }
     //---------------------------------------------------------------------------------------------
-    void RenderSystem::destroyRenderTarget(const String& name)
+    void RenderSystem::destroyRenderTarget_internal(const String& name)
     {
-        RenderTarget* rt = detachRenderTarget(name);
+        RenderTarget* rt = detachRenderTarget_internal(name);
         delete rt;
     }
     //---------------------------------------------------------------------------------------------
-    void RenderSystem::attachRenderTarget( RenderTarget &target )
+    void RenderSystem::attachRenderTarget_internal( RenderTarget &target )
     {
 		assert( target.getPriority() < OGRE_NUM_RENDERTARGET_GROUPS );
 
@@ -153,7 +180,7 @@ namespace CamelotEngine {
     }
 
     //---------------------------------------------------------------------------------------------
-    RenderTarget * RenderSystem::getRenderTarget( const String &name )
+    RenderTarget * RenderSystem::getRenderTarget_internal( const String &name )
     {
         RenderTargetMap::iterator it = mRenderTargets.find( name );
         RenderTarget *ret = NULL;
@@ -167,7 +194,7 @@ namespace CamelotEngine {
     }
 
     //---------------------------------------------------------------------------------------------
-    RenderTarget * RenderSystem::detachRenderTarget( const String &name )
+    RenderTarget * RenderSystem::detachRenderTarget_internal( const String &name )
     {
         RenderTargetMap::iterator it = mRenderTargets.find( name );
         RenderTarget *ret = NULL;
@@ -195,13 +222,27 @@ namespace CamelotEngine {
 
         return ret;
     }
+	//-----------------------------------------------------------------------
+	void RenderSystem::setViewport(const Viewport& vp)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setViewport_internal, this, vp));
+	}
     //-----------------------------------------------------------------------
-    Viewport RenderSystem::getViewport(void)
+    Viewport RenderSystem::getViewport_internal(void)
     {
         return mActiveViewport;
     }
     //-----------------------------------------------------------------------
-    void RenderSystem::setTextureUnitSettings(size_t texUnit, const TexturePtr& tex, const SamplerState& tl)
+    void RenderSystem::setTextureUnitSettings(size_t texUnit, const TexturePtr& tex, const SamplerState& samplerState)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setTextureUnitSettings_internal, this, texUnit, tex, samplerState));
+	}
+	//-----------------------------------------------------------------------
+    void RenderSystem::setTextureUnitSettings_internal(size_t texUnit, const TexturePtr& tex, const SamplerState& tl)
     {
         // This method is only ever called to set a texture unit to valid details
         // The method _disableTextureUnit is called to turn a unit off
@@ -213,56 +254,84 @@ namespace CamelotEngine {
 			if (tl.getBindingType() == SamplerState::BT_VERTEX)
 			{
 				// Bind vertex texture
-				setVertexTexture(texUnit, tex);
+				setVertexTexture_internal(texUnit, tex);
 				// bind nothing to fragment unit (hardware isn't shared but fragment
 				// unit can't be using the same index
-				setTexture(texUnit, true, sNullTexPtr);
+				setTexture_internal(texUnit, true, sNullTexPtr);
 			}
 			else
 			{
 				// vice versa
-				setVertexTexture(texUnit, sNullTexPtr);
-				setTexture(texUnit, true, tex);
+				setVertexTexture_internal(texUnit, sNullTexPtr);
+				setTexture_internal(texUnit, true, tex);
 			}
 		}
 		else
 		{
 			// Shared vertex / fragment textures or no vertex texture support
 			// Bind texture (may be blank)
-			setTexture(texUnit, true, tex);
+			setTexture_internal(texUnit, true, tex);
 		}
 
         // Set texture layer filtering
-        setTextureFiltering(texUnit, 
+        setTextureFiltering_internal(texUnit, 
             tl.getTextureFiltering(FT_MIN), 
             tl.getTextureFiltering(FT_MAG), 
             tl.getTextureFiltering(FT_MIP));
 
         // Set texture layer filtering
-        setTextureAnisotropy(texUnit, tl.getTextureAnisotropy());
+        setTextureAnisotropy_internal(texUnit, tl.getTextureAnisotropy());
 
 		// Set mipmap biasing
-		setTextureMipmapBias(texUnit, tl.getTextureMipmapBias());
+		setTextureMipmapBias_internal(texUnit, tl.getTextureMipmapBias());
 
         // Texture addressing mode
         const SamplerState::UVWAddressingMode& uvw = tl.getTextureAddressingMode();
-        setTextureAddressingMode(texUnit, uvw);
+        setTextureAddressingMode_internal(texUnit, uvw);
     }
+	//-----------------------------------------------------------------------
+	void RenderSystem::setTexture(size_t unit, bool enabled, const TexturePtr &texPtr)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setTexture_internal, this, unit, enabled, texPtr));
+	}
 	//-----------------------------------------------------------------------
 	void RenderSystem::setVertexTexture(size_t unit, const TexturePtr& tex)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setVertexTexture_internal, this, unit, tex));
+	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::setVertexTexture_internal(size_t unit, const TexturePtr& tex)
 	{
 		CM_EXCEPT(NotImplementedException, 
 			"This rendersystem does not support separate vertex texture samplers, "
 			"you should use the regular texture samplers which are shared between "
 			"the vertex and fragment units.");
 	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::disableTextureUnit(size_t texUnit)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::disableTextureUnit_internal, this, texUnit));
+	}
     //-----------------------------------------------------------------------
-    void RenderSystem::disableTextureUnit(size_t texUnit)
+    void RenderSystem::disableTextureUnit_internal(size_t texUnit)
     {
-        setTexture(texUnit, false, sNullTexPtr);
+        setTexture_internal(texUnit, false, sNullTexPtr);
     }
+	//---------------------------------------------------------------------
+	void RenderSystem::disableTextureUnitsFrom(size_t texUnit)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::disableTextureUnitsFrom_internal, this, texUnit));
+	}
     //---------------------------------------------------------------------
-    void RenderSystem::disableTextureUnitsFrom(size_t texUnit)
+    void RenderSystem::disableTextureUnitsFrom_internal(size_t texUnit)
     {
         size_t disableTo = CM_MAX_TEXTURE_LAYERS;
         if (disableTo > mDisabledTexUnitsFrom)
@@ -270,21 +339,89 @@ namespace CamelotEngine {
         mDisabledTexUnitsFrom = texUnit;
         for (size_t i = texUnit; i < disableTo; ++i)
         {
-            disableTextureUnit(i);
+            disableTextureUnit_internal(i);
         }
     }
+	//-----------------------------------------------------------------------
+	void RenderSystem::setTextureFiltering(size_t unit, FilterOptions minFilter,
+		FilterOptions magFilter, FilterOptions mipFilter)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setTextureFiltering_internal, this, unit, minFilter, magFilter, mipFilter));
+	}
     //-----------------------------------------------------------------------
-    void RenderSystem::setTextureFiltering(size_t unit, FilterOptions minFilter,
+    void RenderSystem::setTextureFiltering_internal(size_t unit, FilterOptions minFilter,
             FilterOptions magFilter, FilterOptions mipFilter)
     {
-        setTextureFiltering(unit, FT_MIN, minFilter);
-        setTextureFiltering(unit, FT_MAG, magFilter);
-        setTextureFiltering(unit, FT_MIP, mipFilter);
+        setTextureFiltering_internal(unit, FT_MIN, minFilter);
+        setTextureFiltering_internal(unit, FT_MAG, magFilter);
+        setTextureFiltering_internal(unit, FT_MIP, mipFilter);
     }
 	//-----------------------------------------------------------------------
-	CullingMode RenderSystem::getCullingMode(void) const
+	void RenderSystem::setTextureAnisotropy(size_t unit, unsigned int maxAnisotropy)
 	{
-		return mCullingMode;
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setTextureAnisotropy_internal, this, unit, maxAnisotropy));
+	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::setTextureAddressingMode(size_t unit, const SamplerState::UVWAddressingMode& uvw)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setTextureAddressingMode_internal, this, unit, uvw));
+	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::setTextureBorderColor(size_t unit, const Color& color)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setTextureBorderColor_internal, this, unit, color));
+	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::setTextureMipmapBias(size_t unit, float bias)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setTextureMipmapBias_internal, this, unit, bias));
+	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::setPointParameters(float size, bool attenuationEnabled, 
+		float constant, float linear, float quadratic, float minSize, float maxSize)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setPointParameters_internal, this, size, attenuationEnabled, constant, linear, quadratic, minSize, maxSize));
+	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setSceneBlending_internal, this, sourceFactor, destFactor, op));
+	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, 
+		SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setSeparateSceneBlending_internal, this, sourceFactor, destFactor, sourceFactorAlpha, destFactorAlpha, op, alphaOp));
+	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setAlphaRejectSettings_internal, this, func, value, alphaToCoverage));
+	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::setScissorTest(bool enabled, size_t left, size_t top, size_t right, size_t bottom)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setScissorTest_internal, this, enabled, left, top, right, bottom));
 	}
 	//-----------------------------------------------------------------------
 	bool RenderSystem::getWaitForVerticalBlank(void) const
@@ -294,72 +431,167 @@ namespace CamelotEngine {
 		return mActiveContext->waitForVerticalBlank;
 	}
 	//-----------------------------------------------------------------------
+	bool RenderSystem::getWaitForVerticalBlank_internal(void) const
+	{
+		return mVsync;
+	}
+	//-----------------------------------------------------------------------
 	void RenderSystem::setWaitForVerticalBlank(bool enabled)
 	{
 		CM_LOCK_MUTEX(mActiveContextMutex);
 
 		mActiveContext->waitForVerticalBlank = enabled;
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setWaitForVerticalBlank_internal, this, enabled));
 	}
-    //-----------------------------------------------------------------------
-    void RenderSystem::shutdown(void)
-    {
-        // Remove all the render targets.
-		// (destroy primary target last since others may depend on it)
-		RenderTarget* primary = 0;
-		for (RenderTargetMap::iterator it = mRenderTargets.begin(); it != mRenderTargets.end(); ++it)
-		{
-			if (!primary && it->second->isPrimary())
-				primary = it->second;
-			else
-				delete it->second;
-		}
-		delete primary;
-		mRenderTargets.clear();
-
-		mPrioritisedRenderTargets.clear();
-
-		shutdownRenderThread();
-    }
-    //-----------------------------------------------------------------------
-	void RenderSystem::convertColorValue(const Color& colour, UINT32* pDest)
+	//-----------------------------------------------------------------------
+	void RenderSystem::setWaitForVerticalBlank_internal(bool enabled)
+	{
+		mVsync = enabled;
+	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::setInvertVertexWinding(bool invert)
 	{
-		*pDest = VertexElement::convertColourValue(colour, getColorVertexElementType());
+		CM_LOCK_MUTEX(mActiveContextMutex);
 
+		mActiveContext->invertVertexWinding = invert;
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setInvertVertexWinding_internal, this, invert));
+	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::setInvertVertexWinding_internal(bool invert)
+	{
+		mInvertVertexWinding = invert;
 	}
-    //-----------------------------------------------------------------------
-    void RenderSystem::render(const RenderOperation& op)
-    {
-		// sort out clip planes
-		// have to do it here in case of matrix issues
-		if (mClipPlanesDirty)
-		{
-			setClipPlanesImpl(mClipPlanes);
-			mClipPlanesDirty = false;
-		}
-    }
-    //-----------------------------------------------------------------------
-    void RenderSystem::setInvertVertexWinding(bool invert)
-    {
-        mInvertVertexWinding = invert;
-    }
 	//-----------------------------------------------------------------------
 	bool RenderSystem::getInvertVertexWinding(void) const
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		return mActiveContext->invertVertexWinding;
+	}
+	//-----------------------------------------------------------------------
+	bool RenderSystem::getInvertVertexWinding_internal(void) const
 	{
 		return mInvertVertexWinding;
 	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::setDepthBufferParams(bool depthTest, bool depthWrite, CompareFunction depthFunction)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setDepthBufferParams_internal, this, depthTest, depthWrite, depthFunction));
+	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::setDepthBufferCheckEnabled(bool enabled)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setDepthBufferCheckEnabled_internal, this, enabled));
+	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::setDepthBufferWriteEnabled(bool enabled)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setDepthBufferWriteEnabled_internal, this, enabled));
+	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::setDepthBufferFunction(CompareFunction func)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setDepthBufferFunction_internal, this, func));
+	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::setColorBufferWriteEnabled(bool red, bool green, bool blue, bool alpha)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setColorBufferWriteEnabled_internal, this, red, green, blue, alpha));
+	}
+	//---------------------------------------------------------------------
+	void RenderSystem::setDepthBias(float constantBias, float slopeScaleBias)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setDepthBias_internal, this, constantBias, slopeScaleBias));
+	}
+	//---------------------------------------------------------------------
+	void RenderSystem::setPolygonMode(PolygonMode level)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setPolygonMode_internal, this, level));
+	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::setStencilCheckEnabled(bool enabled)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setStencilCheckEnabled_internal, this, enabled));
+	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::setStencilBufferParams(CompareFunction func, UINT32 refValue, UINT32 mask, StencilOperation stencilFailOp, 
+		StencilOperation depthFailOp, StencilOperation passOp, bool twoSidedOperation)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setStencilBufferParams_internal, this, func, refValue, mask, stencilFailOp, depthFailOp, passOp, twoSidedOperation));
+	}
+	//-----------------------------------------------------------------------
+	CullingMode RenderSystem::getCullingMode(void) const
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		return mActiveContext->cullingMode;
+	}
+	//-----------------------------------------------------------------------
+	CullingMode RenderSystem::getCullingMode_internal(void) const
+	{
+		return mCullingMode;
+	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::setCullingMode(CullingMode mode)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->cullingMode = mode;
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setCullingMode_internal, this, mode));
+	}
 	//---------------------------------------------------------------------
-	void RenderSystem::addClipPlane (const Plane &p)
+	void RenderSystem::addClipPlane(const Plane &p)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::addClipPlane_internal, this, p));
+	}
+	//---------------------------------------------------------------------
+	void RenderSystem::addClipPlane_internal (const Plane &p)
 	{
 		mClipPlanes.push_back(p);
 		mClipPlanesDirty = true;
 	}
 	//---------------------------------------------------------------------
-	void RenderSystem::addClipPlane (float A, float B, float C, float D)
+	void RenderSystem::addClipPlane(float A, float B, float C, float D)
 	{
-		addClipPlane(Plane(A, B, C, D));
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::addClipPlane_internal, this, A, B, C, D));
+	}
+	//---------------------------------------------------------------------
+	void RenderSystem::addClipPlane_internal (float A, float B, float C, float D)
+	{
+		addClipPlane_internal(Plane(A, B, C, D));
 	}
 	//---------------------------------------------------------------------
 	void RenderSystem::setClipPlanes(const PlaneList& clipPlanes)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setClipPlanes_internal, this, clipPlanes));
+	}
+	//---------------------------------------------------------------------
+	void RenderSystem::setClipPlanes_internal(const PlaneList& clipPlanes)
 	{
 		if (clipPlanes != mClipPlanes)
 		{
@@ -369,6 +601,13 @@ namespace CamelotEngine {
 	}
 	//---------------------------------------------------------------------
 	void RenderSystem::resetClipPlanes()
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::resetClipPlanes_internal, this));
+	}
+	//---------------------------------------------------------------------
+	void RenderSystem::resetClipPlanes_internal()
 	{
 		if (!mClipPlanes.empty())
 		{
@@ -384,6 +623,26 @@ namespace CamelotEngine {
 		mActiveContext->queueCommand(boost::bind(&RenderSystem::bindGpuProgram_internal, this, prg));
 	}
 	//-----------------------------------------------------------------------
+	void RenderSystem::bindGpuProgram_internal(GpuProgramRef prg)
+	{
+		switch(prg->_getBindingDelegate()->getType())
+		{
+		case GPT_VERTEX_PROGRAM:
+			// mark clip planes dirty if changed (programmable can change space)
+			if (!mVertexProgramBound && !mClipPlanes.empty())
+				mClipPlanesDirty = true;
+
+			mVertexProgramBound = true;
+			break;
+		case GPT_GEOMETRY_PROGRAM:
+			mGeometryProgramBound = true;
+			break;
+		case GPT_FRAGMENT_PROGRAM:
+			mFragmentProgramBound = true;
+			break;
+		}
+	}
+	//-----------------------------------------------------------------------
 	void RenderSystem::unbindGpuProgram(GpuProgramType gptype)
 	{
 		CM_LOCK_MUTEX(mActiveContextMutex);
@@ -391,6 +650,25 @@ namespace CamelotEngine {
 	    mActiveContext->queueCommand(boost::bind(&RenderSystem::unbindGpuProgram_internal, this, gptype));
 	}
 	//-----------------------------------------------------------------------
+	void RenderSystem::unbindGpuProgram_internal(GpuProgramType gptype)
+	{
+		switch(gptype)
+		{
+		case GPT_VERTEX_PROGRAM:
+			// mark clip planes dirty if changed (programmable can change space)
+			if (mVertexProgramBound && !mClipPlanes.empty())
+				mClipPlanesDirty = true;
+			mVertexProgramBound = false;
+			break;
+		case GPT_GEOMETRY_PROGRAM:
+			mGeometryProgramBound = false;
+			break;
+		case GPT_FRAGMENT_PROGRAM:
+			mFragmentProgramBound = false;
+			break;
+		}
+	}
+	//-----------------------------------------------------------------------
 	void RenderSystem::bindGpuProgramParameters(GpuProgramType gptype, 
 		GpuProgramParametersSharedPtr params, UINT16 variabilityMask)
 	{
@@ -406,15 +684,61 @@ namespace CamelotEngine {
 	    switch(gptype)
 	    {
         case GPT_VERTEX_PROGRAM:
-            return mVertexProgramBound;
+            return mActiveContext->vertexProgramBound;
         case GPT_GEOMETRY_PROGRAM:
-            return mGeometryProgramBound;
+            return mActiveContext->geometryProgramBound;
         case GPT_FRAGMENT_PROGRAM:
-            return mFragmentProgramBound;
+            return mActiveContext->fragmentProgramBound;
 	    }
         // Make compiler happy
         return false;
 	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::setRenderTarget(RenderTarget *target)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::setRenderTarget_internal, this, target));
+	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::clearFrameBuffer(unsigned int buffers, const Color& color, float depth, unsigned short stencil)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::clearFrameBuffer_internal, this, buffers, color, depth, stencil));
+	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::beginFrame()
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::beginFrame_internal, this));
+	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::endFrame()
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::endFrame_internal, this));
+	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::render(const RenderOperation& op)
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		mActiveContext->queueCommand(boost::bind(&RenderSystem::render_internal, this, op));
+	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::render_internal(const RenderOperation& op)
+	{
+		// sort out clip planes
+		// have to do it here in case of matrix issues
+		if (mClipPlanesDirty)
+		{
+			setClipPlanesImpl(mClipPlanes);
+			mClipPlanesDirty = false;
+		}
+	}
 
 	void RenderSystem::initRenderThread()
 	{
@@ -482,6 +806,7 @@ namespace CamelotEngine {
 			// Play commands
 			for(auto iter = renderSystemContextsCopy.begin(); iter != renderSystemContextsCopy.end(); ++iter)
 			{
+				setActiveContext(*iter);
 				(*iter)->playbackCommands();
 			}
 
@@ -561,6 +886,13 @@ namespace CamelotEngine {
 		mActiveContext = context;
 	}
 
+	RenderSystemContextPtr RenderSystem::getActiveContext() const
+	{
+		CM_LOCK_MUTEX(mActiveContextMutex);
+
+		return mActiveContext;
+	}
+
 	void RenderSystem::update()
 	{
 		{
@@ -581,56 +913,6 @@ namespace CamelotEngine {
 			CM_EXCEPT(InternalErrorException, "Calling the render system from a non-render thread!");
 	}
 
-	/************************************************************************/
-	/* 							INTERNAL CALLBACKS                     		*/
-	/************************************************************************/
-
-	void RenderSystem::startUp_internal()
-	{
-		mVertexProgramBound = false;
-		mGeometryProgramBound = false;
-		mFragmentProgramBound = false;
-	}
-
-	void RenderSystem::bindGpuProgram_internal(GpuProgramRef prg)
-	{
-		switch(prg->_getBindingDelegate()->getType())
-		{
-		case GPT_VERTEX_PROGRAM:
-			// mark clip planes dirty if changed (programmable can change space)
-			if (!mVertexProgramBound && !mClipPlanes.empty())
-				mClipPlanesDirty = true;
-
-			mVertexProgramBound = true;
-			break;
-		case GPT_GEOMETRY_PROGRAM:
-			mGeometryProgramBound = true;
-			break;
-		case GPT_FRAGMENT_PROGRAM:
-			mFragmentProgramBound = true;
-			break;
-		}
-	}
-
-	void RenderSystem::unbindGpuProgram_internal(GpuProgramType gptype)
-	{
-		switch(gptype)
-		{
-		case GPT_VERTEX_PROGRAM:
-			// mark clip planes dirty if changed (programmable can change space)
-			if (mVertexProgramBound && !mClipPlanes.empty())
-				mClipPlanesDirty = true;
-			mVertexProgramBound = false;
-			break;
-		case GPT_GEOMETRY_PROGRAM:
-			mGeometryProgramBound = false;
-			break;
-		case GPT_FRAGMENT_PROGRAM:
-			mFragmentProgramBound = false;
-			break;
-		}
-	}
-
 	/************************************************************************/
 	/* 								THREAD WORKER                      		*/
 	/************************************************************************/

+ 5 - 0
CamelotRenderer/Source/CmRenderSystemContext.cpp

@@ -9,6 +9,11 @@ namespace CamelotEngine
 	RenderSystemContext::RenderSystemContext(CM_THREAD_ID_TYPE threadId)
 		:mMyThreadId(threadId), mReadyCommands(nullptr), mIsExecuting(false)
 		, waitForVerticalBlank(true)
+		, cullingMode(CULL_CLOCKWISE)
+		, vertexProgramBound(false)
+		, geometryProgramBound(false)
+		, fragmentProgramBound(false)
+		, invertVertexWinding(false)
 	{
 		mCommands = new vector<RenderSystemCommand>::type();
 	}

+ 1 - 1
CamelotRenderer/Source/CmVertexIndexData.cpp

@@ -146,7 +146,7 @@ namespace CamelotEngine {
         bool useVertexPrograms = false;
 
 		RenderSystem* rend = CamelotEngine::RenderSystemManager::getActive();
-        if (rend && rend->getCapabilities()->hasCapability(RSC_VERTEX_PROGRAM))
+        if (rend && rend->getCapabilities_internal()->hasCapability(RSC_VERTEX_PROGRAM))
         {
             useVertexPrograms = true;
         }

+ 4 - 4
CamelotRenderer/Source/CmViewport.cpp

@@ -178,11 +178,11 @@ namespace CamelotEngine {
 		RenderSystem* rs = CamelotEngine::RenderSystemManager::getActive();
 		if (rs)
 		{
-			Viewport currentvp = rs->getViewport();
+			Viewport currentvp = rs->getViewport_internal();
 
-			rs->setViewport(*this);
-			rs->clearFrameBuffer(buffers, col, depth, stencil);
-			rs->setViewport(currentvp);
+			rs->setViewport_internal(*this);
+			rs->clearFrameBuffer_internal(buffers, col, depth, stencil);
+			rs->setViewport_internal(currentvp);
 		}
 	}
     //---------------------------------------------------------------------

+ 7 - 0
CamelotRenderer/TODO.txt

@@ -16,6 +16,13 @@ High-level TODO:
 
 
 Command buffer TODO:
+ - Make sure no internal methods call the external interface
+  - Debug checks to make sure external methods don't get called from render thread, and that internal methods ONLY get called from render thread
+ - Don't make _internal methods protected. Other classes like RenderTarget, buffers, etc. will be executing from render thread and they need direct access to them
+ - My current approach doesn't allow multiple threads to use the RenderSystem (contexts should be handled differently)
+ - Make sure the user knows resources are shared between contexts. All resource updates are executed before rendering a frame, so whichever context updated the resource last,
+   was the version that will be used.
+
  Immediate:
   - Resource updates shouldn't happen once per frame. Resources should be submitted to render thread immediately.
   - Port the rest of the RenderSystem of use RenderContext