Explorar o código

More work on DX11

Marko Pintera %!s(int64=13) %!d(string=hai) anos
pai
achega
a249cfc990

+ 2 - 0
CamelotD3D11RenderSystem/Include/CmD3D11Mappings.h

@@ -7,6 +7,7 @@
 #include "CmIndexBuffer.h"
 #include "CmIndexBuffer.h"
 #include "CmVertexIndexData.h"
 #include "CmVertexIndexData.h"
 #include "CmSamplerState.h"
 #include "CmSamplerState.h"
+#include "CmRenderOperation.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
@@ -54,6 +55,7 @@ namespace CamelotEngine
 		/// Get vertex semantic
 		/// Get vertex semantic
 		static LPCSTR get(VertexElementSemantic sem);
 		static LPCSTR get(VertexElementSemantic sem);
 		static VertexElementSemantic get(LPCSTR sem);
 		static VertexElementSemantic get(LPCSTR sem);
+		static D3D11_PRIMITIVE_TOPOLOGY getPrimitiveType(DrawOperationType type);
 		/// Get dx11 color
 		/// Get dx11 color
 		static void get(const Color& inColour, float * outColour );
 		static void get(const Color& inColour, float * outColour );
 		static bool isMappingWrite(D3D11_MAP map);
 		static bool isMappingWrite(D3D11_MAP map);

+ 22 - 0
CamelotD3D11RenderSystem/Source/CmD3D11Mappings.cpp

@@ -784,6 +784,28 @@ namespace CamelotEngine
 			return static_cast<TextureType>(0);
 			return static_cast<TextureType>(0);
 		}
 		}
 	}
 	}
+
+	D3D11_PRIMITIVE_TOPOLOGY D3D11Mappings::getPrimitiveType(DrawOperationType type)
+	{
+		switch(type)
+		{
+		case DOT_POINT_LIST:
+			return D3D11_PRIMITIVE_TOPOLOGY_POINTLIST;
+		case DOT_LINE_LIST:
+			return D3D11_PRIMITIVE_TOPOLOGY_LINELIST;
+		case DOT_LINE_STRIP:
+			return D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP;
+		case DOT_TRIANGLE_LIST:
+			return D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
+		case DOT_TRIANGLE_STRIP:
+			return D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP;
+		case DOT_TRIANGLE_FAN:
+			CM_EXCEPT(InvalidParametersException, "D3D11 doesn't support triangle fan primitive type.");
+		}
+
+		return D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
+	}
+
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
 	UINT32 D3D11Mappings::_getSizeInBytes(PixelFormat pf, UINT32 xcount, UINT32 ycount)
 	UINT32 D3D11Mappings::_getSizeInBytes(PixelFormat pf, UINT32 xcount, UINT32 ycount)
 	{
 	{

+ 37 - 5
CamelotD3D11RenderSystem/Source/CmD3D11RenderSystem.cpp

@@ -13,6 +13,10 @@
 #include "CmD3D11DepthStencilState.h"
 #include "CmD3D11DepthStencilState.h"
 #include "CmD3D11SamplerState.h"
 #include "CmD3D11SamplerState.h"
 #include "CmD3D11GpuProgram.h"
 #include "CmD3D11GpuProgram.h"
+#include "CmD3D11VertexDeclaration.h"
+#include "CmD3D11Mappings.h"
+#include "CmD3D11VertexBuffer.h"
+#include "CmD3D11IndexBuffer.h"
 #include "CmRenderSystem.h"
 #include "CmRenderSystem.h"
 #include "CmDebug.h"
 #include "CmDebug.h"
 #include "CmException.h"
 #include "CmException.h"
@@ -276,20 +280,46 @@ namespace CamelotEngine
 	{
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 		THROW_IF_NOT_RENDER_THREAD;
 
 
-		throw std::exception("The method or operation is not implemented.");
+		UINT32 maxBoundVertexBuffers = mCurrentCapabilities->getMaxBoundVertexBuffers();
+		if(index < 0 || index >= maxBoundVertexBuffers)
+			CM_EXCEPT(InvalidParametersException, "Invalid vertex index: " + toString(index) + ". Valid range is 0 .. " + toString(maxBoundVertexBuffers - 1));
+
+		ID3D11Buffer* buffers[1];
+		D3D11VertexBuffer* vertexBuffer = static_cast<D3D11VertexBuffer*>(buffer.get());
+		buffers[0] = vertexBuffer->getD3DVertexBuffer();
+
+		UINT32 strides[1] = { buffer->getVertexSize() };
+		UINT32 offsets[1] = { 0 };
+
+		mDevice->getImmediateContext()->IASetVertexBuffers(index, 1, buffers, strides, offsets);
 	}
 	}
 
 
 	void D3D11RenderSystem::setIndexBuffer(const IndexBufferPtr& buffer)
 	void D3D11RenderSystem::setIndexBuffer(const IndexBufferPtr& buffer)
 	{
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 		THROW_IF_NOT_RENDER_THREAD;
 
 
-		throw std::exception("The method or operation is not implemented.");
+		D3D11IndexBuffer* indexBuffer = static_cast<D3D11IndexBuffer*>(buffer.get());
+
+		DXGI_FORMAT indexFormat = DXGI_FORMAT_R16_UINT;
+		if(indexBuffer->getType() == IndexBuffer::IT_16BIT)
+			indexFormat = DXGI_FORMAT_R16_UINT;
+		else if(indexBuffer->getType() == IndexBuffer::IT_32BIT)
+			indexFormat = DXGI_FORMAT_R32_UINT;
+		else
+			CM_EXCEPT(InternalErrorException, "Unsupported index format: " + toString(indexBuffer->getType()));
+
+		mDevice->getImmediateContext()->IASetIndexBuffer(indexBuffer->getD3DIndexBuffer(), indexFormat, 0);
 	}
 	}
 
 
 	void D3D11RenderSystem::setVertexDeclaration(VertexDeclarationPtr vertexDeclaration)
 	void D3D11RenderSystem::setVertexDeclaration(VertexDeclarationPtr vertexDeclaration)
 	{
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 		THROW_IF_NOT_RENDER_THREAD;
 
 
+		//D3D11VertexDeclaration* vertexDeclaration = static_cast<D3D11VertexDeclaration*>(vertexDeclaration.get());
+		//mDevice->getImmediateContext()->IASetInputLayout(vertexDeclaration->get);
+
+		// TODO - Delay setting the input layout until Draw methods are called, when you will retrieve the input layout from the active vertex shader
+
 		throw std::exception("The method or operation is not implemented.");
 		throw std::exception("The method or operation is not implemented.");
 	}
 	}
 
 
