Browse Source

Ported swapBuffers so it now happens on the proper context

Marko Pintera 12 years ago
parent
commit
aeacd7b646

+ 1 - 1
BansheeForwardRenderer/Source/BsForwardRenderer.cpp

@@ -46,7 +46,7 @@ namespace BansheeEngine
 				RenderTargetPtr rt = vp->getTarget();
 				RenderTargetPtr rt = vp->getTarget();
 
 
 				if(rt != nullptr)
 				if(rt != nullptr)
-					rt->swapBuffers(); // TODO - This is wrong as potentially multiple viewports can share a single render target, and swap shouldn't
+					renderContext->swapBuffers(rt); // 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
 				// be done for every one of them
 			}
 			}
 		}
 		}

+ 3 - 0
CamelotCore/Include/CmDeferredRenderContext.h

@@ -95,6 +95,9 @@ namespace CamelotFramework
 		/** @copydoc RenderSystem::clear() */
 		/** @copydoc RenderSystem::clear() */
 		void clear(RenderTargetPtr target, unsigned int buffers, const Color& color = Color::Black, float depth = 1.0f, unsigned short stencil = 0);
 		void clear(RenderTargetPtr target, unsigned int buffers, const Color& color = Color::Black, float depth = 1.0f, unsigned short stencil = 0);
 
 
+		/** @copydoc RenderSystem::swapBuffers() */
+		void swapBuffers(RenderTargetPtr target);
+
 		/**
 		/**
 		 * @brief	Makes all the currently queued commands available to the GPU. They will be executed
 		 * @brief	Makes all the currently queued commands available to the GPU. They will be executed
 		 * 			as soon as the render thread is ready.
 		 * 			as soon as the render thread is ready.

+ 5 - 0
CamelotCore/Include/CmRenderSystem.h

@@ -206,6 +206,11 @@ namespace CamelotFramework
 		 */
 		 */
 		virtual void drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexCount) = 0;
 		virtual void drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexCount) = 0;
 
 
+		/**
+		 * @brief	Swap the front and back buffer of the specified render target.
+		 */
+		virtual void swapBuffers(RenderTargetPtr target);
+
 		/** Gets the capabilities of the render system. */
 		/** Gets the capabilities of the render system. */
 		const RenderSystemCapabilities* getCapabilities(void) const;
 		const RenderSystemCapabilities* getCapabilities(void) const;
 
 

+ 6 - 11
CamelotCore/Include/CmRenderTarget.h

@@ -91,15 +91,12 @@ namespace CamelotFramework
         virtual unsigned int getHeight(void) const;
         virtual unsigned int getHeight(void) const;
         virtual unsigned int getColourDepth(void) const;
         virtual unsigned int getColourDepth(void) const;
 
 
-        /** Swaps the frame buffers to display the next frame.
-            @remarks
-                For targets that are double-buffered so that no
-                'in-progress' versions of the scene are displayed
-                during rendering. Once rendering has completed (to
-                an off-screen version of the window) the buffers
-                are swapped to display the new frame.
-        */
-        void swapBuffers();
+        /**
+         * @brief	Swaps the frame buffers to display the next frame.
+         * 			
+		 * @note	Render thread only.
+         */
+		virtual void swapBuffers() {};
 
 
 		/**
 		/**
 		 * @brief	Returns true if the render target is a render window.
 		 * @brief	Returns true if the render target is a render window.
@@ -180,8 +177,6 @@ namespace CamelotFramework
     protected:
     protected:
 		RenderTarget();
 		RenderTarget();
 
 
-		virtual void swapBuffers_internal() {}
-
         /// The name of this target.
         /// The name of this target.
         String mName;
         String mName;
 		/// The priority of the render target.
 		/// The priority of the render target.

+ 5 - 0
CamelotCore/Source/CmDeferredRenderContext.cpp

@@ -135,6 +135,11 @@ namespace CamelotFramework
 		mCommandQueue->queue(boost::bind(&RenderSystem::endFrame, mRenderSystem));
 		mCommandQueue->queue(boost::bind(&RenderSystem::endFrame, mRenderSystem));
 	}
 	}
 
 
+	void DeferredRenderContext::swapBuffers(RenderTargetPtr target)
+	{
+		mCommandQueue->queue(boost::bind(&RenderSystem::swapBuffers, mRenderSystem, target));
+	}
+
 	void DeferredRenderContext::render(const RenderOperation& op)
 	void DeferredRenderContext::render(const RenderOperation& op)
 	{
 	{
 		mCommandQueue->queue(boost::bind(&RenderSystem::render, mRenderSystem, op));
 		mCommandQueue->queue(boost::bind(&RenderSystem::render, mRenderSystem, op));

+ 5 - 0
CamelotCore/Source/CmRenderSystem.cpp

@@ -265,6 +265,11 @@ namespace CamelotFramework {
 		else
 		else
 			draw(op.vertexData->vertexCount);
 			draw(op.vertexData->vertexCount);
 	}
 	}
+	//-----------------------------------------------------------------------
+	void RenderSystem::swapBuffers(RenderTargetPtr target)
+	{
+		target->swapBuffers();
+	}
 
 
 	/************************************************************************/
 	/************************************************************************/
 	/* 								PRIVATE		                     		*/
 	/* 								PRIVATE		                     		*/

