Browse Source

A bunch of small changes before I start editing RenderTexture

Marko Pintera 13 years ago
parent
commit
854364a16f

+ 1 - 1
CamelotD3D11RenderSystem/Include/CmD3D11RenderSystem.h

@@ -10,7 +10,7 @@ namespace CamelotEngine
 	public:
 		static D3D11Device& getPrimaryDevice();
 
-		void determineFSAASettings(UINT32 fsaa, const String& fsaaHint, DXGI_FORMAT format, DXGI_SAMPLE_DESC* outFSAASettings);
+		void determineFSAASettings(UINT32 fsaa, const String& fsaaHint, DXGI_FORMAT format, DXGI_SAMPLE_DESC* outFSAASettings);
 		bool checkTextureFilteringSupported(TextureType ttype, PixelFormat format, int usage);
 
 		virtual const String& getName() const;

+ 1 - 0
CamelotD3D11RenderSystem/Include/CmD3D11RenderWindow.h

@@ -70,6 +70,7 @@ namespace CamelotEngine
 		ID3D11Texture2D*			mBackBuffer;
 		ID3D11RenderTargetView*		mRenderTargetView;
 		ID3D11DepthStencilView*		mDepthStencilView;
+		DepthStencilBufferPtr		mDepthStencilBuffer;
 
 		IDXGISwapChain*				mSwapChain;
 		DXGI_SWAP_CHAIN_DESC		mSwapChainDesc;

+ 47 - 47
CamelotD3D11RenderSystem/Source/CmD3D11DepthStencilBuffer.cpp