@@ -297,7 +327,7 @@ namespace CamelotEngine
 	{
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 		THROW_IF_NOT_RENDER_THREAD;
 
 
-		throw std::exception("The method or operation is not implemented.");
+		mDevice->getImmediateContext()->IASetPrimitiveTopology(D3D11Mappings::getPrimitiveType(op));
 	}
 	}
 
 
 	void D3D11RenderSystem::bindGpuProgram(GpuProgramHandle prg)
 	void D3D11RenderSystem::bindGpuProgram(GpuProgramHandle prg)
@@ -387,14 +417,14 @@ namespace CamelotEngine
 	{
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 		THROW_IF_NOT_RENDER_THREAD;
 
 
-		throw std::exception("The method or operation is not implemented.");
+		mDevice->getImmediateContext()->Draw(vertexCount, 0);
 	}
 	}
 
 
 	void D3D11RenderSystem::drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexCount)
 	void D3D11RenderSystem::drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexCount)
 	{
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 		THROW_IF_NOT_RENDER_THREAD;
 
 
-		throw std::exception("The method or operation is not implemented.");
+		mDevice->getImmediateContext()->DrawIndexed(indexCount, startIndex, 0);
 	}
 	}
 
 
 	void D3D11RenderSystem::setScissorRect(UINT32 left, UINT32 top, UINT32 right, UINT32 bottom)
 	void D3D11RenderSystem::setScissorRect(UINT32 left, UINT32 top, UINT32 right, UINT32 bottom)
@@ -413,6 +443,8 @@ namespace CamelotEngine
 	{
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 		THROW_IF_NOT_RENDER_THREAD;
 
 
+		//target->g
+
 		//RenderTarget* previousRenderTarget = mActiveRenderTarget;
 		//RenderTarget* previousRenderTarget = mActiveRenderTarget;
 		//if(target.get() != mActiveRenderTarget)
 		//if(target.get() != mActiveRenderTarget)
 		//{
 		//{

+ 6 - 0
CamelotRenderer/TODO.txt

@@ -30,6 +30,11 @@
  Refactor how we handle RenderTargets (no attach/detach, and no waitForVSync propery in RenderSystem)
  Refactor how we handle RenderTargets (no attach/detach, and no waitForVSync propery in RenderSystem)
  waitForVsync can probably be moved somewhere other than being directly in RenderSystem? (where is it in DX11?)
  waitForVsync can probably be moved somewhere other than being directly in RenderSystem? (where is it in DX11?)
 
 
+ Think about how to manage resources. For example check VertexBuffer is VertexData class. How and when is that freed?
+ - Big problem is also that RenderSystem in a lot of cases holds raw pointers, so what happens when resource get destroyed and RS tries to use it?
+
+Extreme lag when starting the game with OpenGL!?
+
 >>>>>>>>>>>>>>>START WORKING ON THE EDITOR!
 >>>>>>>>>>>>>>>START WORKING ON THE EDITOR!
  
  
 
 
@@ -134,6 +139,7 @@ Optional TODO:
  - FBX importer can be greatly sped up by implementing a better allocator
  - FBX importer can be greatly sped up by implementing a better allocator
  - Extend texture copy so it accepts different subregions & subresources (currently only entire resource can be copied)
  - Extend texture copy so it accepts different subregions & subresources (currently only entire resource can be copied)
  - Need a way to convert MSAA render texture into a normal render texture
  - Need a way to convert MSAA render texture into a normal render texture
+ - Vertex buffer start offset is not supported when calling Draw methods
 
 
  -----------------------------------------------------------------------------------------------
  -----------------------------------------------------------------------------------------------