Quellcode durchsuchen

Added RenderWindowManager to DX9

Marko Pintera vor 13 Jahren
Ursprung
Commit
1d3afd1f98

+ 2 - 0
CamelotD3D9Renderer/CamelotD3D9Renderer.vcxproj

@@ -167,6 +167,7 @@
     <ClInclude Include="Include\CmD3D9RenderSystem.h" />
     <ClInclude Include="Include\CmD3D9RenderSystem.h" />
     <ClInclude Include="Include\CmD3D9RenderSystemFactory.h" />
     <ClInclude Include="Include\CmD3D9RenderSystemFactory.h" />
     <ClInclude Include="Include\CmD3D9RenderWindow.h" />
     <ClInclude Include="Include\CmD3D9RenderWindow.h" />
+    <ClInclude Include="Include\CmD3D9RenderWindowManager.h" />
     <ClInclude Include="Include\CmD3D9Resource.h" />
     <ClInclude Include="Include\CmD3D9Resource.h" />
     <ClInclude Include="Include\CmD3D9ResourceManager.h" />
     <ClInclude Include="Include\CmD3D9ResourceManager.h" />
     <ClInclude Include="Include\CmD3D9Texture.h" />
     <ClInclude Include="Include\CmD3D9Texture.h" />
@@ -195,6 +196,7 @@
     <ClCompile Include="Source\CmD3D9RenderSystem.cpp" />
     <ClCompile Include="Source\CmD3D9RenderSystem.cpp" />
     <ClCompile Include="Source\CmD3D9RenderSystemFactory.cpp" />
     <ClCompile Include="Source\CmD3D9RenderSystemFactory.cpp" />
     <ClCompile Include="Source\CmD3D9RenderWindow.cpp" />
     <ClCompile Include="Source\CmD3D9RenderWindow.cpp" />
+    <ClCompile Include="Source\CmD3D9RenderWindowManager.cpp" />
     <ClCompile Include="Source\CmD3D9Resource.cpp" />
     <ClCompile Include="Source\CmD3D9Resource.cpp" />
     <ClCompile Include="Source\CmD3D9ResourceManager.cpp" />
     <ClCompile Include="Source\CmD3D9ResourceManager.cpp" />
     <ClCompile Include="Source\CmD3D9Texture.cpp" />
     <ClCompile Include="Source\CmD3D9Texture.cpp" />

+ 6 - 0
CamelotD3D9Renderer/CamelotD3D9Renderer.vcxproj.filters

@@ -99,6 +99,9 @@
     <ClInclude Include="Include\CmD3D9HLSLProgramRTTI.h">
     <ClInclude Include="Include\CmD3D9HLSLProgramRTTI.h">
       <Filter>Header Files\RTTI</Filter>
       <Filter>Header Files\RTTI</Filter>
     </ClInclude>
     </ClInclude>
+    <ClInclude Include="Include\CmD3D9RenderWindowManager.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\CmD3D9Device.cpp">
     <ClCompile Include="Source\CmD3D9Device.cpp">
@@ -179,5 +182,8 @@
     <ClCompile Include="CmD3D9Plugin.cpp">
     <ClCompile Include="CmD3D9Plugin.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>
+    <ClCompile Include="Source\CmD3D9RenderWindowManager.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   </ItemGroup>
 </Project>
 </Project>

+ 2 - 0
CamelotD3D9Renderer/Include/CmD3D9Prerequisites.h

@@ -82,6 +82,8 @@ namespace CamelotEngine
     class D3D9VertexDeclaration;
     class D3D9VertexDeclaration;
 	class D3D9Resource;
 	class D3D9Resource;
 
 
