Преглед на файлове

Minor fix to DX11 start-up as it was crashing

Marko Pintera преди 11 години
родител
ревизия
6288a3f0d5

+ 1 - 1
BansheeEditorExec/BsEditorExec.cpp

@@ -11,7 +11,7 @@ int CALLBACK WinMain(
 	_In_  int nCmdShow
 	)
 {
-	EditorApplication::startUp(RenderSystemPlugin::DX9);
+	EditorApplication::startUp(RenderSystemPlugin::DX11);
 	EditorApplication::instance().runMainLoop();
 	EditorApplication::shutDown();
 

+ 18 - 19
CamelotD3D11RenderSystem/Include/CmD3D11RenderSystem.h

@@ -104,34 +104,33 @@ namespace BansheeEngine
 		 */
         void destroy_internal();
 
+		/**
+		 * @brief	Creates or retrieves a proper input layout depending on the currently set vertex shader
+		 * 			and vertex buffer.
+		 *
+		 *			Applies the input layout to the pipeline.
+		 */
+		void applyInputLayout();
+
 	private:
-		IDXGIFactory*		mDXGIFactory;
-		D3D11Device*		mDevice;
+		IDXGIFactory* mDXGIFactory;
+		D3D11Device* mDevice;
 
-		D3D11DriverList*	mDriverList;
-		D3D11Driver*		mActiveD3DDriver;
+		D3D11DriverList* mDriverList;
+		D3D11Driver* mActiveD3DDriver;
 
-		D3D_FEATURE_LEVEL	mFeatureLevel;
+		D3D_FEATURE_LEVEL mFeatureLevel;
 
 		D3D11HLSLProgramFactory* mHLSLFactory;
 		D3D11InputLayoutManager* mIAManager;
 
-		// State variables
-		UINT32				mStencilRef;
-		D3D11_VIEWPORT		mViewport;
-		D3D11_RECT			mScissorRect;
+		UINT32 mStencilRef;
+		D3D11_VIEWPORT mViewport;
+		D3D11_RECT mScissorRect;
 
 		VertexDeclarationPtr mActiveVertexDeclaration;
-		D3D11GpuProgramPtr	 mActiveVertexShader;
+		D3D11GpuProgramPtr mActiveVertexShader;
 
-		DrawOperationType	mActiveDrawOp;
-
-		/**
-		 * @brief	Creates or retrieves a proper input layout depending on the currently set vertex shader
-		 * 			and vertex buffer. 
-		 * 			
-		 *			Applies the input layout to the pipeline.
-		 */
-		void applyInputLayout();
+		DrawOperationType mActiveDrawOp;
 	};
 }

+ 2 - 2
CamelotD3D11RenderSystem/Source/CmD3D11Driver.cpp

@@ -60,11 +60,11 @@ namespace BansheeEngine
 			ob.mDXGIAdapter->AddRef();
 
 		SAFE_RELEASE(mDXGIAdapter);
-		mDXGIAdapter=ob.mDXGIAdapter;
+		mDXGIAdapter = ob.mDXGIAdapter;
 
 		return *this;
 	}