+ 0 - 5
CamelotCore/Source/CmRenderTarget.cpp

@@ -85,9 +85,4 @@ namespace CamelotFramework {
     {
     {
         mActive = state;
         mActive = state;
     }
     }
-
-	void RenderTarget::swapBuffers()
-	{
-		queueGpuCommand(getThisPtr(), boost::bind(&RenderTarget::swapBuffers_internal, this));
-	}
 }        
 }        

+ 1 - 2
CamelotD3D11RenderSystem/Include/CmD3D11RenderWindow.h

@@ -18,6 +18,7 @@ namespace CamelotFramework
 		void setFullscreen(bool fullScreen, unsigned int width, unsigned int height);
 		void setFullscreen(bool fullScreen, unsigned int width, unsigned int height);
 
 
 		void copyContentsToMemory(const PixelData &dst, FrameBuffer buffer);
 		void copyContentsToMemory(const PixelData &dst, FrameBuffer buffer);
+		void swapBuffers();
 
 
 		void windowMovedOrResized();
 		void windowMovedOrResized();
 
 
@@ -39,8 +40,6 @@ namespace CamelotFramework
 
 
 		IDXGIDevice* _queryDxgiDevice(); 
 		IDXGIDevice* _queryDxgiDevice(); 
 
 
-		void swapBuffers_internal();
-	
 		bool _checkMultiSampleQuality(UINT SampleCount, UINT *outQuality, DXGI_FORMAT format);
 		bool _checkMultiSampleQuality(UINT SampleCount, UINT *outQuality, DXGI_FORMAT format);
 
 
 		void _createSwapChain();
 		void _createSwapChain();

+ 1 - 1
CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp

@@ -289,7 +289,7 @@ namespace CamelotFramework
 		RenderWindow::destroy_internal();
 		RenderWindow::destroy_internal();
 	}
 	}
 
 