+	typedef std::shared_ptr<D3D9RenderWindow> D3D9RenderWindowPtr;
+
 	enum TypeID_D3D9
 	enum TypeID_D3D9
 	{
 	{
 		TID_D3D9_HLSLProgram = 10000
 		TID_D3D9_HLSLProgram = 10000

+ 8 - 2
CamelotD3D9Renderer/Include/CmD3D9RenderSystem.h

@@ -51,8 +51,6 @@ namespace CamelotEngine
 
 
 		const String& getName() const;
 		const String& getName() const;
 
 
-		void createRenderWindow_internal(const String &name, unsigned int width, unsigned int height, 
-			bool fullScreen, const NameValuePairList& miscParams, AsyncOp& asyncOp);
 		void destroyRenderTarget(RenderTarget* renderTarget);
 		void destroyRenderTarget(RenderTarget* renderTarget);
 		void setRenderTarget(RenderTarget* target);
 		void setRenderTarget(RenderTarget* target);
 
 
@@ -244,6 +242,7 @@ namespace CamelotEngine
 		friend class D3D9Device;
 		friend class D3D9Device;
 		friend class D3D9TextureManager;
 		friend class D3D9TextureManager;
 		friend class D3D9DeviceManager;		
 		friend class D3D9DeviceManager;		
+		friend class D3D9RenderWindowManager;
 
 
 		void startUp_internal();
 		void startUp_internal();
 		void shutdown_internal();
 		void shutdown_internal();
@@ -259,6 +258,8 @@ namespace CamelotEngine
 		void setClipPlane (UINT16 index, float A, float B, float C, float D);
 		void setClipPlane (UINT16 index, float A, float B, float C, float D);
 		void enableClipPlane (UINT16 index, bool enable);
 		void enableClipPlane (UINT16 index, bool enable);
 
 
+		HINSTANCE getInstanceHandle() const { return mhInstance; }
+
 		/**
 		/**
 			Get the matching Z-Buffer identifier for a certain render target
 			Get the matching Z-Buffer identifier for a certain render target
 		*/
 		*/
@@ -287,6 +288,11 @@ namespace CamelotEngine
 		/// Take in some requested FSAA settings and output supported D3D settings
 		/// Take in some requested FSAA settings and output supported D3D settings
 		void determineFSAASettings(IDirect3DDevice9* d3d9Device, UINT32 fsaa, const String& fsaaHint, D3DFORMAT d3dPixelFormat, 
 		void determineFSAASettings(IDirect3DDevice9* d3d9Device, UINT32 fsaa, const String& fsaaHint, D3DFORMAT d3dPixelFormat, 
 			bool fullScreen, D3DMULTISAMPLE_TYPE *outMultisampleType, DWORD *outMultisampleQuality);
 			bool fullScreen, D3DMULTISAMPLE_TYPE *outMultisampleType, DWORD *outMultisampleQuality);
+
+		/**
+		 * @brief	Called internally by RenderWindowManager whenever a new window is created.
+		 */
+		void registerRenderWindow(D3D9RenderWindowPtr renderWindow);
 	
 	
 		/************************************************************************/
 		/************************************************************************/
 		/* 							Sampler states                     			*/
 		/* 							Sampler states                     			*/

+ 23 - 0
CamelotD3D9Renderer/Include/CmD3D9RenderWindowManager.h

@@ -0,0 +1,23 @@
+#pragma once
+
+#include "CmD3D9Prerequisites.h"
+#include "CmRenderWindowManager.h"
+
+namespace CamelotEngine
+{
+	class CM_D3D9_EXPORT D3D9RenderWindowManager : public RenderWindowManager
+	{
+	public:
+		D3D9RenderWindowManager(D3D9RenderSystem* renderSystem);
+
+	protected:
+		/**
+		 * @copydoc RenderWindowManager::create()
+		 */
+		void createImpl(const String& name, UINT32 width, UINT32 height, 
+			bool fullScreen, const map<String, String>::type& miscParams, AsyncOp& asyncOp);
+
+	private:
+		D3D9RenderSystem* mRenderSystem;
+	};
+}

+ 10 - 13
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -47,6 +47,7 @@ THE SOFTWARE.
 #include "CmD3D9MultiRenderTarget.h"
 #include "CmD3D9MultiRenderTarget.h"
 #include "CmD3D9DeviceManager.h"
 #include "CmD3D9DeviceManager.h"
 #include "CmD3D9ResourceManager.h"
 #include "CmD3D9ResourceManager.h"
+#include "CmD3D9RenderWindowManager.h"
 #include "CmHighLevelGpuProgramManager.h"
 #include "CmHighLevelGpuProgramManager.h"
 #include "CmAsyncOp.h"
 #include "CmAsyncOp.h"
 #include "CmBlendState.h"
 #include "CmBlendState.h"
@@ -210,6 +211,9 @@ namespace CamelotEngine
 		// Create & register Cg factory		
 		// Create & register Cg factory		
 		mCgProgramFactory = new CgProgramFactory();
 		mCgProgramFactory = new CgProgramFactory();
 
 
+		// Create render window manager
+		RenderWindowManager::startUp(new D3D9RenderWindowManager(this));
+
 		// call superclass method
 		// call superclass method
 		RenderSystem::startUp_internal();
 		RenderSystem::startUp_internal();
 	}
 	}