-	
+
 	String D3D11Driver::getDriverName() const
 	{
 		size_t size = wcslen(mAdapterIdentifier.Description);

+ 3 - 2
CamelotD3D11RenderSystem/Source/CmD3D11RenderSystem.cpp

@@ -93,10 +93,11 @@ namespace BansheeEngine
 
 		mDevice = cm_new<D3D11Device>(device);
 		
+		// This must query for DirectX 10 interface as this is unsupported for DX11
 		LARGE_INTEGER driverVersion; 
-		if(SUCCEEDED(selectedAdapter->CheckInterfaceSupport(IID_ID3D11Device, &driverVersion)))
+		if(SUCCEEDED(selectedAdapter->CheckInterfaceSupport(IID_ID3D10Device, &driverVersion)))
 		{
-			mDriverVersion.major = HIWORD(driverVersion.HighPart);
+			mDriverVersion.major =  HIWORD(driverVersion.HighPart);
 			mDriverVersion.minor = LOWORD(driverVersion.HighPart);
 			mDriverVersion.release = HIWORD(driverVersion.LowPart);
 			mDriverVersion.build = LOWORD(driverVersion.LowPart);

+ 140 - 137
ExampleProject/Main/Main.cpp

@@ -16,6 +16,7 @@
 #include "BsGUIArea.h"
 #include "BsGUILayoutX.h"
 #include "BsGUILayoutY.h"
+#include "BsGUISpace.h"
 #include "BsGUILabel.h"
 #include "BsGUIButton.h"
 #include "BsGUIListBox.h"
@@ -26,177 +27,179 @@
 #include "CmSceneObject.h"
 #include "CmCoreThread.h"
 
-using namespace BansheeEngine;
-
-Path exampleModelPath = "..\\..\\..\\..\\Data\\Examples\\Pyromancer.fbx";
-Path exampleTexturePath = "..\\..\\..\\..\\Data\\Examples\\Pyromancer.psd";
-Path exampleFragmentShaderPath = "..\\..\\..\\..\\Data\\Examples\\example_fs.gpuprog";
-Path exampleVertexShaderPath = "..\\..\\..\\..\\Data\\Examples\\example_vs.gpuprog";
-
-GUIButton* toggleFullscreenButton = nullptr;
-UINT32 resolutionWidth = 1280;
-UINT32 resolutionHeight = 720;
-bool fullscreen = false;
-const VideoMode* videoMode = nullptr;
-
-HMesh exampleModel;
-HTexture exampleTexture;
-HGpuProgram exampleFragmentGPUProg;
-HGpuProgram exampleVertexGPUProg;
-
-HCamera sceneCamera;
-
-void setUpExample();
-
-int CALLBACK WinMain(
-	_In_  HINSTANCE hInstance,
-	_In_  HINSTANCE hPrevInstance,
-	_In_  LPSTR lpCmdLine,
-	_In_  int nCmdShow
-	)
+namespace BansheeEngine
 {
-	RENDER_WINDOW_DESC renderWindowDesc;
-	renderWindowDesc.width = resolutionWidth;
-	renderWindowDesc.height = resolutionHeight;
-	renderWindowDesc.title = "Banshee Example App";
-	renderWindowDesc.fullscreen = false;
+	Path exampleModelPath = "..\\..\\..\\..\\Data\\Examples\\Pyromancer.fbx";
+	Path exampleTexturePath = "..\\..\\..\\..\\Data\\Examples\\Pyromancer.psd";
+	Path exampleFragmentShaderPath = "..\\..\\..\\..\\Data\\Examples\\example_fs.gpuprog";
+	Path exampleVertexShaderPath = "..\\..\\..\\..\\Data\\Examples\\example_vs.gpuprog";
 
-	gBansheeApp().startUp(renderWindowDesc, "CamelotD3D11RenderSystem", "BansheeForwardRenderer"); // TODO - Use enums instead of names. BansheeApp is a high level system that doesn't need to be as customizable.
-	setUpExample();
-	
-	gBansheeApp().runMainLoop();
-	gBansheeApp().shutDown();
+	GUIButton* toggleFullscreenButton = nullptr;
+	UINT32 resolutionWidth = 1280;
+	UINT32 resolutionHeight = 720;
+	bool fullscreen = false;
+	const VideoMode* videoMode = nullptr;
 
-	return 0;
-}
+	HMesh exampleModel;
+	HTexture exampleTexture;
+	HGpuProgram exampleFragmentGPUProg;
+	HGpuProgram exampleVertexGPUProg;
 
-void toggleFullscreen()
-{
-	RenderWindowPtr window = gApplication().getPrimaryWindow();
+	HCamera sceneCamera;
 
-	if (fullscreen)
+	void toggleFullscreen()
 	{
-		gCoreAccessor().setWindowed(window);
+		RenderWindowPtr window = gApplication().getPrimaryWindow();
+
+		if (fullscreen)
+		{
+			gCoreAccessor().setWindowed(window);
+		}
+		else
+		{
+			//gCoreAccessor().setFullscreen(window, *videoMode);
+			gCoreAccessor().setFullscreen(window, 1920, 1200);
+		}
+
+		fullscreen = !fullscreen;
 	}
-	else
+
+	void setUpExample()
 	{
-		//gCoreAccessor().setFullscreen(window, *videoMode);
-		gCoreAccessor().setFullscreen(window, 1920, 1200);
-	}
+		// Import assets
+		exampleModel = static_resource_cast<Mesh>(Importer::instance().import(exampleModelPath));
+		exampleTexture = static_resource_cast<Texture>(Importer::instance().import(exampleTexturePath));
 
-	fullscreen = !fullscreen;
-}
+		ImportOptionsPtr gpuProgImportOptions = Importer::instance().createImportOptions(exampleFragmentShaderPath);
+		if (rtti_is_of_type<GpuProgramImportOptions>(gpuProgImportOptions))
+		{
+			GpuProgramImportOptions* importOptions = static_cast<GpuProgramImportOptions*>(gpuProgImportOptions.get());
 
-void setUpExample()
-{
-	// Import assets
-	exampleModel = static_resource_cast<Mesh>(Importer::instance().import(exampleModelPath));
-	exampleTexture = static_resource_cast<Texture>(Importer::instance().import(exampleTexturePath));
+			importOptions->setEntryPoint("ps_main");
+			importOptions->setLanguage("hlsl");
+			importOptions->setProfile(GPP_PS_4_0);
+			importOptions->setType(GPT_FRAGMENT_PROGRAM);
+		}
 
-	ImportOptionsPtr gpuProgImportOptions = Importer::instance().createImportOptions(exampleFragmentShaderPath);
-	if(rtti_is_of_type<GpuProgramImportOptions>(gpuProgImportOptions))
-	{
-		GpuProgramImportOptions* importOptions = static_cast<GpuProgramImportOptions*>(gpuProgImportOptions.get());
+		exampleFragmentGPUProg = static_resource_cast<GpuProgram>(Importer::instance().import(exampleFragmentShaderPath, gpuProgImportOptions));
 
-		importOptions->setEntryPoint("ps_main");
-		importOptions->setLanguage("hlsl");
-		importOptions->setProfile(GPP_PS_4_0);
-		importOptions->setType(GPT_FRAGMENT_PROGRAM);
-	}
+		gpuProgImportOptions = Importer::instance().createImportOptions(exampleVertexShaderPath);
+		if (rtti_is_of_type<GpuProgramImportOptions>(gpuProgImportOptions))
+		{
+			GpuProgramImportOptions* importOptions = static_cast<GpuProgramImportOptions*>(gpuProgImportOptions.get());
 
-	exampleFragmentGPUProg = static_resource_cast<GpuProgram>(Importer::instance().import(exampleFragmentShaderPath, gpuProgImportOptions));
+			importOptions->setEntryPoint("vs_main");
+			importOptions->setLanguage("hlsl");
+			importOptions->setProfile(GPP_VS_4_0);
+			importOptions->setType(GPT_VERTEX_PROGRAM);
+		}
 
-	gpuProgImportOptions = Importer::instance().createImportOptions(exampleVertexShaderPath);
-	if(rtti_is_of_type<GpuProgramImportOptions>(gpuProgImportOptions))
-	{
-		GpuProgramImportOptions* importOptions = static_cast<GpuProgramImportOptions*>(gpuProgImportOptions.get());
+		exampleVertexGPUProg = static_resource_cast<GpuProgram>(Importer::instance().import(exampleVertexShaderPath, gpuProgImportOptions));
 
-		importOptions->setEntryPoint("vs_main");
-		importOptions->setLanguage("hlsl");
-		importOptions->setProfile(GPP_VS_4_0);
-		importOptions->setType(GPT_VERTEX_PROGRAM);
-	}
+		// TODO - Optionally make the entire import step one-time. After import save resources and the created scene. Then on next load just load them directly from disk.
 
-	exampleVertexGPUProg = static_resource_cast<GpuProgram>(Importer::instance().import(exampleVertexShaderPath, gpuProgImportOptions));
+		// Create material
+		ShaderPtr exampleShader = Shader::create("ExampleShader");
 
-	// TODO - Optionally make the entire import step one-time. After import save resources and the created scene. Then on next load just load them directly from disk.
+		exampleShader->addParameter("matViewProjection", "matViewProjection", GPDT_MATRIX_4X4);
+		exampleShader->addParameter("samp", "samp", GPOT_SAMPLER2D);
+		exampleShader->addParameter("tex", "tex", GPOT_TEXTURE2D);
 
-	// Create material
-	ShaderPtr exampleShader = Shader::create("ExampleShader");
+		TechniquePtr technique = exampleShader->addTechnique("D3D11RenderSystem", "ForwardRenderer"); // TODO - This render system and forward renderer names should at least match the above names used for initialization
+		PassPtr pass = technique->addPass();
+		pass->setVertexProgram(exampleVertexGPUProg);
+		pass->setFragmentProgram(exampleFragmentGPUProg);
 
-	exampleShader->addParameter("matViewProjection", "matViewProjection", GPDT_MATRIX_4X4);
-	exampleShader->addParameter("samp", "samp", GPOT_SAMPLER2D);
-	exampleShader->addParameter("tex", "tex", GPOT_TEXTURE2D);
+		HMaterial exampleMaterial = Material::create(exampleShader);
+		exampleMaterial->setTexture("tex", exampleTexture);
 
-	TechniquePtr technique = exampleShader->addTechnique("D3D11RenderSystem", "ForwardRenderer"); // TODO - This render system and forward renderer names should at least match the above names used for initialization
-	PassPtr pass = technique->addPass();
-	pass->setVertexProgram(exampleVertexGPUProg);
-	pass->setFragmentProgram(exampleFragmentGPUProg);
+		// Set up the object to render
+		HSceneObject pyromancerSO = SceneObject::create("Pyromancer");
+		HRenderable renderable = pyromancerSO->addComponent<Renderable>();
+		renderable->setMesh(exampleModel);
+		renderable->setMaterial(exampleMaterial);
 
-	HMaterial exampleMaterial = Material::create(exampleShader);
-	exampleMaterial->setTexture("tex", exampleTexture);
+		// Set up scene camera
+		HSceneObject sceneCameraGO = SceneObject::create("SceneCamera");
 
-	// Set up the object to render
-	HSceneObject pyromancerSO = SceneObject::create("Pyromancer");
-	HRenderable renderable = pyromancerSO->addComponent<Renderable>();
-	renderable->setMesh(exampleModel);
-	renderable->setMaterial(exampleMaterial);
+		RenderWindowPtr window = gApplication().getPrimaryWindow(); // TODO - Up until now I'm using gBansheeApp and now I'm using gApplication. It's confusing. BansheeApp should derive from application
+		sceneCamera = sceneCameraGO->addComponent<Camera>(window, 0.0f, 0.0f, 1.0f, 1.0f);
 
-	// Set up scene camera
-	HSceneObject sceneCameraGO = SceneObject::create("SceneCamera");
+		sceneCamera->setPriority(1);
+		sceneCameraGO->setPosition(Vector3(0, 50, 1240));
+		sceneCameraGO->lookAt(Vector3(0, 50, -300));
+		sceneCamera->setNearClipDistance(5);
+		sceneCamera->setAspectRatio(resolutionWidth / (float)resolutionHeight); // TODO - This needs to get called whenever resolution changes
 
-	RenderWindowPtr window = gApplication().getPrimaryWindow(); // TODO - Up until now I'm using gBansheeApp and now I'm using gApplication. It's confusing. BansheeApp should derive from application
-	sceneCamera = sceneCameraGO->addComponent<Camera>(window, 0.0f, 0.0f, 1.0f, 1.0f);
+		// Register input configuration
+		auto inputConfig = VirtualInput::instance().getConfiguration();
 
-	sceneCamera->setPriority(1);
-	sceneCameraGO->setPosition(Vector3(0,50,1240));
-	sceneCameraGO->lookAt(Vector3(0,50,-300));
-	sceneCamera->setNearClipDistance(5);
-	sceneCamera->setAspectRatio(resolutionWidth / (float)resolutionHeight); // TODO - This needs to get called whenever resolution changes
+		inputConfig->registerButton("Forward", BC_W);
+		inputConfig->registerButton("Left", BC_A);
+		inputConfig->registerButton("Right", BC_D);
+		inputConfig->registerButton("Back", BC_S);
 
-	// Register input configuration
-	auto inputConfig = VirtualInput::instance().getConfiguration();
+		inputConfig->registerButton("SimThreadProfilerOverlay", BC_F1);
+		inputConfig->registerButton("CoreThreadProfilerOverlay", BC_F2);
+		inputConfig->registerButton("GPUProfilerOverlay", BC_F3);
 
-	inputConfig->registerButton("Forward", BC_W);
-	inputConfig->registerButton("Left", BC_A);
-	inputConfig->registerButton("Right", BC_D);
-	inputConfig->registerButton("Back", BC_S);
+		// TODO - Add vertical/horizontal axes here
 
-	inputConfig->registerButton("SimThreadProfilerOverlay", BC_F1);
-	inputConfig->registerButton("CoreThreadProfilerOverlay", BC_F2);
-	inputConfig->registerButton("GPUProfilerOverlay", BC_F3);
+		HSceneObject exampleSO = SceneObject::create("Example");
 
-	// TODO - Add vertical/horizontal axes here
+		HCamera guiCamera = exampleSO->addComponent<Camera>(window);
+		guiCamera->setNearClipDistance(5);
+		guiCamera->setAspectRatio(1.0f);
+		guiCamera->setIgnoreSceneRenderables(true);
 
-	HSceneObject exampleSO = SceneObject::create("Example");
+		HGUIWidget gui = exampleSO->addComponent<GUIWidget>(guiCamera->getViewport().get());
+		gui->setDepth(128);
+		gui->setSkin(BuiltinResources::instance().getGUISkin());
 
-	HCamera guiCamera = exampleSO->addComponent<Camera>(window);
-	guiCamera->setNearClipDistance(5);
-	guiCamera->setAspectRatio(1.0f);
-	guiCamera->setIgnoreSceneRenderables(true);
+		// Profiler overlay GUI
+		GUIArea* topArea = GUIArea::createStretchedXY(*gui, 0, 0, 0, 0);
+		GUILayout& topLayout = topArea->getLayout().addLayoutY();
 
-	HGUIWidget gui = exampleSO->addComponent<GUIWidget>();
-	gui->setDepth(128);
-	gui->setSkin(BuiltinResources::instance().getGUISkin());
+		topLayout.addElement(GUILabel::create(HString(L"Press F1 to toggle Sim thread profiler overlay")));
+		topLayout.addElement(GUILabel::create(HString(L"Press F2 to toggle Core thread profiler overlay")));
+		topLayout.addElement(GUILabel::create(HString(L"Press F3 to toggle GPU profiler overlay")));
+		topLayout.addFlexibleSpace();
 
-	// Profiler overlay GUI
-	GUIArea* topArea = GUIArea::createStretchedXY(*gui, 0, 0, 0, 0);
-	GUILayout& topLayout = topArea->getLayout().addLayoutY();
+		// Resolution/Camera options GUI
+		GUIArea* rightArea = GUIArea::createStretchedXY(*gui, 0, 0, 0, 0);
+		rightArea->getLayout().addFlexibleSpace();
+		GUILayout& rightLayout = rightArea->getLayout().addLayoutY();
 
-	topLayout.addElement(GUILabel::create(HString(L"Press F1 to toggle Sim thread profiler overlay")));
-	topLayout.addElement(GUILabel::create(HString(L"Press F2 to toggle Core thread profiler overlay")));
-	topLayout.addElement(GUILabel::create(HString(L"Press F3 to toggle GPU profiler overlay")));
-	topLayout.addFlexibleSpace();
+		rightLayout.addSpace(50);
+		toggleFullscreenButton = GUIButton::create(HString(L"Toggle fullscreen"));
+		toggleFullscreenButton->onClick.connect(&toggleFullscreen);
+		rightLayout.addElement(toggleFullscreenButton);
 
-	// Resolution/Camera options GUI
-	GUIArea* rightArea = GUIArea::createStretchedXY(*gui, 0, 0, 0, 0);
-	rightArea->getLayout().addFlexibleSpace();
-	GUILayout& rightLayout = rightArea->getLayout().addLayoutY();
+		// TODO - add ExampleGUI component
+	}
+}
+
+using namespace BansheeEngine;
 
-	rightLayout.addSpace(50);
-	toggleFullscreenButton = GUIButton::create(HString(L"Toggle fullscreen"));
-	toggleFullscreenButton->onClick.connect(&toggleFullscreen);
-	rightLayout.addElement(toggleFullscreenButton);
+int CALLBACK WinMain(
+	_In_  HINSTANCE hInstance,
+	_In_  HINSTANCE hPrevInstance,
+	_In_  LPSTR lpCmdLine,
+	_In_  int nCmdShow
+	)
+{
+	RENDER_WINDOW_DESC renderWindowDesc;
+	renderWindowDesc.width = resolutionWidth;
+	renderWindowDesc.height = resolutionHeight;
+	renderWindowDesc.title = "Banshee Example App";
+	renderWindowDesc.fullscreen = false;
+
+	gBansheeApp().startUp(renderWindowDesc, "CamelotD3D11RenderSystem", "BansheeForwardRenderer"); // TODO - Use enums instead of names. BansheeApp is a high level system that doesn't need to be as customizable.
+	setUpExample();
+	
+	gBansheeApp().runMainLoop();
+	gBansheeApp().shutDown();
+
+	return 0;
+}
 
-	// TODO - add ExampleGUI component
-}