Browse Source

Sub-render target clear works on DX9 and GL

Marko Pintera 12 years ago
parent
commit
7d2fed1ebb

+ 2 - 2
CamelotClient/CamelotClient.cpp

@@ -37,8 +37,8 @@
 #include "CmCursor.h"
 #include "CmCursor.h"
 
 
 //#define DX11
 //#define DX11
-//#define DX9
-#define GL
+#define DX9
+//#define GL
 
 
 using namespace CamelotFramework;
 using namespace CamelotFramework;
 using namespace BansheeEditor;
 using namespace BansheeEditor;

+ 24 - 11
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -1368,7 +1368,7 @@ namespace CamelotFramework
 	}
 	}
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::clear(RenderTargetPtr target, UINT32 buffers, 
 	void D3D9RenderSystem::clear(RenderTargetPtr target, UINT32 buffers, 
-		const Color& colour, float depth, UINT16 stencil, const Rect& clearArea)
+		const Color& color, float depth, UINT16 stencil, const Rect& clearArea)
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
@@ -1395,17 +1395,30 @@ namespace CamelotFramework
 			flags |= D3DCLEAR_STENCIL;
 			flags |= D3DCLEAR_STENCIL;
 		}
 		}
 
 
-		HRESULT hr;
-		if( FAILED( hr = getActiveD3D9Device()->Clear( 
-			0, 
-			NULL, 
-			flags,
-			colour.getAsBGRA(), 
-			depth, 
-			stencil ) ) )
+		if(clearArea.width > 0 && clearArea.height > 0)
 		{
 		{
-			String msg = DXGetErrorDescription(hr);
-			CM_EXCEPT(RenderingAPIException, "Error clearing frame buffer : " + msg);
+			D3DRECT clearD3DRect;
+			clearD3DRect.x1 = clearArea.x;
+			clearD3DRect.x2 = clearD3DRect.x1 + clearArea.width;
+
+			clearD3DRect.y1 = clearArea.y;
+			clearD3DRect.y2 = clearD3DRect.y1 + clearArea.height;
+
+			HRESULT hr;
+			if(FAILED( hr = getActiveD3D9Device()->Clear(1, &clearD3DRect, flags, color.getAsBGRA(), depth, stencil)))
+			{
+				String msg = DXGetErrorDescription(hr);
+				CM_EXCEPT(RenderingAPIException, "Error clearing frame buffer : " + msg);
+			}
+		}
+		else
+		{
+			HRESULT hr;
+			if(FAILED( hr = getActiveD3D9Device()->Clear(0, nullptr, flags, color.getAsBGRA(), depth, stencil)))
+			{
+				String msg = DXGetErrorDescription(hr);
+				CM_EXCEPT(RenderingAPIException, "Error clearing frame buffer : " + msg);
+			}
 		}
 		}
 
 
 		if(previousRenderTarget != nullptr && target != previousRenderTarget)
 		if(previousRenderTarget != nullptr && target != previousRenderTarget)

+ 21 - 0
CamelotGLRenderer/Source/CmGLRenderSystem.cpp

@@ -774,18 +774,39 @@ namespace CamelotFramework
 
 
 		// Disable scissor test as we want to clear the entire render surface
 		// Disable scissor test as we want to clear the entire render surface
 		GLboolean scissorTestEnabled = glIsEnabled(GL_SCISSOR_TEST);
 		GLboolean scissorTestEnabled = glIsEnabled(GL_SCISSOR_TEST);
+		UINT32 oldScissorTop = mScissorTop;
+		UINT32 oldScissorBottom = mScissorBottom;
+		UINT32 oldScissorLeft = mScissorLeft;
+		UINT32 oldScissorRight = mScissorRight;
+
 		if (scissorTestEnabled)
 		if (scissorTestEnabled)
 		{
 		{
 			glDisable(GL_SCISSOR_TEST);
 			glDisable(GL_SCISSOR_TEST);
 		}
 		}
 
 
+		if(clearArea.width > 0 && clearArea.height > 0)
+		{
+			setScissorRect(clearArea.x, clearArea.y, clearArea.width, clearArea.height);
+			setScissorTestEnable(true);			
+		}
+
 		// Clear buffers
 		// Clear buffers
 		glClear(flags);
 		glClear(flags);
 
 
+		if(clearArea.width > 0 && clearArea.height > 0)
+		{
+			setScissorTestEnable(false);	
+		}
+
 		// Restore scissor test
 		// Restore scissor test
 		if (scissorTestEnabled)
 		if (scissorTestEnabled)
 		{
 		{
 			glEnable(GL_SCISSOR_TEST);
 			glEnable(GL_SCISSOR_TEST);
+
+			mScissorTop = oldScissorTop;
+			mScissorBottom = oldScissorBottom;
+			mScissorLeft = oldScissorLeft;
+			mScissorRight = oldScissorRight;
 		}
 		}
 
 
 		// Reset buffer write state
 		// Reset buffer write state