@@ -228,23 +232,17 @@ namespace CamelotEngine
 		GpuProgramManager::shutDown();		
 		GpuProgramManager::shutDown();		
 	}
 	}
 	//--------------------------------------------------------------------
 	//--------------------------------------------------------------------
-	void D3D9RenderSystem::createRenderWindow_internal(const String &name, 
-		unsigned int width, unsigned int height, bool fullScreen,
-		const NameValuePairList& miscParams, AsyncOp& asyncOp)
+	void D3D9RenderSystem::registerRenderWindow(D3D9RenderWindowPtr renderWindow)
 	{		
 	{		
 		THROW_IF_NOT_RENDER_THREAD;
 		THROW_IF_NOT_RENDER_THREAD;
 
 
 		String msg;
 		String msg;
 
 
-		D3D9RenderWindow* renderWindow = new D3D9RenderWindow(mhInstance);
-
-		renderWindow->initialize(name, width, height, fullScreen, &miscParams);
-
 		mResourceManager->lockDeviceAccess();
 		mResourceManager->lockDeviceAccess();
 
 
 		try
 		try
 		{
 		{
-			mDeviceManager->linkRenderWindow(renderWindow);
+			mDeviceManager->linkRenderWindow(renderWindow.get());
 		}
 		}
 		catch (const CamelotEngine::RenderingAPIException&)
 		catch (const CamelotEngine::RenderingAPIException&)
 		{
 		{
@@ -258,13 +256,12 @@ namespace CamelotEngine
 
 
 		mResourceManager->unlockDeviceAccess();
 		mResourceManager->unlockDeviceAccess();
 
 
-		mRenderWindows.push_back(renderWindow);		
-
-		updateRenderSystemCapabilities(renderWindow);
+		// TODO - Storing raw pointer here might not be a good idea?
+		mRenderWindows.push_back(renderWindow.get());		
 
 
-		attachRenderTarget( *renderWindow );
+		updateRenderSystemCapabilities(renderWindow.get());
 
 
-		asyncOp.completeOperation(static_cast<RenderWindow*>(renderWindow));
+		attachRenderTarget(*renderWindow);
 	}	
 	}	
 
 
 	void D3D9RenderSystem::bindGpuProgram(GpuProgramHandle prg)
 	void D3D9RenderSystem::bindGpuProgram(GpuProgramHandle prg)

+ 27 - 0
CamelotD3D9Renderer/Source/CmD3D9RenderWindowManager.cpp

@@ -0,0 +1,27 @@
+#include "CmD3D9RenderWindowManager.h"
+#include "CmD3D9RenderSystem.h"
+#include "CmD3D9RenderWindow.h"
+#include "CmAsyncOp.h"
+
+namespace CamelotEngine
+{
+	D3D9RenderWindowManager::D3D9RenderWindowManager(D3D9RenderSystem* renderSystem)
+		:mRenderSystem(renderSystem)
+	{
+		assert(mRenderSystem != nullptr);
+	}
+
+	void D3D9RenderWindowManager::createImpl(const String& name, UINT32 width, UINT32 height, 
+		bool fullScreen, const map<String, String>::type& miscParams, AsyncOp& asyncOp)
+	{
+		// Create the window
+		D3D9RenderWindow* renderWindow = new D3D9RenderWindow(mRenderSystem->getInstanceHandle());
+
+		renderWindow->initialize(name, width, height, fullScreen, &miscParams);
+
+		D3D9RenderWindowPtr winPtr(renderWindow);
+		mRenderSystem->registerRenderWindow(winPtr);
+
+		asyncOp.completeOperation(std::static_pointer_cast<RenderWindow>(winPtr));
+	}
+}

+ 6 - 15
CamelotRenderer/TODO.txt

@@ -24,14 +24,16 @@ Move createRenderTexture to TextureManager? (also createMultiRenderTexture)
  - Right now its created with a special texture usage flag, which I don't like
  - Right now its created with a special texture usage flag, which I don't like
 Drop OpenGL support for low level shaders? (See if cg can translate to GLSL)
 Drop OpenGL support for low level shaders? (See if cg can translate to GLSL)
 
 
+Make RenderSystem a module? (Initialize it using startUp, and get rid of directly accessing RenderSystemManager whenever I need the active RenderSystem)
+
+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:
 Rasterizer state:
  D3DRS_MULTISAMPLEANTIALIAS
  D3DRS_MULTISAMPLEANTIALIAS
  - but first check if available using D3DPRASTERCAPS_MULTISAMPLE_TOGGLE
  - but first check if available using D3DPRASTERCAPS_MULTISAMPLE_TOGGLE
  - see if opengl has something similar
  - see if opengl has something similar
  - see if either dx9 or opengl have something similar to DX11 antialias line
  - see if either dx9 or opengl have something similar to DX11 antialias line
 
 
-Move createRenderWindow outside of RenderSystem
-
 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)
 /////
 /////
@@ -42,16 +44,11 @@ Make sure that the simulation can't run faster then the render thread! (Block th
 
 
 
 
 RenderSystem needed modifications
 RenderSystem needed modifications
- - HLSL specifies Texture & Sampler separately
-   - Will probably need a rendersystem specific sampler object implementation
-   - Right now HLSL11 CANNOT SPECIFY TEXTURE PARAMETERS! (Pass needs to be extended)
+ - Right now HLSL11 CANNOT SPECIFY TEXTURE PARAMETERS! (Pass needs to be extended)
  - Generic buffers (Normal/Structured/Raw/Append/Consume/Indirect)
  - Generic buffers (Normal/Structured/Raw/Append/Consume/Indirect)
  - Ability to bind buffers and texture with different type of view (SHADER_RESOURCE & UNORDERED_ACCESS primarily, major others too)
  - Ability to bind buffers and texture with different type of view (SHADER_RESOURCE & UNORDERED_ACCESS primarily, major others too)
  - Pass needs to be modified
  - Pass needs to be modified
-  - Texture & Sampler needs to be specified separately
-  - SamplerState object needs to be created, to be used by all render systems. It needs to have a render specific implementation
   - Needs to support bool/double/texture1D/textue3D/textureCUBE/texture arrays/MS textures/all types of buffers/structs
   - Needs to support bool/double/texture1D/textue3D/textureCUBE/texture arrays/MS textures/all types of buffers/structs
- - Deferred render contexts and multithreaded rendering
  - TextureBuffer support? (Use for bones when skinning for exaple, as constant buffers are too slow)
  - TextureBuffer support? (Use for bones when skinning for exaple, as constant buffers are too slow)
  - RW buffers?
  - RW buffers?
  - Tesselation (hull/domain) shader
  - Tesselation (hull/domain) shader
@@ -71,15 +68,9 @@ RenderSystem needed modifications
  - HLSL9/HLSL11/GLSL/Cg shaders need preprocessor defines & includes
  - HLSL9/HLSL11/GLSL/Cg shaders need preprocessor defines & includes
 
 
  RenderSystem modifications, yet another list:
  RenderSystem modifications, yet another list:
-   - SamplerState - separate object. Multiple objects per pass
-   - RasterizerState - separate object containing all the DX9 and GL variables that were so far solo (fill mode, cull mode, etc). One per pass
-   - DepthStencilState - also separate object, one per pass
-
-   - Edit RenderSystem so it only accepts those objects (in bulk), and not individual commands? (Since DX11 can't accept individual commands)
-
    - DepthStencilView & RenderTargetView are automatically created for any RenderTarget (no special mechanism for setting them needed)
    - DepthStencilView & RenderTargetView are automatically created for any RenderTarget (no special mechanism for setting them needed)
 
 
-   - Extend pass with "struct" (void*) parameters to that they can be assigned to constant buffers, and also expand it so it accepts separate textures & samplers. 
+   - Extend pass with "struct" (void*) parameters to that they can be assigned to constant buffers
    - Extend pass so it accepts "GenericBuffers"
    - Extend pass so it accepts "GenericBuffers"
 
 
    - Add support for "GenericBuffers" (normal/structured/raw/append/consume/indirect)
    - Add support for "GenericBuffers" (normal/structured/raw/append/consume/indirect)