@@ -10,55 +10,55 @@ namespace CamelotEngine
 		, mDepthStencil(nullptr)
 		, mDepthStencilView(nullptr)
 	{
-		// Create depth stencil texture
-		D3D11_TEXTURE2D_DESC descDepth;
-
-		descDepth.Width = width;
-		descDepth.Height = height;
-		descDepth.MipLevels = 1;
-		descDepth.ArraySize = 1;
-		descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
-		descDepth.Usage = D3D11_USAGE_DEFAULT;
-		descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
-		descDepth.CPUAccessFlags = 0;
-		descDepth.MiscFlags = 0;
-
+		// Create depth stencil texture
+		D3D11_TEXTURE2D_DESC descDepth;
+
+		descDepth.Width = width;
+		descDepth.Height = height;
+		descDepth.MipLevels = 1;
+		descDepth.ArraySize = 1;
+		descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
+		descDepth.Usage = D3D11_USAGE_DEFAULT;
+		descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
+		descDepth.CPUAccessFlags = 0;
+		descDepth.MiscFlags = 0;
+
 		D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
-		rs->determineFSAASettings(fsaa, fsaaHint, DXGI_FORMAT_D24_UNORM_S8_UINT, &descDepth.SampleDesc);
-
-		D3D11Device& device = D3D11RenderSystem::getPrimaryDevice();
-		HRESULT hr = device.getD3D11Device()->CreateTexture2D(&descDepth, NULL, &mDepthStencil);
-		if( FAILED(hr) || device.hasError())
-		{
-			String errorDescription = device.getErrorDescription(hr);
-			CM_EXCEPT(RenderingAPIException, "Unable to create depth texture\nError Description:" + errorDescription);
-		}
-
-		// Create the depth stencil view
-		D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;
-		ZeroMemory(&descDSV, sizeof(D3D11_DEPTH_STENCIL_VIEW_DESC));
-
-		descDSV.Format =  descDepth.Format;
-		descDSV.ViewDimension = (fsaa != 0) ? D3D11_DSV_DIMENSION_TEXTURE2DMS : D3D11_DSV_DIMENSION_TEXTURE2D;
-		descDSV.Texture2D.MipSlice = 0;
-		hr = device.getD3D11Device()->CreateDepthStencilView(mDepthStencil, &descDSV, &mDepthStencilView);
-
-		if(FAILED(hr))
-		{
-			String errorDescription = device.getErrorDescription();
-			CM_EXCEPT(RenderingAPIException, "Unable to create depth stencil view\nError Description:" + errorDescription);
+		rs->determineFSAASettings(fsaa, fsaaHint, DXGI_FORMAT_D24_UNORM_S8_UINT, &descDepth.SampleDesc);
+
+		D3D11Device& device = D3D11RenderSystem::getPrimaryDevice();
+		HRESULT hr = device.getD3D11Device()->CreateTexture2D(&descDepth, NULL, &mDepthStencil);
+		if( FAILED(hr) || device.hasError())
+		{
+			String errorDescription = device.getErrorDescription();
+			CM_EXCEPT(RenderingAPIException, "Unable to create depth texture\nError Description:" + errorDescription);
+		}
+
+		// Create the depth stencil view
+		D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;
+		ZeroMemory(&descDSV, sizeof(D3D11_DEPTH_STENCIL_VIEW_DESC));
+
+		descDSV.Format =  descDepth.Format;
+		descDSV.ViewDimension = (fsaa != 0) ? D3D11_DSV_DIMENSION_TEXTURE2DMS : D3D11_DSV_DIMENSION_TEXTURE2D;
+		descDSV.Texture2D.MipSlice = 0;
+		hr = device.getD3D11Device()->CreateDepthStencilView(mDepthStencil, &descDSV, &mDepthStencilView);
+
+		if(FAILED(hr))
+		{
+			String errorDescription = device.getErrorDescription();
+			CM_EXCEPT(RenderingAPIException, "Unable to create depth stencil view\nError Description:" + errorDescription);
 		}
 	}
-
-	D3D11DepthStencilBuffer::~D3D11DepthStencilBuffer()
-	{
-		SAFE_RELEASE(mDepthStencilView);
-		SAFE_RELEASE(mDepthStencil);
-	}
-
-	bool D3D11DepthStencilBuffer::isCompatible(RenderTarget* renderTarget) const
-	{
-		// Implement once I have RenderTarget properly implemented
-		CM_EXCEPT(NotImplementedException, "Not implemented");
+
+	D3D11DepthStencilBuffer::~D3D11DepthStencilBuffer()
+	{
+		SAFE_RELEASE(mDepthStencilView);
+		SAFE_RELEASE(mDepthStencil);
+	}
+
+	bool D3D11DepthStencilBuffer::isCompatible(RenderTarget* renderTarget) const
+	{
+		// Implement once I have RenderTarget properly implemented
+		CM_EXCEPT(NotImplementedException, "Not implemented");
 	}
 }

+ 1 - 4
CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp

@@ -19,7 +19,6 @@ namespace CamelotEngine
 		, mSwitchingFullscreen(false)
 		, mDisplayFrequency(0)
 		, mRenderTargetView(nullptr)
-		, mDepthStencilView(nullptr)
 		, mBackBuffer(nullptr)
 		, mSwapChain(nullptr)
 		, mHWnd(0)
@@ -593,7 +592,7 @@ namespace CamelotEngine
 			CM_EXCEPT(RenderingAPIException, "Unable to Get Back Buffer for swap chain");
 
 		// create all other size depended resources
-		assert(mBackBuffer && !mRenderTargetView && !mDepthStencilView);
+		assert(mBackBuffer && !mRenderTargetView);
 
 		// get the backbuffer desc
 		D3D11_TEXTURE2D_DESC BBDesc;
@@ -623,8 +622,6 @@ namespace CamelotEngine
 		SAFE_RELEASE(mRenderTargetView);
 
 		mDepthStencilBuffer = nullptr;
-
-		SAFE_RELEASE(mDepthStencilView);
 	}
 
 	void D3D11RenderWindow::_resizeSwapChainBuffers(unsigned width, unsigned height)

+ 0 - 3
CamelotD3D9Renderer/Include/CmD3D9Device.h