-	void D3D11RenderWindow::swapBuffers_internal()
+	void D3D11RenderWindow::swapBuffers()
 	{
 	{
 		if(mDevice.getD3D11Device() != nullptr)
 		if(mDevice.getD3D11Device() != nullptr)
 		{
 		{

+ 2 - 2
CamelotD3D9Renderer/Include/CmD3D9RenderWindow.h

@@ -58,6 +58,8 @@ namespace CamelotFramework
 		void				copyContentsToMemory	(const PixelData &dst, FrameBuffer buffer);
 		void				copyContentsToMemory	(const PixelData &dst, FrameBuffer buffer);
 		bool				requiresTextureFlipping	() const { return false; }
 		bool				requiresTextureFlipping	() const { return false; }
 
 
+		void				swapBuffers();
+
 		// Method for dealing with resize / move & 3d library
 		// Method for dealing with resize / move & 3d library
 		void				windowMovedOrResized	();
 		void				windowMovedOrResized	();
 	
 	
@@ -92,8 +94,6 @@ namespace CamelotFramework
 
 
 		void updateWindowRect();
 		void updateWindowRect();
 
 
-		void swapBuffers_internal();
-
 		/**
 		/**
 		 * @copydoc RenderWindow::initialize_internal().
 		 * @copydoc RenderWindow::initialize_internal().
 		 */
 		 */

+ 1 - 1
CamelotD3D9Renderer/Source/CmD3D9RenderWindow.cpp

@@ -608,7 +608,7 @@ namespace CamelotFramework
 		updateWindowRect();
 		updateWindowRect();
 	}
 	}
 
 
-	void D3D9RenderWindow::swapBuffers_internal()
+	void D3D9RenderWindow::swapBuffers()
 	{
 	{
 		if (mDeviceValid)
 		if (mDeviceValid)
 			mDevice->present(this);		
 			mDevice->present(this);		

+ 2 - 2
CamelotGLRenderer/Include/CmWin32Window.h

@@ -48,6 +48,8 @@ namespace CamelotFramework {
 		/** Overridden - see RenderTarget. */
 		/** Overridden - see RenderTarget. */
 		virtual void copyContentsToMemory(const PixelData &dst, FrameBuffer buffer);
 		virtual void copyContentsToMemory(const PixelData &dst, FrameBuffer buffer);
 
 
+		void swapBuffers();
+
 		bool requiresTextureFlipping() const { return false; }
 		bool requiresTextureFlipping() const { return false; }
 
 
 		HWND getWindowHandle() const { return mHWnd; }
 		HWND getWindowHandle() const { return mHWnd; }
@@ -84,8 +86,6 @@ namespace CamelotFramework {
         int     mDisplayFrequency;      // fullscreen only, to restore display
         int     mDisplayFrequency;      // fullscreen only, to restore display
         Win32Context *mContext;
         Win32Context *mContext;
 
 
-		void swapBuffers_internal();
-
 		/**
 		/**
 		 * @copydoc RenderWindow::initialize_internal().
 		 * @copydoc RenderWindow::initialize_internal().
 		 */
 		 */

+ 1 - 1
CamelotGLRenderer/Source/CmWin32Window.cpp

@@ -637,7 +637,7 @@ namespace CamelotFramework {
 		// TODO - Notify viewports of resize
 		// TODO - Notify viewports of resize
 	}
 	}
 
 
-	void Win32Window::swapBuffers_internal()
+	void Win32Window::swapBuffers()
 	{
 	{
 	  if (!mIsExternalGLControl) {
 	  if (!mIsExternalGLControl) {
 	  	SwapBuffers(mHDC);
 	  	SwapBuffers(mHDC);

+ 2 - 2
TODODoc.txt

@@ -3,8 +3,8 @@
     - For example HighLevelGpuProgram is thread safe but GpuProgram itself isn't
     - For example HighLevelGpuProgram is thread safe but GpuProgram itself isn't
     - Classes that are safe to use outside of the render thread: RenderSystem, Mesh, Texture, HighLevelGpuProgram, Material, Shader, Technique
     - Classes that are safe to use outside of the render thread: RenderSystem, Mesh, Texture, HighLevelGpuProgram, Material, Shader, Technique
 	- Classes that are only accessible from the render thread: GpuProgram, HardwarePixelBuffer, HardwareVertexBuffer, HardwareIndexBuffer
 	- Classes that are only accessible from the render thread: GpuProgram, HardwarePixelBuffer, HardwareVertexBuffer, HardwareIndexBuffer
-  - 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.
+   - Add documentation notes to specific methods of classes that may be used both in and out of render thread
+     - RenderTarget & RenderWindow for example. Methods like getWidth/getHeight can be made thread safe, while swapBuffers() cannot
   - GLSL limitations
   - GLSL limitations
      - layout(row_major) is not supported and will likely result in incorrect matrices
      - layout(row_major) is not supported and will likely result in incorrect matrices
 	 - Because GLSL introspection API is built around basic types I don't support structs or arrays of objects: 
 	 - Because GLSL introspection API is built around basic types I don't support structs or arrays of objects: