Kaynağa Gözat

D3D9 multisample enable and antialiased line support

Marko Pintera 13 yıl önce
ebeveyn
işleme
5f312797a4

+ 14 - 0
CamelotD3D9Renderer/Include/CmD3D9RenderSystem.h

@@ -426,6 +426,20 @@ namespace CamelotEngine
 		*/
 		*/
 		void setScissorTestEnable(bool enable);
 		void setScissorTestEnable(bool enable);
 
 
+		/**
+		 * @brief	Only applies when rendering to a multisample render target.
+		 * 			If disabled all of the samples will be taken from the center of the pixel,
+		 * 			effectively making the image aliased. Default value is true where samples are
+		 * 			picked randomly within the pixel.
+		 */
+		void setMultisampleAntialiasEnable(bool enable);
+
+		/**
+		 * @brief	Only applies when rendering to a non-multisample render target.
+		 * 			If enabled, lines will be antialiased. Default state is disabled.
+		 */
+		void setAntialiasedLineEnable(bool enable);
+
 		/************************************************************************/
 		/************************************************************************/
 		/* 						Depth stencil state                      		*/
 		/* 						Depth stencil state                      		*/
 		/************************************************************************/
 		/************************************************************************/

+ 42 - 0
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -616,6 +616,10 @@ namespace CamelotEngine
 		setPolygonMode(rasterizerState.getPolygonMode());
 		setPolygonMode(rasterizerState.getPolygonMode());
 
 
 		setScissorTestEnable(rasterizerState.getScissorEnable());
 		setScissorTestEnable(rasterizerState.getScissorEnable());
+
+		setMultisampleAntialiasEnable(rasterizerState.getMultisampleEnable());
+
+		setAntialiasedLineEnable(rasterizerState.getAntialiasedLineEnable());
 	}
 	}
 	//----------------------------------------------------------------------
 	//----------------------------------------------------------------------
 	void D3D9RenderSystem::setDepthStencilState(const DepthStencilState& depthStencilState)
 	void D3D9RenderSystem::setDepthStencilState(const DepthStencilState& depthStencilState)
@@ -1389,6 +1393,44 @@ namespace CamelotEngine
 			}
 			}
 		}
 		}
 	}
 	}
+	//--------------------------------------------------------------------
+	void D3D9RenderSystem::setMultisampleAntialiasEnable(bool enable)
+	{
+		HRESULT hr;
+		if(enable)
+		{
+			if (FAILED(hr = __SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE)))
+			{
+				CM_EXCEPT(RenderingAPIException, "Unable to enable multisample antialiasing. Error description: " + getErrorDescription(hr));
+			}
+		}
+		else
+		{
+			if (FAILED(hr = __SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, FALSE)))
+			{
+				CM_EXCEPT(RenderingAPIException, "Unable to disable multisample antialiasing. Error description: " + getErrorDescription(hr));
+			}
+		}
+	}
+	//---------------------------------------------------------------------
+	void D3D9RenderSystem::setAntialiasedLineEnable(bool enable)
+	{
+		HRESULT hr;
+		if(enable)
+		{
+			if (FAILED(hr = __SetRenderState(D3DRS_ANTIALIASEDLINEENABLE, TRUE)))
+			{
+				CM_EXCEPT(RenderingAPIException, "Unable to enable line antialiasing. Error description: " + getErrorDescription(hr));
+			}
+		}
+		else
+		{
+			if (FAILED(hr = __SetRenderState(D3DRS_ANTIALIASEDLINEENABLE, FALSE)))
+			{
+				CM_EXCEPT(RenderingAPIException, "Unable to disable line antialiasing. Error description: " + getErrorDescription(hr));
+			}
+		}
+	}
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::clearFrameBuffer(unsigned int buffers, 
 	void D3D9RenderSystem::clearFrameBuffer(unsigned int buffers, 
 		const Color& colour, float depth, unsigned short stencil)
 		const Color& colour, float depth, unsigned short stencil)

+ 1 - 1
CamelotRenderer/Include/CmRasterizerState.h

@@ -16,7 +16,7 @@ namespace CamelotEngine
 			, slopeScaledDepthBias(0.0f)
 			, slopeScaledDepthBias(0.0f)
 			, depthClipEnable(true)
 			, depthClipEnable(true)
 			, scissorEnable(false)
 			, scissorEnable(false)
-			, multisampleEnable(false)
+			, multisampleEnable(true)
 			, antialiasedLineEnable(false)
 			, antialiasedLineEnable(false)
 		{ }
 		{ }
 
 

+ 0 - 6
CamelotRenderer/TODO.txt

@@ -28,12 +28,6 @@ Make RenderSystem a module? (Initialize it using startUp, and get rid of directl
 
 
 Keeping a list of all render targets in RenderSystem shouldn't be needed (and calling attach/detach renderTarget). Renderer should determine in what order are render targets presented.
 Keeping a list of all render targets in RenderSystem shouldn't be needed (and calling attach/detach renderTarget). Renderer should determine in what order are render targets presented.
 
 
-Rasterizer state:
- D3DRS_MULTISAMPLEANTIALIAS
- - but first check if available using D3DPRASTERCAPS_MULTISAMPLE_TOGGLE
- - see if opengl has something similar
- - see if either dx9 or opengl have something similar to DX11 antialias line
-
 Make CommandQueue not use mutexes and use atomics instead??
 Make CommandQueue not use mutexes and use atomics instead??
 Make sure that the simulation can't run faster then the render thread! (Block the main thread until previous render finishes)
 Make sure that the simulation can't run faster then the render thread! (Block the main thread until previous render finishes)
 /////
 /////