@@ -71,8 +71,6 @@ namespace CamelotEngine {
 		IDirect3DSurface9*		getDepthBuffer			(D3D9RenderWindow* renderWindow);
 		IDirect3DSurface9*		getBackBuffer			(D3D9RenderWindow* renderWindow);
 
-		UINT32					getRenderWindowCount	() const;
-		D3D9RenderWindow*		getRenderWindow			(UINT32 index);
 		UINT32					getLastPresentFrame		() const { return mLastPresentFrame; }
 
 		void					setAdapterOrdinalIndex  (D3D9RenderWindow* renderWindow, UINT32 adapterOrdinalInGroupIndex);
@@ -133,7 +131,6 @@ namespace CamelotEngine {
 		void					releaseD3D9Device				();
 		void					releaseRenderWindowResources	(RenderWindowResources* renderWindowResources);
 		void					acquireRenderWindowResources	(RenderWindowToResorucesIterator it);		
-		void					setupDeviceStates				();
 		void					notifyDeviceLost				();
 
 		void					validateFocusWindow				();

+ 0 - 48
CamelotD3D9Renderer/Source/CmD3D9Device.cpp

@@ -260,36 +260,6 @@ namespace CamelotEngine
 	
 		return it->second->backBuffer;		
 	}
-
-	//---------------------------------------------------------------------
-	UINT32 D3D9Device::getRenderWindowCount() const
-	{
-		return static_cast<UINT32>(mMapRenderWindowToResoruces.size());
-	}
-
-	//---------------------------------------------------------------------
-	D3D9RenderWindow* D3D9Device::getRenderWindow(UINT32 index)
-	{
-		if (index >= mMapRenderWindowToResoruces.size())
-		{
-			CM_EXCEPT(RenderingAPIException, 
-				"Index of render window is out of bounds!");
-		}
-		
-		RenderWindowToResorucesIterator it = mMapRenderWindowToResoruces.begin();
-
-		while (it != mMapRenderWindowToResoruces.end())
-		{
-			if (index == 0)			
-				break;			
-			
-			--index;
-			++it;
-		}
-		
-		return it->first;
-	}
-
 	//---------------------------------------------------------------------
 	void D3D9Device::setAdapterOrdinalIndex(D3D9RenderWindow* renderWindow, UINT32 adapterOrdinalInGroupIndex)
 	{
@@ -409,9 +379,6 @@ namespace CamelotEngine
 
 		mDeviceLost = false;
 
-		// Initialize device states.
-		setupDeviceStates();
-
 		// Update resources of each window.
 		it = mMapRenderWindowToResoruces.begin();
 
@@ -701,9 +668,6 @@ namespace CamelotEngine
 		}
 
 		mD3D9DeviceCapsValid = true;
-			
-		// Initialize device states.
-		setupDeviceStates();
 
 		// Lock access to rendering device.
 		D3D9RenderSystem::getResourceManager()->lockDeviceAccess();
@@ -1061,18 +1025,6 @@ namespace CamelotEngine
 
 		renderWindowResources->acquired = true; 
 	}
