فهرست منبع

Refactored how are render targets handled in all of the render systems

Marko Pintera 13 سال پیش
والد
کامیت
5eeed8897c

+ 49 - 49
CamelotClient/CamelotClient.cpp

@@ -32,9 +32,9 @@ int CALLBACK WinMain(
 	_In_  int nCmdShow
 	)
 {
-	//gApplication().startUp("CamelotGLRenderSystem", "CamelotForwardRenderer");
+	gApplication().startUp("CamelotGLRenderSystem", "CamelotForwardRenderer");
 	//gApplication().startUp("CamelotD3D9RenderSystem", "CamelotForwardRenderer");
-	gApplication().startUp("CamelotD3D11RenderSystem", "CamelotForwardRenderer");
+	//gApplication().startUp("CamelotD3D11RenderSystem", "CamelotForwardRenderer");
 
 	RenderSystem* renderSystem = RenderSystem::instancePtr();
 	RenderWindowPtr renderWindow = gApplication().getPrimaryRenderWindow();
@@ -77,28 +77,28 @@ int CALLBACK WinMain(
 	//HighLevelGpuProgramHandle vertProgRef =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "hlsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 
 	/////////////////// HLSL 11 SHADERS //////////////////////////
-	String fragShaderCode = "SamplerState samp : register(s0);			\
-							Texture2D tex : register(t0); \
-							float4 ps_main(in float4 inPos : SV_Position, float2 uv : TEXCOORD0) : SV_Target		\
-							{														\
-							float4 color = tex.Sample(samp, uv);				\
-							return color;										\
-							}";
-
-	HighLevelGpuProgramHandle fragProgRef =  HighLevelGpuProgram::create(fragShaderCode, "ps_main", "hlsl", GPT_FRAGMENT_PROGRAM, GPP_PS_4_0);
-
-	String vertShaderCode = "float4x4 matViewProjection;	\
-							void vs_main(										\
-							in float4 inPos : POSITION,							\
-							in float2 uv : TEXCOORD0,								\
-							out float4 oPosition : SV_Position,					\
-							out float2 oUv : TEXCOORD0)							\
-							{														\
-							oPosition = mul(matViewProjection, inPos);			\
-							oUv = uv;											\
-							}";
-
-	HighLevelGpuProgramHandle vertProgRef =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "hlsl", GPT_VERTEX_PROGRAM, GPP_VS_4_0);
+	//String fragShaderCode = "SamplerState samp : register(s0);			\
+	//						Texture2D tex : register(t0); \
+	//						float4 ps_main(in float4 inPos : SV_Position, float2 uv : TEXCOORD0) : SV_Target		\
+	//						{														\
+	//						float4 color = tex.Sample(samp, uv);				\
+	//						return color;										\
+	//						}";
+
+	//HighLevelGpuProgramHandle fragProgRef =  HighLevelGpuProgram::create(fragShaderCode, "ps_main", "hlsl", GPT_FRAGMENT_PROGRAM, GPP_PS_4_0);
+
+	//String vertShaderCode = "float4x4 matViewProjection;	\
+	//						void vs_main(										\
+	//						in float4 inPos : POSITION,							\
+	//						in float2 uv : TEXCOORD0,								\
+	//						out float4 oPosition : SV_Position,					\
+	//						out float2 oUv : TEXCOORD0)							\
+	//						{														\
+	//						oPosition = mul(matViewProjection, inPos);			\
+	//						oUv = uv;											\
+	//						}";
+
+	//HighLevelGpuProgramHandle vertProgRef =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "hlsl", GPT_VERTEX_PROGRAM, GPP_VS_4_0);
 
 	/////////////////// CG SHADERS //////////////////////////
 	//String fragShaderCode = "sampler2D tex;					\
@@ -124,31 +124,31 @@ int CALLBACK WinMain(
 	//HighLevelGpuProgramHandle vertProgRef =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "cg", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 
 	///////////////// GLSL SHADERS ////////////////////////////
-	//String fragShaderCode = " #version 400 \n \
-	//						  uniform sampler2D tex; \
-	//						  in vec2 texcoord0; \
-	//						  out vec4 fragColor; \
-	//						  void main() \
-	//						  {\
-	//							  vec4 texColor = texture2D(tex, texcoord0.st);\
-	//							  fragColor = texColor; \
-	//						  }";
-
-	//HighLevelGpuProgramHandle fragProgRef = HighLevelGpuProgram::create(fragShaderCode, "main", "glsl", GPT_FRAGMENT_PROGRAM, GPP_PS_2_0);
-
-	//// TODO - Make sure to document the strict input parameter naming. (Exact supported names are in GLSLParamParser)
-	//String vertShaderCode = "#version 400 \n \
-	//						 uniform mainFragBlock { mat4 matViewProjection; }; \
-	//						 in vec4 cm_position; \
-	//						 in vec2 cm_texcoord0; \
-	//						 out vec2 texcoord0; \
-	//						 void main() \
-	//						 { \
-	//							texcoord0 = cm_texcoord0; \
-	//							gl_Position = cm_position * matViewProjection; \
-	//						 }";
-
-	//HighLevelGpuProgramHandle vertProgRef= HighLevelGpuProgram::create(vertShaderCode, "main", "glsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
+	String fragShaderCode = " #version 400 \n \
+							  uniform sampler2D tex; \
+							  in vec2 texcoord0; \
+							  out vec4 fragColor; \
+							  void main() \
+							  {\
+								  vec4 texColor = texture2D(tex, texcoord0.st);\
+								  fragColor = texColor; \
+							  }";
+
+	HighLevelGpuProgramHandle fragProgRef = HighLevelGpuProgram::create(fragShaderCode, "main", "glsl", GPT_FRAGMENT_PROGRAM, GPP_PS_2_0);
+
+	// TODO - Make sure to document the strict input parameter naming. (Exact supported names are in GLSLParamParser)
+	String vertShaderCode = "#version 400 \n \
+							 uniform mainFragBlock { mat4 matViewProjection; }; \
+							 in vec4 cm_position; \
+							 in vec2 cm_texcoord0; \
+							 out vec2 texcoord0; \
+							 void main() \
+							 { \
+								texcoord0 = cm_texcoord0; \
+								gl_Position = cm_position * matViewProjection; \
+							 }";
+
+	HighLevelGpuProgramHandle vertProgRef= HighLevelGpuProgram::create(vertShaderCode, "main", "glsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 
 	gResources().create(vertProgRef, "C:\\vertProgCg.vprog", true);
 	gResources().unload(vertProgRef);

+ 2 - 1
CamelotD3D11RenderSystem/Include/CmD3D11RenderWindow.h

@@ -17,7 +17,6 @@ namespace CamelotEngine
 		void setActive(bool state);
 		void setFullscreen(bool fullScreen, unsigned int width, unsigned int height);
 
-		void swapBuffers(bool waitForVSync = true);
 		void copyContentsToMemory(const PixelData &dst, FrameBuffer buffer);
 
 		void windowMovedOrResized();
@@ -39,6 +38,8 @@ namespace CamelotEngine
 		void _destroySizeDependedD3DResources();
 
 		IDXGIDevice* _queryDxgiDevice(); 
+
+		void swapBuffers_internal();
 	
 		bool _checkMultiSampleQuality(UINT SampleCount, UINT *outQuality, DXGI_FORMAT format);
 

+ 3 - 3
CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp

@@ -163,7 +163,7 @@ namespace CamelotEngine
 
 		RenderSystem* rs = RenderSystem::instancePtr();
 		D3D11RenderSystem* d3d11rs = static_cast<D3D11RenderSystem*>(rs);
-		d3d11rs->attachRenderTarget(*this);
+		d3d11rs->_notifyWindowCreated(*this);
 
 		RenderWindow::initialize_internal();
 	}
@@ -194,11 +194,11 @@ namespace CamelotEngine
 		RenderWindow::destroy_internal();
 	}
 
-	void D3D11RenderWindow::swapBuffers(bool waitForVSync)
+	void D3D11RenderWindow::swapBuffers_internal()
 	{
 		if(mDevice.getD3D11Device() != nullptr)
 		{
-			HRESULT hr = mSwapChain->Present(waitForVSync ? mVSyncInterval : 0, 0);
+			HRESULT hr = mSwapChain->Present(mVSync ? mVSyncInterval : 0, 0);
 
 			if( FAILED(hr) )
 				CM_EXCEPT(RenderingAPIException, "Error Presenting surfaces");

+ 4 - 6
CamelotD3D9Renderer/Include/CmD3D9RenderSystem.h

@@ -59,7 +59,10 @@ namespace CamelotEngine
 		 */
 		const String& getShadingLanguageName() const;
 
-		void destroyRenderTarget(RenderTarget* renderTarget);
+		/**
+		 * @copydoc RenderSystem::_notifyWindowCreated.
+		 */
+		void _notifyWindowCreated(RenderWindow& renderWindow);
 
 		/**
 		 * @copydoc RenderSystem::setRenderTarget()
@@ -290,11 +293,6 @@ namespace CamelotEngine
         */
         bool checkTextureFilteringSupported(TextureType ttype, PixelFormat format, int usage);
 
-		/**
-		 * @brief	Called internally by RenderWindowManager whenever a new window is created.
-		 */
-		void registerRenderWindow(D3D9RenderWindow* renderWindow);
-	
 		/************************************************************************/
 		/* 							Sampler states                     			*/
 		/************************************************************************/

+ 2 - 8
CamelotD3D9Renderer/Include/CmD3D9RenderWindow.h

@@ -46,7 +46,6 @@ namespace CamelotEngine
 		bool				isVSync				() const { return mVSync; }
 		void 				reposition			(int left, int top);
 		void 				resize				(unsigned int width, unsigned int height);
-		void 				swapBuffers			( bool waitForVSync = true );
 		HWND 				getWindowHandle		() const { return mHWnd; }				
 		IDirect3DDevice9*	getD3D9Device		();
 		D3D9Device*			getDevice			();
@@ -65,13 +64,6 @@ namespace CamelotEngine
 		/// Build the presentation parameters used with this window
 		void				buildPresentParameters	(D3DPRESENT_PARAMETERS* presentParams);
 		
-
-		/// @copydoc RenderTarget::_beginUpdate
-		void _beginUpdate();
-	
-		/// @copydoc RenderTarget::_endUpdate
-		void _endUpdate();
-
 		/// Accessor for render surface
 		IDirect3DSurface9* getRenderSurface();
 
@@ -100,6 +92,8 @@ namespace CamelotEngine
 
 		void updateWindowRect();
 
+		void swapBuffers_internal();
+
 		/**
 		 * @copydoc RenderWindow::initialize_internal().
 		 */

+ 6 - 28
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -228,17 +228,19 @@ namespace CamelotEngine
 		msD3D9RenderSystem = NULL;
 	}
 	//--------------------------------------------------------------------
-	void D3D9RenderSystem::registerRenderWindow(D3D9RenderWindow* renderWindow)
+	void D3D9RenderSystem::_notifyWindowCreated(RenderWindow& renderWindow)
 	{		
 		THROW_IF_NOT_RENDER_THREAD;
 
+		D3D9RenderWindow* d3d9renderWindow = static_cast<D3D9RenderWindow*>(&renderWindow);
+
 		String msg;
 
 		mResourceManager->lockDeviceAccess();
 
 		try
 		{
-			mDeviceManager->linkRenderWindow(renderWindow);
+			mDeviceManager->linkRenderWindow(d3d9renderWindow);
 		}
 		catch (const CamelotEngine::RenderingAPIException&)
 		{
@@ -252,11 +254,9 @@ namespace CamelotEngine
 		mResourceManager->unlockDeviceAccess();
 
 		// TODO - Storing raw pointer here might not be a good idea?
-		mRenderWindows.push_back(renderWindow);		
-
-		updateRenderSystemCapabilities(renderWindow);
+		mRenderWindows.push_back(d3d9renderWindow);		
 
-		attachRenderTarget(*renderWindow);
+		updateRenderSystemCapabilities(d3d9renderWindow);
 	}	
 
 	void D3D9RenderSystem::bindGpuProgram(GpuProgramHandle prg)
@@ -467,28 +467,6 @@ namespace CamelotEngine
 		};
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::destroyRenderTarget(RenderTarget* renderTarget)
-	{		
-		THROW_IF_NOT_RENDER_THREAD;
-
-		D3D9RenderWindow* renderWindow = NULL;
-
-		// Check render windows
-		D3D9RenderWindowList::iterator sw;
-		for (sw = mRenderWindows.begin(); sw != mRenderWindows.end(); ++sw)
-		{
-			if ((*sw) == renderTarget)
-			{
-				renderWindow = (*sw);					
-				mRenderWindows.erase(sw);
-				break;
-			}
-		}
-		
-		// Do the real removal
-		RenderSystem::destroyRenderTarget(renderTarget);	
-	}
-	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setTexture(GpuProgramType gptype, UINT16 unit, bool enabled, const TexturePtr& tex)
 	{
 		THROW_IF_NOT_RENDER_THREAD;

+ 2 - 43
CamelotD3D9Renderer/Source/CmD3D9RenderWindow.cpp

@@ -250,7 +250,7 @@ namespace CamelotEngine
 		mClosed = false;
 
 		D3D9RenderSystem* rs = static_cast<D3D9RenderSystem*>(RenderSystem::instancePtr());
-		rs->registerRenderWindow(this);
+		rs->_notifyWindowCreated(*this);
 
 		RenderWindow::initialize_internal();
 	}
@@ -604,7 +604,7 @@ namespace CamelotEngine
 		updateWindowRect();
 	}
 
-	void D3D9RenderWindow::swapBuffers( bool waitForVSync )
+	void D3D9RenderWindow::swapBuffers_internal()
 	{
 		if (mDeviceValid)
 			mDevice->present(this);		
@@ -660,47 +660,6 @@ namespace CamelotEngine
 		mDevice->copyContentsToMemory(this, dst, buffer);
 	}
 	//-----------------------------------------------------------------------------
-	void D3D9RenderWindow::_beginUpdate()
-	{		
-		// External windows should update per frame
-		// since it dosen't get the window resize/move messages.
-		if (mIsExternal)
-		{		
-			updateWindowRect();
-		}
-
-		if (mWidth == 0 || mHeight == 0)
-		{
-			mDeviceValid = false;
-			return;
-		}
-
-		D3D9RenderSystem::getDeviceManager()->setActiveRenderTargetDevice(mDevice);
-
-		// Check that device can be used for rendering operations.
-		mDeviceValid = mDevice->validate(this);
-		if (mDeviceValid)
-		{
-			// Finish window / fullscreen mode switch.
-			if (_getSwitchingFullscreen())
-			{
-				_finishSwitchingFullscreen();		
-				// have to re-validate since this may have altered dimensions
-				mDeviceValid = mDevice->validate(this);
-			}
-		}
-
-		RenderWindow::_beginUpdate();
-	}
-	//---------------------------------------------------------------------
-	void D3D9RenderWindow::_endUpdate()
-	{
-		RenderWindow::_endUpdate();
-
-		D3D9RenderSystem::getDeviceManager()->setActiveRenderTargetDevice(NULL);	
-
-	}
-	//-----------------------------------------------------------------------------
 	IDirect3DDevice9* D3D9RenderWindow::getD3D9Device()
 	{
 		return mDevice->getD3D9Device();

+ 11 - 2
CamelotForwardRenderer/Source/CmForwardRenderer.cpp

@@ -11,6 +11,7 @@
 #include "CmDepthStencilState.h"
 #include "CmApplication.h"
 #include "CmViewport.h"
+#include "CmRenderTarget.h"
 
 namespace CamelotEngine
 {
@@ -35,9 +36,17 @@ namespace CamelotEngine
 		for(auto iter = allCameras.begin(); iter != allCameras.end(); ++iter)
 		{
 			render(*iter);
-		}
 
-		renderContext->swapAllRenderTargetBuffers(false);
+			Viewport* vp = (*iter)->getViewport();
+			if(vp != nullptr)
+			{
+				RenderTargetPtr rt = vp->getTarget();
+
+				if(rt != nullptr)
+					rt->swapBuffers(); // TODO - This is wrong as potentially multiple viewports can share a single render target, and swap shouldn't
+				// be done for every one of them
+			}
+		}
 	}
 
 	void ForwardRenderer::render(const CameraPtr camera) 

+ 0 - 3
CamelotGLRenderer/Include/CmGLRenderSystem.h

@@ -200,9 +200,6 @@ namespace CamelotEngine {
 		GLSupport* getGLSupport() const { return mGLSupport; }
 
     private:
-        /// Rendering loop control
-        bool mStopRendering;
-
 		// Scissor test
 		UINT32 mScissorTop, mScissorBottom, mScissorLeft, mScissorRight;
 

+ 2 - 1
CamelotGLRenderer/Include/CmWin32Window.h

@@ -44,7 +44,6 @@ namespace CamelotEngine {
         bool isClosed(void) const;
         void reposition(int left, int top);
         void resize(unsigned int width, unsigned int height);
-        void swapBuffers(bool waitForVSync);
 
 		/** Overridden - see RenderTarget. */
 		virtual void copyContentsToMemory(const PixelData &dst, FrameBuffer buffer);
@@ -85,6 +84,8 @@ namespace CamelotEngine {
         int     mDisplayFrequency;      // fullscreen only, to restore display
         Win32Context *mContext;
 
+		void swapBuffers_internal();
+
 		/**
 		 * @copydoc RenderWindow::initialize_internal().
 		 */

+ 0 - 3
CamelotGLRenderer/Source/CmGLRenderSystem.cpp

@@ -197,7 +197,6 @@ namespace CamelotEngine
 		mBoundIndexBuffer = nullptr;
 
 		mGLSupport->stop();
-		mStopRendering = true;
 
 		TextureManager::shutDown();
 		RenderWindowManager::shutDown();
@@ -211,8 +210,6 @@ namespace CamelotEngine
 		if(mProgramPipelineManager != nullptr)
 			delete mProgramPipelineManager;
 
-		mRenderTargets.clear();
-
 		if(mGLSupport)
 			delete mGLSupport;
 	}

+ 2 - 2
CamelotGLRenderer/Source/CmWin32Window.cpp

@@ -380,7 +380,7 @@ namespace CamelotEngine {
 
 		GLRenderSystem* rs = static_cast<GLRenderSystem*>(RenderSystem::instancePtr());
 
-		rs->attachRenderTarget(*this);
+		rs->_notifyWindowCreated(*this);
 		rs->registerContext(mContext);
 
 		RenderWindow::initialize_internal();
@@ -633,7 +633,7 @@ namespace CamelotEngine {
 		// TODO - Notify viewports of resize
 	}
 
-	void Win32Window::swapBuffers(bool waitForVSync)
+	void Win32Window::swapBuffers_internal()
 	{
 	  if (!mIsExternalGLControl) {
 	  	SwapBuffers(mHDC);

+ 0 - 9
CamelotRenderer/Include/CmDeferredRenderContext.h

@@ -20,11 +20,6 @@ namespace CamelotEngine
 		DeferredRenderContext(RenderSystem* rs, CM_THREAD_ID_TYPE threadId);
 		~DeferredRenderContext();
 
-		/** @copydoc RenderSystem::setWaitForVerticalBlank() */
-		void setWaitForVerticalBlank(bool enabled);
-		/** @copydoc RenderSystem::getWaitForVerticalBlank() */
-		bool getWaitForVerticalBlank(void) const;
-
 		/** @copydoc RenderSystem::disableTextureUnit() */
 		void disableTextureUnit(GpuProgramType gptype, UINT16 texUnit);
 
@@ -97,8 +92,6 @@ namespace CamelotEngine
 		/** @copydoc RenderSystem::drawIndexed() */
 		void drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexCount);
 
-		/** @copydoc RenderSystem::swapAllRenderTargetBuffers() */
-		void swapAllRenderTargetBuffers(bool waitForVsync = true);
 		/** @copydoc RenderSystem::clear() */
 		void clear(RenderTargetPtr target, unsigned int buffers, const Color& color = Color::Black, float depth = 1.0f, unsigned short stencil = 0);
 
@@ -116,7 +109,5 @@ namespace CamelotEngine
 	private:
 		CommandQueue* mCommandQueue;
 		RenderSystem* mRenderSystem;
-
-		bool mWaitForVerticalBlank;
 	};
 }

+ 4 - 45
CamelotRenderer/Include/CmRenderSystem.h

@@ -95,41 +95,11 @@ namespace CamelotEngine
 		 */
 		virtual const String& getShadingLanguageName() const = 0;
 
-		/** Attaches the passed render target to the render system.
+		/** Notifies the render system that a new window was created.  
+		* 
+		* @note Should only be called by internal methods.
 		*/
-		virtual void attachRenderTarget(RenderTarget &target);
-
-		/** Detaches the render target from the render system.
-		@note
-		If the render target cannot be found, NULL is returned.
-		*/
-		virtual void detachRenderTarget(RenderTarget& renderTarget);
-
-		/** Destroys a render window */
-		virtual void destroyRenderWindow(RenderWindow* renderWindow);
-		/** Destroys a render texture */
-		virtual void destroyRenderTexture(RenderTexture* renderTexture);
-		/** Destroys a render target of any sort */
-		virtual void destroyRenderTarget(RenderTarget* renderTarget);
-
-		/** Defines whether or now fullscreen render windows wait for the vertical blank before flipping buffers.
-		@remarks
-		By default, all rendering windows wait for a vertical blank (when the CRT beam turns off briefly to move
-		from the bottom right of the screen back to the top left) before flipping the screen buffers. This ensures
-		that the image you see on the screen is steady. However it restricts the frame rate to the refresh rate of
-		the monitor, and can slow the frame rate down. You can speed this up by not waiting for the blank, but
-		this has the downside of introducing 'tearing' artefacts where part of the previous frame is still displayed
-		as the buffers are switched. Speed vs quality, you choose.
-		@note
-		Has NO effect on windowed mode render targets. Only affects fullscreen mode.
-		@param
-		enabled If true, the system waits for vertical blanks - quality over speed. If false it doesn't - speed over quality.
-		*/
-		void setWaitForVerticalBlank(bool enabled);
-
-		/** Returns true if the system is synchronising frames with the monitor vertical blank.
-		*/
-		bool getWaitForVerticalBlank(void) const;
+		virtual void _notifyWindowCreated(RenderWindow& window);
 
 		/**
 		 * @brief	Sets a sampler state for the specified texture unit.
@@ -279,10 +249,6 @@ namespace CamelotEngine
 		*/
 		virtual void resetClipPlanes();
 
-		/** Internal method for swapping all the buffers on all render targets,
-		if _updateAllRenderTargets was called with a 'false' parameter. */
-		virtual void swapAllRenderTargetBuffers(bool waitForVsync = true);
-
 		/** Sets the 'scissor region' ie the region of the target in which rendering can take place.
 		@remarks
 		This method allows you to 'mask off' rendering in all but a given rectangular area
@@ -379,10 +345,6 @@ namespace CamelotEngine
 	protected:
 		friend class RenderSystemManager;
 
-		/** The render targets. */
-		vector<RenderTarget*>::type mRenderTargets;
-		/** The render targets, ordered by priority. */
-		RenderTargetPriorityMap mPrioritisedRenderTargets;
 		/** The Active render target. */
 		RenderTarget* mActiveRenderTarget;
 
@@ -391,9 +353,6 @@ namespace CamelotEngine
 
 		CullingMode mCullingMode;
 
-		bool mVsync;
-		unsigned int mVSyncInterval;
-
 		bool mInvertVertexWinding;
 
 		/// Texture units from this upwards are disabled

+ 14 - 77
CamelotRenderer/Include/CmRenderTarget.h

@@ -91,29 +91,6 @@ namespace CamelotEngine
         virtual unsigned int getHeight(void) const;
         virtual unsigned int getColourDepth(void) const;
 
-        /** Tells the target to update it's contents.
-            @remarks
-                If OGRE is not running in an automatic rendering loop
-                (started using Root::startRendering),
-                the user of the library is responsible for asking each render
-                target to refresh. This is the method used to do this. It automatically
-                re-renders the contents of the target using whatever cameras have been
-                pointed at it (using Camera::setRenderTarget).
-            @par
-                This allows OGRE to be used in multi-windowed utilities
-                and for contents to be refreshed only when required, rather than
-                constantly as with the automatic rendering loop.
-			@param swapBuffers For targets that support double-buffering, if set 
-				to true, the target will immediately
-				swap it's buffers after update. Otherwise, the buffers are
-				not swapped, and you have to call swapBuffers yourself sometime
-				later. You might want to do this on some rendersystems which 
-				pause for queued rendering commands to complete before accepting
-				swap buffers calls - so you could do other CPU tasks whilst the 
-				queued commands complete. Or, you might do this if you want custom
-				control over your windows, such as for externally created windows.
-        */
-        virtual void update(bool swapBuffers = true);
         /** Swaps the frame buffers to display the next frame.
             @remarks
                 For targets that are double-buffered so that no
@@ -121,21 +98,8 @@ namespace CamelotEngine
                 during rendering. Once rendering has completed (to
                 an off-screen version of the window) the buffers
                 are swapped to display the new frame.
-
-            @param
-                waitForVSync If true, the system waits for the
-                next vertical blank period (when the CRT beam turns off
-                as it travels from bottom-right to top-left at the
-                end of the pass) before flipping. If false, flipping
-                occurs no matter what the beam position. Waiting for
-                a vertical blank can be slower (and limits the
-                framerate to the monitor refresh rate) but results
-                in a steadier image with no 'tearing' (a flicker
-                resulting from flipping buffers when the beam is
-                in the progress of drawing the last frame).
         */
-        virtual void swapBuffers(bool waitForVSync = true)
-        { (void)waitForVSync; }
+        void swapBuffers();
 
         /** Gets a custom (maybe platform-specific) attribute.
             @remarks
@@ -181,14 +145,6 @@ namespace CamelotEngine
 
 		virtual bool requiresTextureFlipping() const = 0;
 
-        /** Indicates whether this target is the primary window. The
-            primary window is special in that it is destroyed when
-            ogre is shut down, and cannot be destroyed directly.
-            This is the case because it holds the context for vertex,
-            index buffers and textures.
-        */
-        virtual bool isPrimary(void) const;
-
 		/** Indicates whether on rendering, linear colour space is converted to 
 			sRGB gamma colour space. This is the exact opposite conversion of
 			what is indicated by Texture::isHardwareGammaEnabled, and can only
@@ -206,42 +162,21 @@ namespace CamelotEngine
 		*/
 		virtual const String& getFSAAHint() const { return mFSAAHint; }
 
-		/** Method for manual management of rendering : fires 'preRenderTargetUpdate'
-			and initialises statistics etc.
-		@remarks 
-		<ul>
-		<li>_beginUpdate resets statistics and fires 'preRenderTargetUpdate'.</li>
-		<li>_updateViewport renders the given viewport (even if it is not autoupdated),
-		fires preViewportUpdate and postViewportUpdate and manages statistics.</li>
-		<li>_updateAutoUpdatedViewports renders only viewports that are auto updated,
-		fires preViewportUpdate and postViewportUpdate and manages statistics.</li>
-		<li>_endUpdate() ends statistics calculation and fires postRenderTargetUpdate.</li>
-		</ul>
-		you can use it like this for example :
-		<pre>
-			renderTarget->_beginUpdate();
-			renderTarget->_updateViewport(1); // which is not auto updated
-			renderTarget->_updateViewport(2); // which is not auto updated
-			renderTarget->_updateAutoUpdatedViewports();
-			renderTarget->_endUpdate();
-			renderTarget->swapBuffers(true);
-		</pre>
-			Please note that in that case, the zorder may not work as you expect,
-			since you are responsible for calling _updateViewport in the correct order.
-        */
-		virtual void _beginUpdate();
-		
-		/** Method for manual management of rendering - finishes statistics calculation 
-			and fires 'postRenderTargetUpdate'.
-		@remarks
-		You should call it after a _beginUpdate
-		@see _beginUpdate for more details.
-		*/
-		virtual void _endUpdate();
+		/**
+		 * @brief	Returns true if the render target will wait for vertical sync before swapping buffers.
+		 */
+		bool getVSync() const { return mVSync; }
+
+		/**
+		 * @brief	Set whether the render target will wait for vertical sync before swapping buffers.
+		 */
+		void setVSync(bool vsync)  { mVSync = vsync; }
 
     protected:
 		RenderTarget();
 
+		virtual void swapBuffers_internal() {}
+
         /// The name of this target.
         String mName;
 		/// The priority of the render target.
@@ -254,6 +189,8 @@ namespace CamelotEngine
         bool mActive;
 		// Hardware sRGB gamma conversion done on write?
 		bool mHwGamma;
+		// Wait for vsync?
+		bool mVSync;
 		// FSAA performed?
 		UINT32 mFSAA;
 		String mFSAAHint;

+ 0 - 13
CamelotRenderer/Include/CmRenderWindow.h

@@ -139,14 +139,6 @@ namespace CamelotEngine
         */
         virtual bool isClosed(void) const = 0;
         
-        /** Indicates whether the window is the primary window. The
-        	primary window is special in that it is destroyed when 
-        	ogre is shut down, and cannot be destroyed directly.
-        	This is the case because it holds the context for vertex,
-        	index buffers and textures.
-        */
-        virtual bool isPrimary(void) const;
-
         /** Returns true if window is running in fullscreen mode.
         */
         virtual bool isFullScreen(void) const;
@@ -177,13 +169,8 @@ namespace CamelotEngine
         */
         RenderWindow(const RENDER_WINDOW_DESC& desc);
         
-        /** Indicates that this is the primary window. 
-        */
-        void _setPrimary() { mIsPrimary = true; }
-
 	protected:
 		bool mIsFullScreen;
-		bool mIsPrimary;
 		bool mAutoDeactivatedOnFocusChange;
 		int mLeft;
 		int mTop;

+ 0 - 19
CamelotRenderer/Source/CmDeferredRenderContext.cpp

@@ -10,7 +10,6 @@ namespace CamelotEngine
 {
 	DeferredRenderContext::DeferredRenderContext(RenderSystem* rs, CM_THREAD_ID_TYPE threadId)
 		:mCommandQueue(new CommandQueue(threadId))
-		, mWaitForVerticalBlank(true)
 		, mRenderSystem(rs)
 	{
 		assert(mRenderSystem != nullptr);
@@ -21,11 +20,6 @@ namespace CamelotEngine
 		delete mCommandQueue;
 	}
 
-	void DeferredRenderContext::swapAllRenderTargetBuffers(bool waitForVSync)
-	{
-		mCommandQueue->queue(boost::bind(&RenderSystem::swapAllRenderTargetBuffers, mRenderSystem, waitForVSync));
-	}
-
 	void DeferredRenderContext::setViewport(const Viewport* vp)
 	{
 		mCommandQueue->queue(boost::bind(&RenderSystem::setViewport, mRenderSystem, vp));
@@ -86,17 +80,6 @@ namespace CamelotEngine
 		mCommandQueue->queue(boost::bind(&RenderSystem::setScissorRect, mRenderSystem, left, top, right, bottom));
 	}
 
-	bool DeferredRenderContext::getWaitForVerticalBlank(void) const
-	{
-		return mWaitForVerticalBlank;
-	}
-
-	void DeferredRenderContext::setWaitForVerticalBlank(bool enabled)
-	{
-		mWaitForVerticalBlank = enabled;
-		mCommandQueue->queue(boost::bind(&RenderSystem::setWaitForVerticalBlank, mRenderSystem, enabled));
-	}
-
 	void DeferredRenderContext::addClipPlane(const Plane &p)
 	{
 		mCommandQueue->queue(boost::bind(&RenderSystem::addClipPlane, mRenderSystem, p));
@@ -179,7 +162,5 @@ namespace CamelotEngine
 	{
 		std::queue<CommandQueue::Command>* commands = mCommandQueue->flush();
 		delete commands;
-
-		// TODO - This cancels the commands but doesn't revert the state variables
 	}
 }

+ 1 - 92
CamelotRenderer/Source/CmRenderSystem.cpp

@@ -57,8 +57,6 @@ namespace CamelotEngine {
     RenderSystem::RenderSystem()
         : mActiveRenderTarget(nullptr)
         , mCullingMode(CULL_CLOCKWISE)
-		, mVsync(false)
-		, mVSyncInterval(1)
         , mInvertVertexWinding(false)
         , mDisabledTexUnitsFrom(0)
         , mVertexProgramBound(false)
@@ -113,88 +111,13 @@ namespace CamelotEngine {
 	//-----------------------------------------------------------------------
 	void RenderSystem::destroy_internal()
 	{
-		// Remove all the render targets.
-		mRenderTargets.clear();
-
-		mPrioritisedRenderTargets.clear();
 	}
-    //-----------------------------------------------------------------------
-    void RenderSystem::swapAllRenderTargetBuffers(bool waitForVSync)
-    {
-		THROW_IF_NOT_RENDER_THREAD;
-
-        // Update all in order of priority
-        // This ensures render-to-texture targets get updated before render windows
-		RenderTargetPriorityMap::iterator itarg, itargend;
-		itargend = mPrioritisedRenderTargets.end();
-		for( itarg = mPrioritisedRenderTargets.begin(); itarg != itargend; ++itarg )
-		{
-			if( itarg->second->isActive())
-				itarg->second->swapBuffers(waitForVSync);
-		}
-    }
-    //---------------------------------------------------------------------------------------------
-    void RenderSystem::destroyRenderWindow(RenderWindow* renderWindow)
-    {
-		THROW_IF_NOT_RENDER_THREAD;
-
-        destroyRenderTarget(renderWindow);
-    }
-    //---------------------------------------------------------------------------------------------
-    void RenderSystem::destroyRenderTexture(RenderTexture* renderTexture)
-    {
-		THROW_IF_NOT_RENDER_THREAD;
-
-        destroyRenderTarget(renderTexture);
-    }
     //---------------------------------------------------------------------------------------------
-    void RenderSystem::destroyRenderTarget(RenderTarget* renderTarget)
+    void RenderSystem::_notifyWindowCreated(RenderWindow& window)
     {
 		THROW_IF_NOT_RENDER_THREAD;
 
-        detachRenderTarget(*renderTarget);
-        delete renderTarget;
-    }
-    //---------------------------------------------------------------------------------------------
-    void RenderSystem::attachRenderTarget( RenderTarget &target )
-    {
-		THROW_IF_NOT_RENDER_THREAD;
-
-		assert( target.getPriority() < CM_NUM_RENDERTARGET_GROUPS );
-
-        mRenderTargets.push_back(&target);
-        mPrioritisedRenderTargets.insert(
-            RenderTargetPriorityMap::value_type(target.getPriority(), &target ));
     }
-	//---------------------------------------------------------------------------------------------
-	void RenderSystem::detachRenderTarget(RenderTarget& renderTarget)
-	{
-		THROW_IF_NOT_RENDER_THREAD;
-
-		auto it = std::find(mRenderTargets.begin(), mRenderTargets.end(), &renderTarget);
-		RenderTarget* foundRT = nullptr;
-
-		if( it != mRenderTargets.end() )
-		{
-			foundRT = *it;
-
-			/* Remove the render target from the priority groups. */
-			RenderTargetPriorityMap::iterator itarg, itargend;
-			itargend = mPrioritisedRenderTargets.end();
-			for( itarg = mPrioritisedRenderTargets.begin(); itarg != itargend; ++itarg )
-			{
-				if( itarg->second == *it ) {
-					mPrioritisedRenderTargets.erase( itarg );
-					break;
-				}
-			}
-
-			mRenderTargets.erase( it );
-		}
-		/// If detached render target is the active render target, reset active render target
-		if(foundRT == mActiveRenderTarget)
-			mActiveRenderTarget = 0;
-	}
 	//---------------------------------------------------------------------------------------------
 	const RenderSystemCapabilities* RenderSystem::getCapabilities(void) const 
 	{ 
@@ -223,20 +146,6 @@ namespace CamelotEngine {
 
         setTexture(gptype, texUnit, false, sNullTexPtr);
     }
-	//-----------------------------------------------------------------------
-	bool RenderSystem::getWaitForVerticalBlank(void) const
-	{
-		THROW_IF_NOT_RENDER_THREAD;
-
-		return mVsync;
-	}
-	//-----------------------------------------------------------------------
-	void RenderSystem::setWaitForVerticalBlank(bool enabled)
-	{
-		THROW_IF_NOT_RENDER_THREAD;
-
-		mVsync = enabled;
-	}
 	//---------------------------------------------------------------------
 	void RenderSystem::addClipPlane (const Plane &p)
 	{

+ 7 - 27
CamelotRenderer/Source/CmRenderTarget.cpp

@@ -37,6 +37,7 @@ namespace CamelotEngine {
 		:mPriority(CM_DEFAULT_RT_GROUP),
 		mActive(true),
 		mHwGamma(false), 
+		mVSync(false),
 		mFSAA(0)
     {
     }
@@ -70,44 +71,23 @@ namespace CamelotEngine {
         return mColorDepth;
     }
 
-
-	void RenderTarget::_beginUpdate()
-	{
-	}
-
-	void RenderTarget::_endUpdate()
-	{
-	}
-
 	void RenderTarget::getCustomAttribute(const String& name, void* pData)
     {
         CM_EXCEPT(InvalidParametersException, "Attribute not found.");
     }
-    //-----------------------------------------------------------------------
+
     bool RenderTarget::isActive() const
     {
         return mActive;
     }
-    //-----------------------------------------------------------------------
+
     void RenderTarget::setActive( bool state )
     {
         mActive = state;
     }
-    //-----------------------------------------------------------------------
-    bool RenderTarget::isPrimary(void) const
-    {
-        // RenderWindow will override and return true for the primary window
-        return false;
-    }
-    //-----------------------------------------------------------------------
-    void RenderTarget::update(bool swap)
-    {
-		if (swap)
-		{
-			// Swap buffers
-    	    swapBuffers(CamelotEngine::RenderSystem::instancePtr()->getWaitForVerticalBlank());
-		}
-    }
-	
 
+	void RenderTarget::swapBuffers()
+	{
+		queueGpuCommand(getThisPtr(), boost::bind(&RenderTarget::swapBuffers_internal, this));
+	}
 }        

+ 0 - 6
CamelotRenderer/Source/CmRenderWindow.cpp

@@ -33,7 +33,6 @@ namespace CamelotEngine
 {
     RenderWindow::RenderWindow(const RENDER_WINDOW_DESC& desc)
         : RenderTarget()
-		, mIsPrimary(false)
 		, mIsFullScreen(false)
 		, mDesc(desc)
     {
@@ -60,11 +59,6 @@ namespace CamelotEngine
     {
         return mIsFullScreen;
     }
-	//-----------------------------------------------------------------------
-    bool RenderWindow::isPrimary(void) const
-    {
-        return mIsPrimary;
-    }
 
     bool RenderWindow::isDeactivatedOnFocusChange() const
     {

+ 2 - 3
CamelotRenderer/TODO.txt

@@ -21,9 +21,6 @@ Add support for include file resource
 Make sure we can add an include file to a HighLevelGpuProgram, and make sure it uses it
  - Also a way to list all referenced includes, and a way to remove them
 
- Refactor how we handle RenderTargets (no attach/detach, and no waitForVSync propery in RenderSystem)
- waitForVsync can probably be moved somewhere other than being directly in RenderSystem? (where is it in DX11?)
-
 Go through RenderSystem classes and make sure we don't hold any raw pointer references.
 Seems there is a possible deadlock when starting the render thread, while waiting for the thread to be started
 Get rid of resource handlers in Resources?
@@ -42,6 +39,8 @@ Can be delayed:
  - BE CAREFUL on how this will be implemented. Likely it will have much of the same interface as a material and/or GpuParams
  Mesh::setMeshData is currently always synced
   register/unregisterObjectToDestroy might be redundant now that I save a reference with each queue entry?
+ queueGpuCommand is handled weird. shared_ptr isn't used for setting (this) parameter, and could be optimized out by the compiler
+  - test if everything is okay in release mode
 >>>>>>>>>>>>>>>START WORKING ON THE EDITOR!