-
-	//---------------------------------------------------------------------
-	void D3D9Device::setupDeviceStates()
-	{
-		HRESULT hr = mpDevice->SetRenderState(D3DRS_SPECULARENABLE, TRUE);
-		
-		if (FAILED(hr)) 
-		{
-			CM_EXCEPT(RenderingAPIException, "Unable to apply render state: D3DRS_SPECULARENABLE <- TRUE");
-		}		
-	}
-
 	//---------------------------------------------------------------------
 	bool D3D9Device::isSwapChainWindow(D3D9RenderWindow* renderWindow)
 	{

+ 2 - 24
CamelotRenderer/Include/CmRenderTarget.h

@@ -37,8 +37,8 @@ THE SOFTWARE.
 /* Define the number of priority groups for the render system's render targets. */
 #ifndef CM_NUM_RENDERTARGET_GROUPS
 	#define CM_NUM_RENDERTARGET_GROUPS 10
-	#define OGRE_DEFAULT_RT_GROUP 4
-	#define OGRE_REND_TO_TEX_RT_GROUP 2
+	#define CM_DEFAULT_RT_GROUP 4
+	#define CM_REND_TO_TEX_RT_GROUP 2
 #endif
 
 namespace CamelotEngine {
@@ -198,26 +198,6 @@ namespace CamelotEngine {
 		*/
 		virtual const String& getFSAAHint() const { return mFSAAHint; }
 
-		/**
-		 * @brief	Gets the depth stencil buffer attached to this render target.
-		 */
-		virtual DepthStencilBufferPtr getDepthStencilBuffer() const { return mDepthStencilBuffer; }
-
-        /** RenderSystem specific interface for a RenderTarget;
-            this should be subclassed by RenderSystems.
-        */
-        class Impl
-        {
-        protected:
-            ~Impl() { }
-        };
-        /** Get rendersystem specific interface for this RenderTarget.
-            This is used by the RenderSystem to (un)bind this target, 
-            and to get specific information like surfaces
-            and framebuffer objects.
-        */
-        virtual Impl *_getImpl();
-
 		/** Method for manual management of rendering : fires 'preRenderTargetUpdate'
 			and initialises statistics etc.
 		@remarks 
@@ -257,8 +237,6 @@ namespace CamelotEngine {
 		/// The priority of the render target.
 		UINT8 mPriority;
 
-		DepthStencilBufferPtr mDepthStencilBuffer;
-
         unsigned int mWidth;
         unsigned int mHeight;
         unsigned int mColourDepth;

+ 1 - 6
CamelotRenderer/Source/CmRenderTarget.cpp

@@ -34,7 +34,7 @@ THE SOFTWARE.
 namespace CamelotEngine {
 
     RenderTarget::RenderTarget()
-		:mPriority(OGRE_DEFAULT_RT_GROUP),
+		:mPriority(CM_DEFAULT_RT_GROUP),
 		mActive(true),
 		mAutoUpdate(true),
 		mHwGamma(false), 
@@ -107,11 +107,6 @@ namespace CamelotEngine {
         return false;
     }
     //-----------------------------------------------------------------------
-    RenderTarget::Impl *RenderTarget::_getImpl()
-    {
-        return 0;
-    }
-    //-----------------------------------------------------------------------
     void RenderTarget::update(bool swap)
     {
         // call implementation

+ 2 - 2
CamelotRenderer/Source/CmRenderTexture.cpp

@@ -37,7 +37,7 @@ namespace CamelotEngine
 	RenderTexture::RenderTexture(HardwarePixelBuffer *buffer, UINT32 zoffset):
 		mBuffer(buffer), mZOffset(zoffset)
     {
-        mPriority = OGRE_REND_TO_TEX_RT_GROUP;
+        mPriority = CM_REND_TO_TEX_RT_GROUP;
 		mWidth = static_cast<unsigned int>(mBuffer->getWidth());
 		mHeight = static_cast<unsigned int>(mBuffer->getHeight());
         mColourDepth = static_cast<unsigned int>(
@@ -67,7 +67,7 @@ namespace CamelotEngine
 	//-----------------------------------------------------------------------------
 	MultiRenderTarget::MultiRenderTarget(const String &name)
     {
-        mPriority = OGRE_REND_TO_TEX_RT_GROUP;
+        mPriority = CM_REND_TO_TEX_RT_GROUP;
 		mName = name;
 		/// Width and height is unknown with no targets attached
 		mWidth = mHeight = 0;

+ 3 - 3
CamelotRenderer/TODO.txt

@@ -18,6 +18,7 @@
 
 /////
 DX11 Render Textures are not implemented. I need to rethink render textures (and multi render textures) completely (Get rid of TU_RENDERTARGET enum)
+ - Ability to create MultiRenderTarget (currently there is no method that does it)
 
 waitForVsync can probably be moved somewhere other than being directly in RenderSystem? (where is it in DX11?)
 
@@ -30,11 +31,8 @@ Keeping a list of all render targets in RenderSystem shouldn't be needed (and ca
 Constant buffers are created in a weird way. Maybe they should only be created internally by GpuProgramParameters?
  - Multiple GpuProgramParameters get returned from GpuProgram after createParameters() is called, in a map, each with its own name
 
-
 setDepthBuffer method on RenderTexture
 All render targets need to create DepthStencilBuffer internally, so that getDepthStencilBuffer can return something. Right now only D3D11 render window does this
-Add D3D11DepthStencilBuffer
- - Remove commented out buffer creation code from D3D11RenderWindow
 
 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)
@@ -189,6 +187,8 @@ After everything is polished
 	  further modifications.
  - Port boost threads to std threads (CmThreadDefines.h)
  - Remove HardwarePixelBuffer (DX11 doesn't use it, and DX9 and OpenGL textures can be rewritten so they have its methods internally)
+ - Multihead device
+ - 3D rendering (use low level hardware methods for it)
  
  - Go to Game Engine Architecture book and make a list of Utility systems we will need (Config files, Parsers, File I/O etc)
  - Go to GEA book and read about resource managers before implementing them